-
Notifications
You must be signed in to change notification settings - Fork 543
/
envvar.go
52 lines (46 loc) · 1.32 KB
/
envvar.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package proxy
import (
apiconfigv1 "github.com/openshift/api/config/v1"
corev1 "k8s.io/api/core/v1"
)
const (
// HTTP_PROXY is the URL of the proxy for HTTP requests.
// Empty means unset and will not result in an env var.
envHTTPProxyName = "HTTP_PROXY"
// HTTPS_PROXY is the URL of the proxy for HTTPS requests.
// Empty means unset and will not result in an env var.
envHTTPSProxyName = "HTTPS_PROXY"
// NO_PROXY is the list of domains for which the proxy should not be used.
// Empty means unset and will not result in an env var.
envNoProxyName = "NO_PROXY"
)
var (
allProxyEnvVarNames = []string{
envHTTPProxyName,
envHTTPSProxyName,
envNoProxyName,
}
)
// ToEnvVar accepts a config Proxy object and returns an array of all three
// proxy variables with values.
//
// Please note that the function uses the status of the Proxy object to rea the
// proxy env variables. It's because OpenShift validates the proxy variables in
// spec and writes them back to status.
// As a consumer we should be reading off of proxy.status.
func ToEnvVar(proxy *apiconfigv1.Proxy) []corev1.EnvVar {
return []corev1.EnvVar{
{
Name: envHTTPProxyName,
Value: proxy.Status.HTTPProxy,
},
{
Name: envHTTPSProxyName,
Value: proxy.Status.HTTPSProxy,
},
{
Name: envNoProxyName,
Value: proxy.Status.NoProxy,
},
}
}