Skip to content

Commit

Permalink
feat: Add cluster refresh (#35)
Browse files Browse the repository at this point in the history
* add refreshing to install

* add refresh command

* add default acceptance to refresh

* add charm upgrades

* liniting and formatting

* renaming

* refactor

* update readme

* rollback features from sunbeam latest to sunbeam anvil

* format again

* more linting

* remove unused imports

* include openstack client

* fetch manifest correctly

* remove clear manifest

* Roll our own upgrades to stop sunbeam issues

* subordinate unit

* remove openstack

* use manifest path, not manifest

* update job definitions

* move refresh to correct filepath

* add prompts back to postgresql

* remove extra refresh

* license and moving
  • Loading branch information
SK1Y101 authored Jul 26, 2024
1 parent f8730c3 commit b1858c1
Show file tree
Hide file tree
Showing 11 changed files with 437 additions and 0 deletions.
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,17 @@ ubuntu@infra1:~$ juju run maas-region/0 create-admin username=admin password=pas

# Managing the cluster after initial deployment


## 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.

## Juju permission denied

If you get an error message such as:
Expand Down
29 changes: 29 additions & 0 deletions anvil-python/anvil/commands/haproxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,15 @@ def get_application_timeout(self) -> int:
return HAPROXY_APP_TIMEOUT

def has_prompts(self) -> bool:
"""Returns true if the step has prompts that it can ask the user.
:return: True if the step can ask the user for prompts,
False otherwise
"""
# No need to prompt for questions in case of refresh
if self.refresh:
return False

return True

def prompt(self, console: Console | None = None) -> None:
Expand Down Expand Up @@ -198,3 +207,23 @@ def haproxy_install_steps(
),
AddHAProxyUnitsStep(client, fqdn, jhelper, model),
]


def haproxy_upgrade_steps(
client: Client,
manifest: Manifest,
jhelper: JujuHelper,
model: str,
preseed: dict[Any, Any],
) -> List[BaseStep]:
return [
TerraformInitStep(manifest.get_tfhelper("haproxy-plan")),
DeployHAProxyApplicationStep(
client,
manifest,
jhelper,
model,
deployment_preseed=preseed,
refresh=True,
),
]
14 changes: 14 additions & 0 deletions anvil-python/anvil/commands/maas_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,3 +123,17 @@ def maas_agent_install_steps(
DeployMAASAgentApplicationStep(client, manifest, jhelper, model),
AddMAASAgentUnitsStep(client, fqdn, jhelper, model),
]


def maas_agent_upgrade_steps(
client: Client,
manifest: Manifest,
jhelper: JujuHelper,
model: str,
) -> List[BaseStep]:
return [
TerraformInitStep(manifest.get_tfhelper("maas-agent-plan")),
DeployMAASAgentApplicationStep(
client, manifest, jhelper, model, refresh=True
),
]
14 changes: 14 additions & 0 deletions anvil-python/anvil/commands/maas_region.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,3 +131,17 @@ def maas_region_install_steps(
DeployMAASRegionApplicationStep(client, manifest, jhelper, model),
AddMAASRegionUnitsStep(client, fqdn, jhelper, model),
]


def maas_region_upgrade_steps(
client: Client,
manifest: Manifest,
jhelper: JujuHelper,
model: str,
) -> List[BaseStep]:
return [
TerraformInitStep(manifest.get_tfhelper("maas-region-plan")),
DeployMAASRegionApplicationStep(
client, manifest, jhelper, model, refresh=True
),
]
29 changes: 29 additions & 0 deletions anvil-python/anvil/commands/postgresql.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,26 @@ def postgresql_install_steps(
]


def postgresql_upgrade_steps(
client: Client,
manifest: Manifest,
jhelper: JujuHelper,
model: str,
preseed: dict[Any, Any],
) -> List[BaseStep]:
return [
TerraformInitStep(manifest.get_tfhelper("postgresql-plan")),
DeployPostgreSQLApplicationStep(
client,
manifest,
jhelper,
model,
deployment_preseed=preseed,
refresh=True,
),
]


def postgresql_questions() -> dict[str, questions.PromptQuestion]:
return {
"max_connections": questions.PromptQuestion(
Expand Down Expand Up @@ -153,6 +173,15 @@ def extra_tfvars(self) -> dict[str, Any]:
return variables

def has_prompts(self) -> bool:
"""Returns true if the step has prompts that it can ask the user.
:return: True if the step can ask the user for prompts,
False otherwise
"""
# No need to prompt for questions in case of refresh
if self.refresh:
return False

return True


Expand Down
85 changes: 85 additions & 0 deletions anvil-python/anvil/commands/refresh.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
# Copyright (c) 2024 Canonical Ltd.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
# implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import logging
from pathlib import Path

import click
from rich.console import Console
from sunbeam.jobs.common import (
run_plan,
)
from sunbeam.jobs.juju import JujuHelper
from sunbeam.jobs.manifest import AddManifestStep

from anvil.commands.upgrades.intra_channel import LatestInChannelCoordinator
from anvil.jobs.manifest import Manifest
from anvil.provider.local.deployment import LocalDeployment

LOG = logging.getLogger(__name__)
console = Console()


@click.command()
@click.option(
"-m",
"--manifest",
"manifest_path",
help="Manifest file.",
type=click.Path(exists=True, dir_okay=False, path_type=Path),
)
@click.pass_context
def refresh(
ctx: click.Context,
manifest_path: Path | None = None,
) -> None:
"""Refresh deployment.
Refresh the deployment and allow passing new configuration options.
"""

deployment: LocalDeployment = ctx.obj
client = deployment.get_client()

manifest = None
if manifest_path:
manifest = Manifest.load(
deployment, manifest_file=manifest_path, include_defaults=True
)
run_plan([AddManifestStep(client, manifest)], console)

if not manifest:
LOG.debug("Getting latest manifest from cluster db")
manifest = Manifest.load_latest_from_clusterdb(
deployment, include_defaults=True
)

LOG.debug(
f"Manifest used for refresh - deployment preseed: {manifest.deployment_config}"
)
LOG.debug(
f"Manifest used for refresh - software: {manifest.software_config}"
)
jhelper = JujuHelper(deployment.get_connected_controller())

a = LatestInChannelCoordinator(
deployment,
client,
jhelper,
manifest,
)
a.run_plan()

click.echo("Refresh complete.")
Empty file.
54 changes: 54 additions & 0 deletions anvil-python/anvil/commands/upgrades/base.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# Copyright (c) 2024 Canonical Ltd.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
# implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import logging

from rich.console import Console
from rich.status import Status
from sunbeam.jobs.common import (
BaseStep,
Result,
ResultType,
)
from sunbeam.jobs.deployment import Deployment

from anvil.jobs.plugin import PluginManager

LOG = logging.getLogger(__name__)
console = Console()


class UpgradePlugins(BaseStep):
def __init__(
self,
deployment: Deployment,
upgrade_release: bool = False,
):
"""Upgrade plugins.
:client: Helper for interacting with clusterd
:upgrade_release: Whether to upgrade channel
"""
super().__init__("Validation", "Running pre-upgrade validation")
self.deployment = deployment
self.upgrade_release = upgrade_release

def run(self, status: Status | None = None) -> Result:
PluginManager.update_plugins(
self.deployment,
repos=["core"],
upgrade_release=self.upgrade_release,
)
return Result(ResultType.COMPLETED)
Loading

0 comments on commit b1858c1

Please sign in to comment.