diff --git a/charms/istio-pilot/config.yaml b/charms/istio-pilot/config.yaml index 9e57d5df..2e1c2388 100644 --- a/charms/istio-pilot/config.yaml +++ b/charms/istio-pilot/config.yaml @@ -3,6 +3,18 @@ options: type: string default: istio-gateway description: Name to use as a default gateway + image-configuration: + default: | + pilot-image: 'pilot' # values.pilot.image + global-tag: '1.17.3' # values.global.tag + global-hub: 'docker.io/istio' # values.global.hub + global-proxy-image: 'proxyv2' # values.global.proxy.image + global-proxy-init-image: 'proxyv2' # values.global.proxy_init.image + grpc-bootstrap-init: 'busybox:1.28' + description: > + YAML or JSON formatted input defining image configuration to use when installing the Istio control plane. + For reference https://istio.io/v1.5/docs/reference/config/installation-options/ + type: string gateway-service-name: type: string default: istio-ingressgateway-workload diff --git a/charms/istio-pilot/src/charm.py b/charms/istio-pilot/src/charm.py index c563d4fe..c46aaa7a 100755 --- a/charms/istio-pilot/src/charm.py +++ b/charms/istio-pilot/src/charm.py @@ -5,6 +5,7 @@ from typing import List, Optional import tenacity +import yaml from charmed_kubeflow_chisme.exceptions import ErrorWithStatus, GenericCharmRuntimeError from charmed_kubeflow_chisme.kubernetes import ( KubernetesResourceHandler, @@ -53,6 +54,7 @@ "https": 8443, } GATEWAY_TEMPLATE_FILES = ["src/manifests/gateway.yaml.j2"] +IMAGE_CONFIGURATION = "image-configuration" KRH_GATEWAY_SCOPE = "gateway" METRICS_PORT = 15014 INGRESS_AUTH_RELATION_NAME = "ingress-auth" @@ -156,19 +158,42 @@ def __init__(self, *args): ) self.grafana_dashboards = GrafanaDashboardProvider(self, relation_name="grafana-dashboard") + def _get_image_config(self): + """Retrieve and return image configuration.""" + image_config = yaml.safe_load(self.model.config[IMAGE_CONFIGURATION]) + return image_config + def install(self, _): """Install charm.""" self._log_and_set_status(MaintenanceStatus("Deploying Istio control plane")) + image_config = self._get_image_config() + pilot_image = image_config["pilot-image"] + global_tag = image_config["global-tag"] + global_hub = image_config["global-hub"] + global_proxy_image = image_config["global-proxy-image"] + global_proxy_init_image = image_config["global-proxy-init-image"] + + # Call istioctl install and set parameters based on image configuration subprocess.check_call( [ "./istioctl", "install", "-y", - "-s", + "--set", "profile=minimal", - "-s", - f"values.global.istioNamespace={self.model.name}", + "--set", + "values.global.istioNamespace=kubeflow", + "--set", + f"values.pilot.image={pilot_image}", + "--set", + f"values.global.tag={global_tag}", + "--set", + f"values.global.hub={global_hub}", + "--set", + f"values.global.proxy.image={global_proxy_image}", + "--set", + f"values.global.proxy_init.image={global_proxy_init_image}", ] ) diff --git a/charms/istio-pilot/tests/unit/test_charm.py b/charms/istio-pilot/tests/unit/test_charm.py index 337af8bb..78d11393 100644 --- a/charms/istio-pilot/tests/unit/test_charm.py +++ b/charms/istio-pilot/tests/unit/test_charm.py @@ -1030,6 +1030,14 @@ def test_xor(self, left, right, expected): """Test that the xor helper function works as expected.""" assert _xor(left, right) is expected + def test_get_config(self, harness): + """Test configuration retrieval function.""" + harness.begin() + image_config = harness.charm._get_image_config() + assert "pilot-image" in image_config.keys() + assert "pilot" == image_config["pilot-image"] + assert "proxyv2" == image_config["global-proxy-image"] + class TestCharmUpgrade: """Tests for charm upgrade handling."""