Skip to content

Commit 9b7d871

Browse files
committed
Add show hidden flag to kube-proxy
1 parent ec4f3e3 commit 9b7d871

File tree

6 files changed

+35
-3
lines changed

6 files changed

+35
-3
lines changed

cmd/kube-proxy/app/server.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,12 @@ func (o *Options) AddFlags(fs *pflag.FlagSet) {
150150
fs.StringVar(&o.master, "master", o.master, "The address of the Kubernetes API server (overrides any value in kubeconfig)")
151151
fs.StringVar(&o.hostnameOverride, "hostname-override", o.hostnameOverride, "If non-empty, will use this string as identification instead of the actual hostname.")
152152
fs.StringVar(&o.config.IPVS.Scheduler, "ipvs-scheduler", o.config.IPVS.Scheduler, "The ipvs scheduler type when proxy mode is ipvs")
153+
fs.StringVar(&o.config.ShowHiddenMetricsForVersion, "show-hidden-metrics-for-version", o.config.ShowHiddenMetricsForVersion,
154+
"The previous version for which you want to show hidden metrics. "+
155+
"Only the previous minor version is meaningful, other values will not be allowed. "+
156+
"The format is <major>.<minor>, e.g.: '1.16'. "+
157+
"The purpose of this format is make sure you have the opportunity to notice if the next release hides additional metrics, "+
158+
"rather than being surprised when they are permanently removed in the release after that.")
153159

154160
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.")
155161
fs.StringSliceVar(&o.config.NodePortAddresses, "nodeport-addresses", o.config.NodePortAddresses,

cmd/kube-proxy/app/server_others.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,15 @@ import (
3232
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
3333
utilfeature "k8s.io/apiserver/pkg/util/feature"
3434
"k8s.io/client-go/tools/record"
35+
"k8s.io/component-base/metrics"
3536
"k8s.io/kubernetes/pkg/features"
3637
"k8s.io/kubernetes/pkg/proxy"
3738
proxyconfigapi "k8s.io/kubernetes/pkg/proxy/apis/config"
3839
proxyconfigscheme "k8s.io/kubernetes/pkg/proxy/apis/config/scheme"
3940
"k8s.io/kubernetes/pkg/proxy/healthcheck"
4041
"k8s.io/kubernetes/pkg/proxy/iptables"
4142
"k8s.io/kubernetes/pkg/proxy/ipvs"
42-
"k8s.io/kubernetes/pkg/proxy/metrics"
43+
proxymetrics "k8s.io/kubernetes/pkg/proxy/metrics"
4344
"k8s.io/kubernetes/pkg/proxy/userspace"
4445
"k8s.io/kubernetes/pkg/util/configz"
4546
utilipset "k8s.io/kubernetes/pkg/util/ipset"
@@ -105,6 +106,10 @@ func newProxyServer(
105106
}, nil
106107
}
107108

109+
if len(config.ShowHiddenMetricsForVersion) > 0 {
110+
metrics.SetShowHidden()
111+
}
112+
108113
client, eventClient, err := createClients(config.ClientConnection, master)
109114
if err != nil {
110115
return nil, err
@@ -167,7 +172,7 @@ func newProxyServer(
167172
if err != nil {
168173
return nil, fmt.Errorf("unable to create proxier: %v", err)
169174
}
170-
metrics.RegisterMetrics()
175+
proxymetrics.RegisterMetrics()
171176
} else if proxyMode == proxyModeIPVS {
172177
klog.V(0).Info("Using ipvs Proxier.")
173178
if utilfeature.DefaultFeatureGate.Enabled(features.IPv6DualStack) {
@@ -228,7 +233,7 @@ func newProxyServer(
228233
if err != nil {
229234
return nil, fmt.Errorf("unable to create proxier: %v", err)
230235
}
231-
metrics.RegisterMetrics()
236+
proxymetrics.RegisterMetrics()
232237
} else {
233238
klog.V(0).Info("Using userspace Proxier.")
234239

cmd/kube-proxy/app/server_windows.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import (
3232
"k8s.io/apimachinery/pkg/types"
3333
utilnet "k8s.io/apimachinery/pkg/util/net"
3434
"k8s.io/client-go/tools/record"
35+
"k8s.io/component-base/metrics"
3536
"k8s.io/kubernetes/pkg/proxy"
3637
proxyconfigapi "k8s.io/kubernetes/pkg/proxy/apis/config"
3738
proxyconfigscheme "k8s.io/kubernetes/pkg/proxy/apis/config/scheme"
@@ -67,6 +68,10 @@ func newProxyServer(config *proxyconfigapi.KubeProxyConfiguration, cleanupAndExi
6768
return &ProxyServer{}, nil
6869
}
6970

71+
if len(config.ShowHiddenMetricsForVersion) > 0 {
72+
metrics.SetShowHidden()
73+
}
74+
7075
client, eventClient, err := createClients(config.ClientConnection, master)
7176
if err != nil {
7277
return nil, err

pkg/proxy/apis/config/types.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,8 @@ type KubeProxyConfiguration struct {
153153
NodePortAddresses []string
154154
// winkernel contains winkernel-related configuration options.
155155
Winkernel KubeProxyWinkernelConfiguration
156+
// ShowHiddenMetricsForVersion is the version for which you want to show hidden metrics.
157+
ShowHiddenMetricsForVersion string
156158
}
157159

158160
// Currently, three modes of proxy are available in Linux platform: 'userspace' (older, going to be EOL), 'iptables'

pkg/proxy/apis/config/validation/validation.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import (
2727
"k8s.io/apimachinery/pkg/util/sets"
2828
"k8s.io/apimachinery/pkg/util/validation/field"
2929
componentbaseconfig "k8s.io/component-base/config"
30+
"k8s.io/component-base/metrics"
3031
apivalidation "k8s.io/kubernetes/pkg/apis/core/validation"
3132
kubefeatures "k8s.io/kubernetes/pkg/features"
3233
kubeproxyconfig "k8s.io/kubernetes/pkg/proxy/apis/config"
@@ -87,6 +88,7 @@ func Validate(config *kubeproxyconfig.KubeProxyConfiguration) field.ErrorList {
8788
}
8889

8990
allErrs = append(allErrs, validateKubeProxyNodePortAddress(config.NodePortAddresses, newPath.Child("NodePortAddresses"))...)
91+
allErrs = append(allErrs, validateShowHiddenMetricsVersion(config.ShowHiddenMetricsForVersion, newPath.Child("ShowHiddenMetricsForVersion"))...)
9092

9193
return allErrs
9294
}
@@ -274,3 +276,13 @@ func validateIPVSExcludeCIDRs(excludeCIDRs []string, fldPath *field.Path) field.
274276
}
275277
return allErrs
276278
}
279+
280+
func validateShowHiddenMetricsVersion(version string, fldPath *field.Path) field.ErrorList {
281+
allErrs := field.ErrorList{}
282+
errs := metrics.ValidateShowHiddenMetricsVersion(version)
283+
for _, e := range errs {
284+
allErrs = append(allErrs, field.Invalid(fldPath, version, e.Error()))
285+
}
286+
287+
return allErrs
288+
}

staging/src/k8s.io/kube-proxy/config/v1alpha1/types.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,8 @@ type KubeProxyConfiguration struct {
149149
NodePortAddresses []string `json:"nodePortAddresses"`
150150
// winkernel contains winkernel-related configuration options.
151151
Winkernel KubeProxyWinkernelConfiguration `json:"winkernel"`
152+
// ShowHiddenMetricsForVersion is the version for which you want to show hidden metrics.
153+
ShowHiddenMetricsForVersion string `json:"showHiddenMetricsForVersion"`
152154
}
153155

154156
// Currently, three modes of proxy are available in Linux platform: 'userspace' (older, going to be EOL), 'iptables'

0 commit comments

Comments
 (0)