Skip to content

Commit

Permalink
refactor, chore: move TAGGED_IMAGE away from charm code, add tools/ge…
Browse files Browse the repository at this point in the history
…t-images.sh (#51)

* refactor: move TAGGED_IMAGE from charm code to config.yaml

This commit removes the TAGGED_IMAGE variable from the charm code and places
the image to be used as a configuration option for the charm.

* chore: add tools/get-images.sh to gather images from this charm

This commit adds the support script for gathering the images this charm uses.

Part of canonical/bundle-kubeflow#1084
  • Loading branch information
DnPlas authored Oct 8, 2024
1 parent df0bb92 commit 56237e0
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 4 deletions.
5 changes: 5 additions & 0 deletions config.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
options:
namespace-node-affinity-image:
type: string
default: 'charmedkubeflow/namespace-node-affinity:2.2.0'
description: |
Container image to be used by the namespace-node-affinity workload.
settings_yaml:
type: string
default: ''
Expand Down
3 changes: 1 addition & 2 deletions src/charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
from certs import gen_certs

K8S_RESOURCE_FILES = ["src/templates/webhook_resources.yaml"]
TAGGED_IMAGE = "charmedkubeflow/namespace-node-affinity:2.2.0"


class NamespaceNodeAffinityOperator(CharmBase):
Expand Down Expand Up @@ -146,7 +145,7 @@ def _context(self):
return {
"app_name": self._name,
"namespace": self._namespace,
"image": TAGGED_IMAGE,
"image": self.config["namespace-node-affinity-image"],
"ca_bundle": b64encode(self._cert_ca.encode("ascii")).decode("utf-8"),
"cert": b64encode(self._cert.encode("ascii")).decode("utf-8"),
"cert_key": b64encode(self._cert_key.encode("ascii")).decode("utf-8"),
Expand Down
Binary file not shown.
4 changes: 2 additions & 2 deletions tests/unit/test_operator.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from ops.model import WaitingStatus
from ops.testing import Harness

from charm import K8S_RESOURCE_FILES, TAGGED_IMAGE, NamespaceNodeAffinityOperator
from charm import K8S_RESOURCE_FILES, NamespaceNodeAffinityOperator

# Used for test_get_settings_yaml
SETTINGS_YAML = """
Expand Down Expand Up @@ -53,7 +53,7 @@ def test_not_leader(self, harness: Harness):
def test_context(self, harness: Harness):
"""Test context property."""
model_name = "test-model"
image = TAGGED_IMAGE
image = harness.model.config["namespace-node-affinity-image"]
ca_bundle = "bundle123"
cert = "cert123"
cert_key = "cert_key123"
Expand Down
12 changes: 12 additions & 0 deletions tools/get-images.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/bash
#
# This script returns list of container images that are managed by this charm and/or its workload
#
# dynamic list

set -xe

IMAGE_LIST=()
IMAGE_LIST+=($(find -type f -name config.yaml -exec yq '.options | with_entries(select(.key | test("-image$"))) | .[].default' {} \; | tr -d '"'))
printf "%s\n" "${IMAGE_LIST[@]}"

0 comments on commit 56237e0

Please sign in to comment.