Skip to content

Commit

Permalink
Merge branch 'main' into tls-passthrough
Browse files Browse the repository at this point in the history
  • Loading branch information
wyattrees authored Sep 4, 2024
2 parents 9050d19 + 9331e06 commit c8633ae
Show file tree
Hide file tree
Showing 14 changed files with 491 additions and 94 deletions.
12 changes: 5 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,20 +90,19 @@ ubuntu@infra1:~$ maas-anvil cluster list
ubuntu@infra1:~$ juju run maas-region/0 create-admin username=admin password=pass email=admin@maas.io ssh-import=lp:maasadmin
```

# Managing the cluster after initial deployment
### Managing the cluster after initial deployment


## Cluster updates
#### Cluster updates

You can refresh the cluster by running the `refresh` command:

```bash
ubuntu@infra1:~$ maas-anvil refresh
```

This allows passing a new manifest file with `--manifest` for updating configuration options.
This allows passing a new manifest file with `--manifest` for updating configuration options. If `--manifest -` is passed, then the manifest is loaded from stdin.

## Juju permission denied
#### Juju permission denied

If you get an error message such as:

Expand All @@ -130,11 +129,10 @@ user: $user

And `juju login` as usual.

### Charm documentation
## Charm documentation

- MAAS Region: <https://charmhub.io/maas-region>
- MAAS Region: <https://charmhub.io/maas-agent>
- PostgreSQL: <https://charmhub.io/postgresql>
- PgBouncer: <https://charmhub.io/pgbouncer>
- HAProxy: <https://charmhub.io/haproxy>
- Keepalived: <https://charmhub.io/keepalived>
10 changes: 6 additions & 4 deletions anvil-python/anvil/commands/haproxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
HAPROXY_UNIT_TIMEOUT = (
1200 # 15 minutes, adding / removing units can take a long time
)

VALID_TLS_MODES = ["termination", "passthrough"]
LOG = logging.getLogger(__name__)

Expand All @@ -53,6 +54,7 @@ def validate_cert_file(filepath: str | None) -> None:
raise ValueError(
"Please provide a certificate file when enabling TLS."
)

if not os.path.isfile(filepath):
raise ValueError(f"{filepath} does not exist")
try:
Expand Down Expand Up @@ -80,12 +82,12 @@ def validate_key_file(filepath: str | None) -> None:
raise ValueError(f"Permission denied when trying to read {filepath}")


def validate_virtual_ip(value: str) -> str:
def validate_virtual_ip(value: str) -> None:
"""We allow passing an empty IP for virtual_ip"""
if value == "":
return ""
return
try:
return ipaddress.ip_address(value).exploded
ipaddress.ip_address(value).exploded
except ValueError as e:
raise ValueError(f"{value} is not a valid IP address: {e}")

Expand All @@ -94,7 +96,6 @@ def validate_tls_mode(value: str) -> None:
if value not in VALID_TLS_MODES:
raise ValueError(f"TLS Mode must be one of {VALID_TLS_MODES}")


def haproxy_questions() -> dict[str, questions.PromptQuestion]:
return {
"virtual_ip": questions.PromptQuestion(
Expand Down Expand Up @@ -188,6 +189,7 @@ def prompt(self, console: Console | None = None) -> None:
previous_answers=variables,
accept_defaults=self.accept_defaults,
)

tls_mode = haproxy_config_bank.tls_mode.ask()
variables["tls_mode"] = tls_mode
if tls_mode:
Expand Down
1 change: 0 additions & 1 deletion anvil-python/anvil/commands/manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.


import logging
import os
from pathlib import Path
Expand Down
6 changes: 5 additions & 1 deletion anvil-python/anvil/commands/postgresql.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,11 @@ def has_prompts(self) -> bool:
if self.refresh:
return False

return True
skip_result = self.is_skip()
if skip_result.result_type == ResultType.SKIPPED:
return False
else:
return True


class ReapplyPostgreSQLTerraformPlanStep(DeployMachineApplicationStep):
Expand Down
53 changes: 42 additions & 11 deletions anvil-python/anvil/commands/refresh.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,11 @@
run_plan,
)
from sunbeam.jobs.juju import JujuHelper
from sunbeam.jobs.manifest import AddManifestStep
import yaml

from anvil.commands.upgrades.inter_channel import ChannelUpgradeCoordinator
from anvil.commands.upgrades.intra_channel import LatestInChannelCoordinator
from anvil.jobs.manifest import Manifest
from anvil.jobs.manifest import AddManifestStep, Manifest
from anvil.provider.local.deployment import LocalDeployment

LOG = logging.getLogger(__name__)
Expand All @@ -38,12 +39,23 @@
"--manifest",
"manifest_path",
help="Manifest file.",
type=click.Path(exists=True, dir_okay=False, path_type=Path),
type=click.Path(
exists=True, dir_okay=False, path_type=Path, allow_dash=True
),
)
@click.option(
"-u",
"--upgrade-release",
is_flag=True,
show_default=True,
default=False,
help="Upgrade MAAS Anvil release.",
)
@click.pass_context
def refresh(
ctx: click.Context,
manifest_path: Path | None = None,
upgrade_release: bool = False,
) -> None:
"""Refresh deployment.
Expand All @@ -55,10 +67,19 @@ def refresh(

manifest = None
if manifest_path:
try:
with click.open_file(manifest_path) as file: # type: ignore
manifest_data = yaml.safe_load(file)
except (OSError, yaml.YAMLError) as e:
LOG.debug(e)
raise click.ClickException(f"Manifest parsing failed: {e!s}")

manifest = Manifest.load(
deployment, manifest_file=manifest_path, include_defaults=True
deployment,
manifest_data=manifest_data or {},
include_defaults=True,
)
run_plan([AddManifestStep(client, manifest)], console)
run_plan([AddManifestStep(client, manifest_data)], console)

if not manifest:
LOG.debug("Getting latest manifest from cluster db")
Expand All @@ -74,12 +95,22 @@ def refresh(
)
jhelper = JujuHelper(deployment.get_connected_controller())

a = LatestInChannelCoordinator(
deployment,
client,
jhelper,
manifest,
coordinator = (
ChannelUpgradeCoordinator(
deployment,
client,
jhelper,
manifest,
)
if upgrade_release
else LatestInChannelCoordinator(
deployment,
client,
jhelper,
manifest,
)
)
a.run_plan()
upgrade_plan = coordinator.get_plan() # type:ignore [attr-defined]
run_plan(upgrade_plan, console)

click.echo("Refresh complete.")
Loading

0 comments on commit c8633ae

Please sign in to comment.