diff --git a/cmd/kube-proxy/app/server.go b/cmd/kube-proxy/app/server.go index c32e561d8a0..ae30e758ede 100644 --- a/cmd/kube-proxy/app/server.go +++ b/cmd/kube-proxy/app/server.go @@ -150,6 +150,12 @@ func (o *Options) AddFlags(fs *pflag.FlagSet) { fs.StringVar(&o.master, "master", o.master, "The address of the Kubernetes API server (overrides any value in kubeconfig)") fs.StringVar(&o.hostnameOverride, "hostname-override", o.hostnameOverride, "If non-empty, will use this string as identification instead of the actual hostname.") fs.StringVar(&o.config.IPVS.Scheduler, "ipvs-scheduler", o.config.IPVS.Scheduler, "The ipvs scheduler type when proxy mode is ipvs") + fs.StringVar(&o.config.ShowHiddenMetricsForVersion, "show-hidden-metrics-for-version", o.config.ShowHiddenMetricsForVersion, + "The previous version for which you want to show hidden metrics. "+ + "Only the previous minor version is meaningful, other values will not be allowed. "+ + "The format is ., e.g.: '1.16'. "+ + "The purpose of this format is make sure you have the opportunity to notice if the next release hides additional metrics, "+ + "rather than being surprised when they are permanently removed in the release after that.") fs.StringSliceVar(&o.config.IPVS.ExcludeCIDRs, "ipvs-exclude-cidrs", o.config.IPVS.ExcludeCIDRs, "A comma-separated list of CIDR's which the ipvs proxier should not touch when cleaning up IPVS rules.") fs.StringSliceVar(&o.config.NodePortAddresses, "nodeport-addresses", o.config.NodePortAddresses, diff --git a/cmd/kube-proxy/app/server_others.go b/cmd/kube-proxy/app/server_others.go index fd622863a0a..e4f96a26975 100644 --- a/cmd/kube-proxy/app/server_others.go +++ b/cmd/kube-proxy/app/server_others.go @@ -32,6 +32,7 @@ import ( utilruntime "k8s.io/apimachinery/pkg/util/runtime" utilfeature "k8s.io/apiserver/pkg/util/feature" "k8s.io/client-go/tools/record" + "k8s.io/component-base/metrics" "k8s.io/kubernetes/pkg/features" "k8s.io/kubernetes/pkg/proxy" proxyconfigapi "k8s.io/kubernetes/pkg/proxy/apis/config" @@ -39,7 +40,7 @@ import ( "k8s.io/kubernetes/pkg/proxy/healthcheck" "k8s.io/kubernetes/pkg/proxy/iptables" "k8s.io/kubernetes/pkg/proxy/ipvs" - "k8s.io/kubernetes/pkg/proxy/metrics" + proxymetrics "k8s.io/kubernetes/pkg/proxy/metrics" "k8s.io/kubernetes/pkg/proxy/userspace" "k8s.io/kubernetes/pkg/util/configz" utilipset "k8s.io/kubernetes/pkg/util/ipset" @@ -105,6 +106,10 @@ func newProxyServer( }, nil } + if len(config.ShowHiddenMetricsForVersion) > 0 { + metrics.SetShowHidden() + } + client, eventClient, err := createClients(config.ClientConnection, master) if err != nil { return nil, err @@ -167,7 +172,7 @@ func newProxyServer( if err != nil { return nil, fmt.Errorf("unable to create proxier: %v", err) } - metrics.RegisterMetrics() + proxymetrics.RegisterMetrics() } else if proxyMode == proxyModeIPVS { klog.V(0).Info("Using ipvs Proxier.") if utilfeature.DefaultFeatureGate.Enabled(features.IPv6DualStack) { @@ -228,7 +233,7 @@ func newProxyServer( if err != nil { return nil, fmt.Errorf("unable to create proxier: %v", err) } - metrics.RegisterMetrics() + proxymetrics.RegisterMetrics() } else { klog.V(0).Info("Using userspace Proxier.") diff --git a/cmd/kube-proxy/app/server_windows.go b/cmd/kube-proxy/app/server_windows.go index b67d85073e7..f94ec6c5297 100644 --- a/cmd/kube-proxy/app/server_windows.go +++ b/cmd/kube-proxy/app/server_windows.go @@ -32,6 +32,7 @@ import ( "k8s.io/apimachinery/pkg/types" utilnet "k8s.io/apimachinery/pkg/util/net" "k8s.io/client-go/tools/record" + "k8s.io/component-base/metrics" "k8s.io/kubernetes/pkg/proxy" proxyconfigapi "k8s.io/kubernetes/pkg/proxy/apis/config" proxyconfigscheme "k8s.io/kubernetes/pkg/proxy/apis/config/scheme" @@ -67,6 +68,10 @@ func newProxyServer(config *proxyconfigapi.KubeProxyConfiguration, cleanupAndExi return &ProxyServer{}, nil } + if len(config.ShowHiddenMetricsForVersion) > 0 { + metrics.SetShowHidden() + } + client, eventClient, err := createClients(config.ClientConnection, master) if err != nil { return nil, err diff --git a/pkg/proxy/apis/config/types.go b/pkg/proxy/apis/config/types.go index b1314fc2e88..cf0b6a32483 100644 --- a/pkg/proxy/apis/config/types.go +++ b/pkg/proxy/apis/config/types.go @@ -153,6 +153,8 @@ type KubeProxyConfiguration struct { NodePortAddresses []string // winkernel contains winkernel-related configuration options. Winkernel KubeProxyWinkernelConfiguration + // ShowHiddenMetricsForVersion is the version for which you want to show hidden metrics. + ShowHiddenMetricsForVersion string } // Currently, three modes of proxy are available in Linux platform: 'userspace' (older, going to be EOL), 'iptables' diff --git a/pkg/proxy/apis/config/validation/validation.go b/pkg/proxy/apis/config/validation/validation.go index ccd38d1b9f0..773dd542dc2 100644 --- a/pkg/proxy/apis/config/validation/validation.go +++ b/pkg/proxy/apis/config/validation/validation.go @@ -27,6 +27,7 @@ import ( "k8s.io/apimachinery/pkg/util/sets" "k8s.io/apimachinery/pkg/util/validation/field" componentbaseconfig "k8s.io/component-base/config" + "k8s.io/component-base/metrics" apivalidation "k8s.io/kubernetes/pkg/apis/core/validation" kubefeatures "k8s.io/kubernetes/pkg/features" kubeproxyconfig "k8s.io/kubernetes/pkg/proxy/apis/config" @@ -87,6 +88,7 @@ func Validate(config *kubeproxyconfig.KubeProxyConfiguration) field.ErrorList { } allErrs = append(allErrs, validateKubeProxyNodePortAddress(config.NodePortAddresses, newPath.Child("NodePortAddresses"))...) + allErrs = append(allErrs, validateShowHiddenMetricsVersion(config.ShowHiddenMetricsForVersion, newPath.Child("ShowHiddenMetricsForVersion"))...) return allErrs } @@ -274,3 +276,13 @@ func validateIPVSExcludeCIDRs(excludeCIDRs []string, fldPath *field.Path) field. } return allErrs } + +func validateShowHiddenMetricsVersion(version string, fldPath *field.Path) field.ErrorList { + allErrs := field.ErrorList{} + errs := metrics.ValidateShowHiddenMetricsVersion(version) + for _, e := range errs { + allErrs = append(allErrs, field.Invalid(fldPath, version, e.Error())) + } + + return allErrs +} diff --git a/staging/src/k8s.io/kube-proxy/config/v1alpha1/types.go b/staging/src/k8s.io/kube-proxy/config/v1alpha1/types.go index 8bc7894e481..6ed58cc0562 100644 --- a/staging/src/k8s.io/kube-proxy/config/v1alpha1/types.go +++ b/staging/src/k8s.io/kube-proxy/config/v1alpha1/types.go @@ -149,6 +149,8 @@ type KubeProxyConfiguration struct { NodePortAddresses []string `json:"nodePortAddresses"` // winkernel contains winkernel-related configuration options. Winkernel KubeProxyWinkernelConfiguration `json:"winkernel"` + // ShowHiddenMetricsForVersion is the version for which you want to show hidden metrics. + ShowHiddenMetricsForVersion string `json:"showHiddenMetricsForVersion"` } // Currently, three modes of proxy are available in Linux platform: 'userspace' (older, going to be EOL), 'iptables'