Proxy Friendly Operators

Proxy-friendly Operators should inspect their environment for the standard proxy variables (HTTPS_PROXY, HTTP_PROXY, and NO_PROXY) and pass the values to Operands.

Operator-lib provides a helper function proxy.ReadProxyVarsFromEnv that does this inspection, all you need to do is append the results to the Operand environments.

Using the memcached tutorial as an example, add the following to the Reconcile loop in controllers/memcached_controller.go:

  1. import (
  2. ...
  3. "github.com/operator-framework/operator-lib/proxy"
  4. )
  5. for i, container := range dep.Spec.Template.Spec.Containers {
  6. dep.Spec.Template.Spec.Containers[i].Env = append(container.Env, proxy.ReadProxyVarsFromEnv()...)
  7. }

You can set the environment variable on the Operator deployment. Using the memcached tutorial, edit config/manager/manager.yaml:

  1. containers:
  2. - args:
  3. - --leader-elect
  4. - --leader-election-id=go-proxy-demo
  5. image: controller:latest
  6. name: manager
  7. env:
  8. - name: "HTTP_PROXY"
  9. value: "http_proxy_test"

Last modified November 9, 2021: add import to go proxy docs (#5279) (45915b24)