mirror of https://github.com/k3s-io/k3s
Merge pull request #37494 from kad/issue-36573
Automatic merge from submit-queue (batch tested with PRs 36990, 37494, 38152, 37561, 38136) Pass proxy environment variables to static pods **What this PR does / why we need it**: To access outside world or cloud provider APIs it might be required to use proxy. kubeadm will be passing proxy variables to static pods during init stage. **Which issue this PR fixes** *(optional, in `fixes #<issue number>(, fixes #<issue_number>, ...)` format, will close that issue when PR gets merged)*: fixes kubernetes/kubernetes#36573, kubernetes/kubeadm#5 **Special notes for your reviewer**: **Release note**: ```release-note - kubeadm will pass proxy environment variables to static pods. ```pull/6/head
commit
6331bec5d2
|
@ -76,6 +76,7 @@ func WriteStaticPodManifests(cfg *kubeadmapi.MasterConfiguration) error {
|
|||
VolumeMounts: volumeMounts,
|
||||
LivenessProbe: componentProbe(8080, "/healthz"),
|
||||
Resources: componentResources("250m"),
|
||||
Env: getProxyEnvVars(),
|
||||
}, volumes...),
|
||||
kubeControllerManager: componentPod(api.Container{
|
||||
Name: kubeControllerManager,
|
||||
|
@ -84,6 +85,7 @@ func WriteStaticPodManifests(cfg *kubeadmapi.MasterConfiguration) error {
|
|||
VolumeMounts: volumeMounts,
|
||||
LivenessProbe: componentProbe(10252, "/healthz"),
|
||||
Resources: componentResources("200m"),
|
||||
Env: getProxyEnvVars(),
|
||||
}, volumes...),
|
||||
kubeScheduler: componentPod(api.Container{
|
||||
Name: kubeScheduler,
|
||||
|
@ -91,6 +93,7 @@ func WriteStaticPodManifests(cfg *kubeadmapi.MasterConfiguration) error {
|
|||
Command: getSchedulerCommand(cfg),
|
||||
LivenessProbe: componentProbe(10251, "/healthz"),
|
||||
Resources: componentResources("100m"),
|
||||
Env: getProxyEnvVars(),
|
||||
}),
|
||||
}
|
||||
|
||||
|
@ -359,3 +362,21 @@ func getProxyCommand(cfg *kubeadmapi.MasterConfiguration) (command []string) {
|
|||
|
||||
return
|
||||
}
|
||||
|
||||
func getProxyEnvVars() []api.EnvVar {
|
||||
envs := []api.EnvVar{}
|
||||
for _, env := range os.Environ() {
|
||||
pos := strings.Index(env, "=")
|
||||
if pos == -1 {
|
||||
// malformed environment variable, skip it.
|
||||
continue
|
||||
}
|
||||
name := env[:pos]
|
||||
value := env[pos+1:]
|
||||
if strings.HasSuffix(strings.ToLower(name), "_proxy") && value != "" {
|
||||
envVar := api.EnvVar{Name: name, Value: value}
|
||||
envs = append(envs, envVar)
|
||||
}
|
||||
}
|
||||
return envs
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue