From 486cde2148523f4159fc2b50c93b473fdd4c81ab Mon Sep 17 00:00:00 2001 From: i-chvets <113444075+i-chvets@users.noreply.github.com> Date: Thu, 31 Aug 2023 14:44:15 -0400 Subject: [PATCH] Kf 3996 istio-pilot control plane configurable images with set (#321) # Description More details in: https://github.com/canonical/istio-operators/issues/322 The changes in this PR are based on work done in https://github.com/canonical/istio-operators/pull/316 Created a new PR to simplify workflow. # Summary of changes: - Modified code to use --set to alter precompile istioctl manifests to allow changes according to charm configuration. - Added `image-configuration` option to istio-pilot `config.yaml` - Added `proxy-image` option to istio-gatewat `config.yaml` - Added unit test for testing helper that retrieves configuration. # Testing For complete testing refer to https://github.com/canonical/istio-operators/issues/322 Related PR: https://github.com/canonical/istio-operators/issues/320 NOTE: Created [issue](https://github.com/canonical/istio-operators/issues/324) to track updates to process of updating Istio. --- charms/istio-pilot/config.yaml | 12 ++++++++ charms/istio-pilot/src/charm.py | 31 +++++++++++++++++++-- charms/istio-pilot/tests/unit/test_charm.py | 8 ++++++ 3 files changed, 48 insertions(+), 3 deletions(-) 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."""