Skip to content

Commit

Permalink
fix: Make the metacontroller image configurable (#83)
Browse files Browse the repository at this point in the history
Expose the metacontroller image in config.yaml, so that it can be set
either pre or post deployment. This also ensures that the image is
always pulled from the specified source and not a private registry,
which the metacontroller StatefulSet doesn't have permission to access.

Signed-off-by: Phoevos Kalemkeris <phoevos.kalemkeris@canonical.com>
  • Loading branch information
phoevos committed Sep 5, 2023
1 parent e1850b8 commit 5d36799
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 24 deletions.
5 changes: 5 additions & 0 deletions config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
options:
metacontroller-image:
type: string
default: docker.io/metacontrollerio/metacontroller:v3.0.0
description: Metacontroller image
5 changes: 0 additions & 5 deletions metadata.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,6 @@ description: |
assumes:
- juju >= 2.9
summary: An add-on for Kubernetes to write and deploy custom controllers from simple scripts
resources:
oci-image:
type: oci-image
description: OCI image for metacontroller
upstream-source: docker.io/metacontrollerio/metacontroller:v3.0.0
provides:
metrics-endpoint:
interface: prometheus_scrape
Expand Down
12 changes: 2 additions & 10 deletions src/charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
from lightkube import codecs
from lightkube.core.exceptions import ApiError
from lightkube.resources.apps_v1 import StatefulSet
from oci_image import OCIImageResource, OCIImageResourceError
from ops.charm import CharmBase
from ops.main import main
from ops.model import ActiveStatus, BlockedStatus, MaintenanceStatus, WaitingStatus
Expand Down Expand Up @@ -47,14 +46,14 @@ def __init__(self, *args):
self.dashboard_provider = GrafanaDashboardProvider(self)

self.framework.observe(self.on.install, self._install)
self.framework.observe(self.on.config_changed, self._install)
self.framework.observe(self.on.update_status, self._update_status)

self.logger: logging.Logger = logging.getLogger(__name__)

self._name: str = self.model.app.name
self._namespace: str = self.model.name
self._metacontroller_image_resource = OCIImageResource(self, "oci-image")
self._metacontroller_image = self._fetch_image_path()
self._metacontroller_image = self.model.config["metacontroller-image"]
self._resource_files: dict = {
"crds": "metacontroller-crds-v1.yaml",
"rbac": "metacontroller-rbac.yaml",
Expand Down Expand Up @@ -203,13 +202,6 @@ def _get_manifest_files(self) -> list:
"""Returns a list of all manifest files"""
return glob.glob(str(self._manifest_file_root / "*.yaml"))

def _fetch_image_path(self):
try:
image_details = self._metacontroller_image_resource.fetch()
except OCIImageResourceError as e:
raise CheckFailed(f"{e.status.message}", e.status_type)
return image_details.get("imagePath")

@property
def lightkube_client(self):
if not self._lightkube_client:
Expand Down
8 changes: 0 additions & 8 deletions tests/unit/test_charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,6 @@ def harness():
def harness_with_charm(harness):
harness.set_leader(True)
harness.set_model_name("test-namespace")
harness.add_oci_resource(
"oci-image",
{
"registrypath": "image",
"username": "",
"password": "",
},
)
harness.begin()
return harness

Expand Down
2 changes: 1 addition & 1 deletion tools/get-images.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
#
# dynamic list
IMAGE_LIST=()
IMAGE_LIST+=($(find -type f -name metadata.yaml -exec yq '.resources | to_entries | .[] | .value | ."upstream-source"' {} \;))
IMAGE_LIST+=($(find -type f -name config.yaml -exec yq eval .options.metacontroller-image.default {} \;))
printf "%s\n" "${IMAGE_LIST[@]}"

0 comments on commit 5d36799

Please sign in to comment.