Skip to content

Commit

Permalink
Merge pull request #217 from canonical/cherrypick-fix-configure-proxy…
Browse files Browse the repository at this point in the history
…-env-vars-in-serving-1.10

* feat: add initial config for proxy envs in knative-serving controller
* unit test proxy configs
* add integration test
  • Loading branch information
NohaIhab authored Aug 20, 2024
2 parents 59fc4af + 9cd1eab commit 9270cec
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 0 deletions.
12 changes: 12 additions & 0 deletions charms/knative-serving/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,15 @@ options:
description: >
Image to use for the `queue-proxy` sidecar container in a Knative Service workload Pod.
type: string
http-proxy:
default: ""
description: The value of HTTP_PROXY environment variable in the serving controller.
type: string
https-proxy:
default: ""
description: The value of HTTPS_PROXY environment variable in the serving controller.
type: string
no-proxy:
default: ""
description: The value of NO_PROXY environment variable in the serving controller.
type: string
3 changes: 3 additions & 0 deletions charms/knative-serving/src/charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,9 @@ def _context(self):
"serving_namespace": self.model.config["namespace"],
"serving_version": self.model.config["version"],
"custom_images": self._get_custom_images(),
"http_proxy": self.model.config["http-proxy"],
"https_proxy": self.model.config["https-proxy"],
"no_proxy": self.model.config["no-proxy"],
}
if self._otel_collector_relation_data:
context.update(self._otel_collector_relation_data)
Expand Down
19 changes: 19 additions & 0 deletions charms/knative-serving/src/manifests/KnativeServing.yaml.j2
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,22 @@ spec:
{{ container }}: {{ image }}
{% endfor %}
{% endif %}
{% if http_proxy or https_proxy or no_proxy %}
workloads:
- name: controller
env:
- container: controller
envVars:
{% if http_proxy %}
- name: HTTP_PROXY
value: {{ http_proxy }}
{% endif %}
{% if https_proxy %}
- name: HTTPS_PROXY
value: {{ https_proxy }}
{% endif %}
{% if no_proxy %}
- name: NO_PROXY
value: {{ no_proxy }}
{% endif %}
{% endif %}
6 changes: 6 additions & 0 deletions charms/knative-serving/tests/unit/test_charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,9 @@ def test_context_changes(harness):
"namespace": "knative-serving",
"istio.gateway.name": "knative-gateway",
"istio.gateway.namespace": "istio-namespace",
"http-proxy": "my_http_proxy",
"https-proxy": "my_https_proxy",
"no-proxy": "my_no_proxy",
}
)
harness.begin()
Expand All @@ -174,6 +177,9 @@ def test_context_changes(harness):
"gateway_namespace": harness.model.config["istio.gateway.namespace"],
"serving_namespace": harness.model.config["namespace"],
"serving_version": harness.model.config["version"],
"http_proxy": harness.model.config["http-proxy"],
"https_proxy": harness.model.config["https-proxy"],
"no_proxy": harness.model.config["no-proxy"],
CUSTOM_IMAGE_CONFIG_NAME: DEFAULT_IMAGES,
}

Expand Down
49 changes: 49 additions & 0 deletions tests/test_bundle.py
Original file line number Diff line number Diff line change
Expand Up @@ -363,3 +363,52 @@ async def test_queue_sidecar_image_config(

# Assert that the Knative Service is trying to use the custom image.
assert cloudevents_deployment.spec.template.spec.containers[1].image == fake_image


async def test_serving_proxy_config(ops_test: OpsTest):
"""
Changes `http-proxy`, `https-proxy` and `no-proxy` configs and checks that the Knative Serving
controller container is using the values from configs as environment variables.
"""

# Act
test_http_proxy = "my_http_proxy"
test_https_proxy = "my_https_proxy"
test_no_proxy = "no_proxy"

await ops_test.model.applications["knative-serving"].set_config(
{"http-proxy": test_http_proxy, "https-proxy": test_https_proxy, "no-proxy": test_no_proxy}
)

await ops_test.model.wait_for_idle(
["knative-serving"],
status="active",
raise_on_blocked=False,
timeout=60 * 1,
)

client = Client()

# Get Knative Serving controller Deployment
controller_deployment = client.get(
Deployment, "controller", namespace=KNATIVE_SERVING_NAMESPACE
)

# Get Knative Serving controller environment variables
serving_controller_env_vars = controller_deployment.spec.template.spec.containers[0].env

http_proxy_env = https_proxy_env = no_proxy_env = None

# Get proxy environment variables from all Knative Serving controller env vars
for env_var in serving_controller_env_vars:
if env_var.name == "HTTP_PROXY":
http_proxy_env = env_var.value
elif env_var.name == "HTTPS_PROXY":
https_proxy_env = env_var.value
elif env_var.name == "NO_PROXY":
no_proxy_env = env_var.value

# Assert Deployment spec contains correct proxy environment variables
assert http_proxy_env == test_http_proxy
assert https_proxy_env == test_https_proxy
assert no_proxy_env == test_no_proxy

0 comments on commit 9270cec

Please sign in to comment.