1
0
mirror of https://github.com/openshift/openshift-docs.git synced 2026-02-05 12:46:18 +01:00
Files
openshift-docs/modules/osdk-run-proxy.adoc
2023-10-30 10:13:25 -04:00

151 lines
3.8 KiB
Plaintext

// Module included in the following assemblies:
//
// * operators/operator_sdk/golang/osdk-golang-tutorial.adoc
// * operators/operator_sdk/ansible/osdk-ansible-tutorial.adoc
// * operators/operator_sdk/helm/osdk-helm-tutorial.adoc
ifeval::["{context}" == "osdk-golang-tutorial"]
:golang:
endif::[]
ifeval::["{context}" == "osdk-ansible-tutorial"]
:ansible:
endif::[]
ifeval::["{context}" == "osdk-helm-tutorial"]
:helm:
endif::[]
:_mod-docs-content-type: PROCEDURE
[id="osdk-run-proxy_{context}"]
= Enabling proxy support
Operator authors can develop Operators that support network proxies.
ifndef::openshift-dedicated,openshift-rosa[]
Cluster administrators
endif::openshift-dedicated,openshift-rosa[]
ifdef::openshift-dedicated,openshift-rosa[]
Administrators with the `dedicated-admin` role
endif::openshift-dedicated,openshift-rosa[]
configure proxy support for the environment variables that are handled by Operator Lifecycle Manager (OLM). To support proxied clusters, your Operator must inspect the environment for the following standard proxy variables and pass the values to Operands:
* `HTTP_PROXY`
* `HTTPS_PROXY`
* `NO_PROXY`
[NOTE]
====
This tutorial uses `HTTP_PROXY` as an example environment variable.
====
.Prerequisites
* A cluster with cluster-wide egress proxy enabled.
.Procedure
ifdef::golang[]
. Edit the `controllers/memcached_controller.go` file to include the following:
.. Import the `proxy` package from the link:https://github.com/operator-framework/operator-lib/releases/tag/v0.7.0[`operator-lib`] library:
+
[source,golang]
----
import (
...
"github.com/operator-framework/operator-lib/proxy"
)
----
.. Add the `proxy.ReadProxyVarsFromEnv` helper function to the reconcile loop and append the results to the Operand environments:
+
[source,golang]
----
for i, container := range dep.Spec.Template.Spec.Containers {
dep.Spec.Template.Spec.Containers[i].Env = append(container.Env, proxy.ReadProxyVarsFromEnv()...)
}
...
----
endif::[]
ifdef::ansible[]
. Add the environment variables to the deployment by updating the `roles/memcached/tasks/main.yml` file with the following:
+
[source,yaml]
----
...
env:
- name: HTTP_PROXY
value: '{{ lookup("env", "HTTP_PROXY") | default("", True) }}'
- name: http_proxy
value: '{{ lookup("env", "HTTP_PROXY") | default("", True) }}'
...
----
endif::[]
ifdef::helm[]
. Edit the `watches.yaml` file to include overrides based on an environment variable by adding the `overrideValues` field:
+
[source,yaml]
----
...
- group: demo.example.com
version: v1alpha1
kind: Nginx
chart: helm-charts/nginx
overrideValues:
proxy.http: $HTTP_PROXY
...
----
. Add the `proxy.http` value in the `helm-charts/nginx/values.yaml` file:
+
[source,yaml]
----
...
proxy:
http: ""
https: ""
no_proxy: ""
----
. To make sure the chart template supports using the variables, edit the chart template in the `helm-charts/nginx/templates/deployment.yaml` file to contain the following:
+
[source,yaml]
----
containers:
- name: {{ .Chart.Name }}
securityContext:
- toYaml {{ .Values.securityContext | nindent 12 }}
image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
imagePullPolicy: {{ .Values.image.pullPolicy }}
env:
- name: http_proxy
value: "{{ .Values.proxy.http }}"
----
endif::[]
. Set the environment variable on the Operator deployment by adding the following to the `config/manager/manager.yaml` file:
+
[source,yaml]
----
containers:
- args:
- --leader-elect
- --leader-election-id=ansible-proxy-demo
image: controller:latest
name: manager
env:
- name: "HTTP_PROXY"
value: "http_proxy_test"
----
ifeval::["{context}" == "osdk-golang-tutorial"]
:!golang:
endif::[]
ifeval::["{context}" == "osdk-ansible-tutorial"]
:!ansible:
endif::[]
ifeval::["{context}" == "osdk-helm-tutorial"]
:!helm:
endif::[]