mirror of
				https://github.com/k3s-io/kubernetes.git
				synced 2025-11-03 23:40:03 +00:00 
			
		
		
		
	propagate proxy env var to kube-proxy
Signed-off-by: Yassine TIJANI <ytijani@vmware.com>
This commit is contained in:
		@@ -22,7 +22,7 @@ import (
 | 
			
		||||
 | 
			
		||||
	"github.com/pkg/errors"
 | 
			
		||||
	apps "k8s.io/api/apps/v1"
 | 
			
		||||
	"k8s.io/api/core/v1"
 | 
			
		||||
	v1 "k8s.io/api/core/v1"
 | 
			
		||||
	rbac "k8s.io/api/rbac/v1"
 | 
			
		||||
	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
 | 
			
		||||
	kuberuntime "k8s.io/apimachinery/pkg/runtime"
 | 
			
		||||
@@ -129,6 +129,8 @@ func createKubeProxyAddon(configMapBytes, daemonSetbytes []byte, client clientse
 | 
			
		||||
	if err := kuberuntime.DecodeInto(clientsetscheme.Codecs.UniversalDecoder(), daemonSetbytes, kubeproxyDaemonSet); err != nil {
 | 
			
		||||
		return errors.Wrap(err, "unable to decode kube-proxy daemonset")
 | 
			
		||||
	}
 | 
			
		||||
	// propagate http/https proxy env vars
 | 
			
		||||
	kubeproxyDaemonSet.Spec.Template.Spec.Containers[0].Env = kubeadmutil.GetProxyEnvVars()
 | 
			
		||||
 | 
			
		||||
	// Create the DaemonSet for kube-proxy or update it in case it already exists
 | 
			
		||||
	return apiclient.CreateOrUpdateDaemonSet(client, kubeproxyDaemonSet)
 | 
			
		||||
 
 | 
			
		||||
@@ -19,7 +19,6 @@ package controlplane
 | 
			
		||||
import (
 | 
			
		||||
	"fmt"
 | 
			
		||||
	"net"
 | 
			
		||||
	"os"
 | 
			
		||||
	"path/filepath"
 | 
			
		||||
	"strconv"
 | 
			
		||||
	"strings"
 | 
			
		||||
@@ -59,7 +58,7 @@ func GetStaticPodSpecs(cfg *kubeadmapi.ClusterConfiguration, endpoint *kubeadmap
 | 
			
		||||
			VolumeMounts:    staticpodutil.VolumeMountMapToSlice(mounts.GetVolumeMounts(kubeadmconstants.KubeAPIServer)),
 | 
			
		||||
			LivenessProbe:   staticpodutil.LivenessProbe(staticpodutil.GetAPIServerProbeAddress(endpoint), "/healthz", int(endpoint.BindPort), v1.URISchemeHTTPS),
 | 
			
		||||
			Resources:       staticpodutil.ComponentResources("250m"),
 | 
			
		||||
			Env:             getProxyEnvVars(),
 | 
			
		||||
			Env:             kubeadmutil.GetProxyEnvVars(),
 | 
			
		||||
		}, mounts.GetVolumes(kubeadmconstants.KubeAPIServer)),
 | 
			
		||||
		kubeadmconstants.KubeControllerManager: staticpodutil.ComponentPod(v1.Container{
 | 
			
		||||
			Name:            kubeadmconstants.KubeControllerManager,
 | 
			
		||||
@@ -69,7 +68,7 @@ func GetStaticPodSpecs(cfg *kubeadmapi.ClusterConfiguration, endpoint *kubeadmap
 | 
			
		||||
			VolumeMounts:    staticpodutil.VolumeMountMapToSlice(mounts.GetVolumeMounts(kubeadmconstants.KubeControllerManager)),
 | 
			
		||||
			LivenessProbe:   staticpodutil.LivenessProbe(staticpodutil.GetControllerManagerProbeAddress(cfg), "/healthz", kubeadmconstants.InsecureKubeControllerManagerPort, v1.URISchemeHTTP),
 | 
			
		||||
			Resources:       staticpodutil.ComponentResources("200m"),
 | 
			
		||||
			Env:             getProxyEnvVars(),
 | 
			
		||||
			Env:             kubeadmutil.GetProxyEnvVars(),
 | 
			
		||||
		}, mounts.GetVolumes(kubeadmconstants.KubeControllerManager)),
 | 
			
		||||
		kubeadmconstants.KubeScheduler: staticpodutil.ComponentPod(v1.Container{
 | 
			
		||||
			Name:            kubeadmconstants.KubeScheduler,
 | 
			
		||||
@@ -79,7 +78,7 @@ func GetStaticPodSpecs(cfg *kubeadmapi.ClusterConfiguration, endpoint *kubeadmap
 | 
			
		||||
			VolumeMounts:    staticpodutil.VolumeMountMapToSlice(mounts.GetVolumeMounts(kubeadmconstants.KubeScheduler)),
 | 
			
		||||
			LivenessProbe:   staticpodutil.LivenessProbe(staticpodutil.GetSchedulerProbeAddress(cfg), "/healthz", kubeadmconstants.InsecureSchedulerPort, v1.URISchemeHTTP),
 | 
			
		||||
			Resources:       staticpodutil.ComponentResources("100m"),
 | 
			
		||||
			Env:             getProxyEnvVars(),
 | 
			
		||||
			Env:             kubeadmutil.GetProxyEnvVars(),
 | 
			
		||||
		}, mounts.GetVolumes(kubeadmconstants.KubeScheduler)),
 | 
			
		||||
	}
 | 
			
		||||
	return staticPodSpecs
 | 
			
		||||
@@ -359,22 +358,3 @@ func getSchedulerCommand(cfg *kubeadmapi.ClusterConfiguration) []string {
 | 
			
		||||
	command = append(command, kubeadmutil.BuildArgumentListFromMap(defaultArguments, cfg.Scheduler.ExtraArgs)...)
 | 
			
		||||
	return command
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// getProxyEnvVars builds a list of environment variables to use in the control plane containers in order to use the right proxy
 | 
			
		||||
func getProxyEnvVars() []v1.EnvVar {
 | 
			
		||||
	envs := []v1.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 := v1.EnvVar{Name: name, Value: value}
 | 
			
		||||
			envs = append(envs, envVar)
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
	return envs
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -9,6 +9,7 @@ go_library(
 | 
			
		||||
        "chroot_windows.go",
 | 
			
		||||
        "copy.go",
 | 
			
		||||
        "endpoint.go",
 | 
			
		||||
        "env.go",
 | 
			
		||||
        "error.go",
 | 
			
		||||
        "marshal.go",
 | 
			
		||||
        "net.go",
 | 
			
		||||
@@ -20,6 +21,7 @@ go_library(
 | 
			
		||||
    deps = [
 | 
			
		||||
        "//cmd/kubeadm/app/apis/kubeadm:go_default_library",
 | 
			
		||||
        "//cmd/kubeadm/app/constants:go_default_library",
 | 
			
		||||
        "//staging/src/k8s.io/api/core/v1:go_default_library",
 | 
			
		||||
        "//staging/src/k8s.io/apimachinery/pkg/runtime:go_default_library",
 | 
			
		||||
        "//staging/src/k8s.io/apimachinery/pkg/runtime/schema:go_default_library",
 | 
			
		||||
        "//staging/src/k8s.io/apimachinery/pkg/runtime/serializer:go_default_library",
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										43
									
								
								cmd/kubeadm/app/util/env.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										43
									
								
								cmd/kubeadm/app/util/env.go
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,43 @@
 | 
			
		||||
/*
 | 
			
		||||
Copyright 2019 The Kubernetes Authors.
 | 
			
		||||
 | 
			
		||||
Licensed under the Apache License, Version 2.0 (the "License");
 | 
			
		||||
you may not use this file except in compliance with the License.
 | 
			
		||||
You may obtain a copy of the License at
 | 
			
		||||
 | 
			
		||||
    http://www.apache.org/licenses/LICENSE-2.0
 | 
			
		||||
 | 
			
		||||
Unless required by applicable law or agreed to in writing, software
 | 
			
		||||
distributed under the License is distributed on an "AS IS" BASIS,
 | 
			
		||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 | 
			
		||||
See the License for the specific language governing permissions and
 | 
			
		||||
limitations under the License.
 | 
			
		||||
*/
 | 
			
		||||
 | 
			
		||||
package util
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"os"
 | 
			
		||||
	"strings"
 | 
			
		||||
 | 
			
		||||
	v1 "k8s.io/api/core/v1"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
// GetProxyEnvVars builds a list of environment variables in order to use the right proxy
 | 
			
		||||
func GetProxyEnvVars() []v1.EnvVar {
 | 
			
		||||
	envs := []v1.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 := v1.EnvVar{Name: name, Value: value}
 | 
			
		||||
			envs = append(envs, envVar)
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
	return envs
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user