Skip to content

Commit

Permalink
feat: istio-pilot configurable images
Browse files Browse the repository at this point in the history
#322

Summary of changes:
- Added unit tests.
- Modified config.yaml to make it consistent.
- Added get config helper to allow for better testing. This can also be
  expanded further.
  • Loading branch information
Ivan Chvets committed Aug 30, 2023
1 parent 953ad7b commit c4ee270
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 27 deletions.
22 changes: 11 additions & 11 deletions charms/istio-pilot/config.yaml
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
options:
image_configuration:
default-gateway:
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'
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
default-gateway:
type: string
default: istio-gateway
description: Name to use as a default gateway
gateway-service-name:
type: string
default: istio-ingressgateway-workload
Expand Down
37 changes: 21 additions & 16 deletions charms/istio-pilot/src/charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@

import logging
import subprocess
import yaml
from pathlib import Path
from typing import List, Optional

import tenacity
import yaml
from charmed_kubeflow_chisme.exceptions import ErrorWithStatus, GenericCharmRuntimeError
from charmed_kubeflow_chisme.kubernetes import (
KubernetesResourceHandler,
Expand All @@ -19,7 +18,6 @@
)
from charms.istio_pilot.v0.istio_gateway_info import GatewayProvider
from charms.prometheus_k8s.v0.prometheus_scrape import MetricsEndpointProvider
from jinja2 import Template
from lightkube import Client
from lightkube.core.exceptions import ApiError
from lightkube.generic_resource import create_namespaced_resource
Expand Down Expand Up @@ -56,7 +54,7 @@
}
GATEWAY_TEMPLATE_FILES = ["src/manifests/gateway.yaml.j2"]
DEFAULT_IMAGES = {}
IMAGE_CONFIGURATION = "image_configuration"
IMAGE_CONFIGURATION = "image-configuration"
KRH_GATEWAY_SCOPE = "gateway"
METRICS_PORT = 15014
INGRESS_AUTH_RELATION_NAME = "ingress-auth"
Expand Down Expand Up @@ -160,18 +158,24 @@ def __init__(self, *args):
)
self.grafana_dashboards = GrafanaDashboardProvider(self, relation_name="grafana-dashboard")

def _get_config(self):
"""Retrieve and return configuration."""
config = {}
config[IMAGE_CONFIGURATION] = yaml.safe_load(self.model.config[IMAGE_CONFIGURATION])
return config

def install(self, _):
"""Install charm."""
self._log_and_set_status(MaintenanceStatus("Deploying Istio control plane"))

image_configuration = yaml.safe_load(self.model.config[IMAGE_CONFIGURATION])
pilot_image = image_configuration["pilot_image"]
global_tag = image_configuration["global_tag"]
global_hub= image_configuration["global_hub"]
global_proxy_image = image_configuration["global_proxy_image"]
global_proxy_init_image = image_configuration["global_proxy_init_image"]
config = self._get_config()
pilot_image = config[IMAGE_CONFIGURATION]["pilot-image"]
global_tag = config[IMAGE_CONFIGURATION]["global-tag"]
global_hub = config[IMAGE_CONFIGURATION]["global-hub"]
global_proxy_image = config[IMAGE_CONFIGURATION]["global-proxy-image"]
global_proxy_init_image = config[IMAGE_CONFIGURATION]["global-proxy-init-image"]

# Call istioctl install and set paramters based on image configuratiob
# Call istioctl install and set parameters based on image configuration
subprocess.check_call(
[
"./istioctl",
Expand All @@ -182,15 +186,15 @@ def install(self, _):
"--set",
"values.global.istioNamespace=kubeflow",
"--set",
f"values.pilot.image='{pilot_image}'",
f"values.pilot.image={pilot_image}",
"--set",
f"values.global.tag='{global_tag}'",
f"values.global.tag={global_tag}",
"--set",
f"values.global.hub='{global_hub}'",
f"values.global.hub={global_hub}",
"--set",
f"values.global.proxy.image='{global_proxy_image}'",
f"values.global.proxy.image={global_proxy_image}",
"--set",
f"values.global.proxy_init.image='{global_proxy_init_image}'",
f"values.global.proxy_init.image={global_proxy_init_image}",
]
)

Expand Down Expand Up @@ -838,6 +842,7 @@ def _remove_envoyfilter(name: str, namespace: str, logger: Optional[logging.Logg
return
raise e


def _validate_upgrade_version(versions) -> bool:
"""Validates that the version of istioctl can upgrade the currently deployed Istio.
Expand Down
9 changes: 9 additions & 0 deletions charms/istio-pilot/tests/unit/test_charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -1039,6 +1039,15 @@ 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()
config = harness.charm._get_config()
assert "image-configuration" in config.keys()
assert "pilot-image" in config["image-configuration"].keys()
assert "pilot" == config["image-configuration"]["pilot-image"]
assert "proxyv2" == config["image-configuration"]["global-proxy-image"]


class TestCharmUpgrade:
"""Tests for charm upgrade handling."""
Expand Down

0 comments on commit c4ee270

Please sign in to comment.