Skip to content

Commit

Permalink
Kf 3996 istio-pilot control plane configurable images with set (#321)
Browse files Browse the repository at this point in the history
# Description
More details in: #322
The changes in this PR are based on work done in #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 #322

Related PR: #320

NOTE: Created [issue](#324) to track updates to process of updating Istio.
  • Loading branch information
i-chvets authored Aug 31, 2023
1 parent bed0151 commit 293f90a
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 3 deletions.
12 changes: 12 additions & 0 deletions charms/istio-pilot/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
31 changes: 28 additions & 3 deletions charms/istio-pilot/src/charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -52,6 +53,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"
Expand Down Expand Up @@ -155,19 +157,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}",
]
)

Expand Down
8 changes: 8 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,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."""
Expand Down

0 comments on commit 293f90a

Please sign in to comment.