|
| 1 | +// Module included in the following assemblies: |
| 2 | +// |
| 3 | +// * operators/operator_sdk/golang/osdk-golang-tutorial.adoc |
| 4 | +// * operators/operator_sdk/ansible/osdk-ansible-tutorial.adoc |
| 5 | +// * operators/operator_sdk/helm/osdk-helm-tutorial.adoc |
| 6 | + |
| 7 | +ifeval::["{context}" == "osdk-golang-tutorial"] |
| 8 | +:golang: |
| 9 | +endif::[] |
| 10 | +ifeval::["{context}" == "osdk-ansible-tutorial"] |
| 11 | +:ansible: |
| 12 | +endif::[] |
| 13 | +ifeval::["{context}" == "osdk-helm-tutorial"] |
| 14 | +:helm: |
| 15 | +endif::[] |
| 16 | + |
| 17 | +[id="osdk-run-proxy_{context}"] |
| 18 | += Enabling proxy support |
| 19 | + |
| 20 | +To support proxied clusters, your Operator must inspect the environment for the following standard proxy variables and pass the values to Operands: |
| 21 | + |
| 22 | +* `HTTP_PROXY` |
| 23 | +* `HTTPS_PROXY` |
| 24 | +* `NO_PROXY` |
| 25 | + |
| 26 | +[NOTE] |
| 27 | +==== |
| 28 | +This tutorial uses `HTTP_PROXY` as an example environment variable. |
| 29 | +==== |
| 30 | + |
| 31 | +.Prerequisites |
| 32 | +* A cluster with cluster-wide egress proxy enabled. |
| 33 | + |
| 34 | +.Procedure |
| 35 | +ifdef::golang[] |
| 36 | +. Add the `proxy.ReadProxyVarsFromEnv` helper function to the reconcile loop in the `controllers/memcached_controller.go` file and append the results to the Operand environments: |
| 37 | ++ |
| 38 | +[source,golang] |
| 39 | +---- |
| 40 | +... |
| 41 | +for i, container := range dep.Spec.Template.Spec.Containers { |
| 42 | + dep.Spec.Template.Spec.Containers[i].Env = append(container.Env, proxy.ReadProxyVarsFromEnv()...) |
| 43 | +} |
| 44 | +... |
| 45 | +---- |
| 46 | + |
| 47 | +endif::[] |
| 48 | + |
| 49 | +ifdef::ansible[] |
| 50 | +. Add the environment variables to the deployment by updating the `roles/memcached/tasks/main.yml` file with the following: |
| 51 | ++ |
| 52 | +[source,yaml] |
| 53 | +---- |
| 54 | +... |
| 55 | +env: |
| 56 | + - name: HTTP_PROXY |
| 57 | + value: '{{ lookup("env", "HTTP_PROXY") | default("", True) }}' |
| 58 | + - name: http_proxy |
| 59 | + value: '{{ lookup("env", "HTTP_PROXY") | default("", True) }}' |
| 60 | +... |
| 61 | +---- |
| 62 | + |
| 63 | +endif::[] |
| 64 | + |
| 65 | +ifdef::helm[] |
| 66 | +* Edit the `watches.yaml` file to include overrides based on an environment variable by adding the `overrideValues` field: |
| 67 | ++ |
| 68 | +[source,yaml] |
| 69 | +---- |
| 70 | +... |
| 71 | +- group: demo.example.com |
| 72 | + version: v1alpha1 |
| 73 | + kind: Nginx |
| 74 | + chart: helm-charts/nginx |
| 75 | + overrideValues: |
| 76 | + proxy.http: $HTTP_PROXY |
| 77 | +... |
| 78 | +---- |
| 79 | + |
| 80 | +. Add the `proxy.http` value in the `helmcharts/nginx/values.yaml` file: |
| 81 | ++ |
| 82 | +[source,yaml] |
| 83 | +---- |
| 84 | +... |
| 85 | +proxy: |
| 86 | + http: "" |
| 87 | + https: "" |
| 88 | + no_proxy: "" |
| 89 | +---- |
| 90 | + |
| 91 | +. 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: |
| 92 | ++ |
| 93 | +[source,yaml] |
| 94 | +---- |
| 95 | +containers: |
| 96 | + - name: {{ .Chart.Name }} |
| 97 | + securityContext: |
| 98 | + - toYaml {{ .Values.securityContext | nindent 12 }} |
| 99 | + image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}" |
| 100 | + imagePullPolicy: {{ .Values.image.pullPolicy }} |
| 101 | + env: |
| 102 | + - name: http_proxy |
| 103 | + value: "{{ .Values.proxy.http }}" |
| 104 | +---- |
| 105 | + |
| 106 | +endif::[] |
| 107 | + |
| 108 | +. Set the environment variable on the Operator deployment by adding the following to the `config/manager/manager.yaml` file: |
| 109 | ++ |
| 110 | +[source,yaml] |
| 111 | +---- |
| 112 | +containers: |
| 113 | + - args: |
| 114 | + - --leader-elect |
| 115 | + - --leader-election-id=ansible-proxy-demo |
| 116 | + image: controller:latest |
| 117 | + name: manager |
| 118 | + env: |
| 119 | + - name: "HTTP_PROXY" |
| 120 | + value: "http_proxy_test" |
| 121 | +---- |
| 122 | + |
| 123 | + |
| 124 | +ifeval::["{context}" == "osdk-golang-tutorial"] |
| 125 | +:!golang: |
| 126 | +endif::[] |
| 127 | +ifeval::["{context}" == "osdk-ansible-tutorial"] |
| 128 | +:!ansible: |
| 129 | +endif::[] |
| 130 | +ifeval::["{context}" == "osdk-helm-tutorial"] |
| 131 | +:!helm: |
| 132 | +endif::[] |
0 commit comments