Skip to content

Commit

Permalink
Merge pull request kubernetes#85281 from RainbowMango/pr_add_metrics_…
Browse files Browse the repository at this point in the history
…flag_to_controller_manager

Allow show hidden metrics in kube-controller-manager
  • Loading branch information
k8s-ci-robot authored Jan 16, 2020
2 parents 2b6d875 + 0412369 commit d9bf22f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
1 change: 1 addition & 0 deletions cmd/kube-controller-manager/app/options/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ go_library(
"//staging/src/k8s.io/client-go/tools/clientcmd:go_default_library",
"//staging/src/k8s.io/client-go/tools/record:go_default_library",
"//staging/src/k8s.io/component-base/cli/flag:go_default_library",
"//staging/src/k8s.io/component-base/metrics:go_default_library",
"//staging/src/k8s.io/kube-controller-manager/config/v1alpha1:go_default_library",
"//vendor/github.com/spf13/pflag:go_default_library",
"//vendor/k8s.io/klog:go_default_library",
Expand Down
19 changes: 17 additions & 2 deletions cmd/kube-controller-manager/app/options/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import (
"k8s.io/client-go/tools/clientcmd"
"k8s.io/client-go/tools/record"
cliflag "k8s.io/component-base/cli/flag"
"k8s.io/component-base/metrics"
kubectrlmgrconfigv1alpha1 "k8s.io/kube-controller-manager/config/v1alpha1"
cmoptions "k8s.io/kubernetes/cmd/controller-manager/app/options"
kubecontrollerconfig "k8s.io/kubernetes/cmd/kube-controller-manager/app/config"
Expand Down Expand Up @@ -87,8 +88,9 @@ type KubeControllerManagerOptions struct {
Authentication *apiserveroptions.DelegatingAuthenticationOptions
Authorization *apiserveroptions.DelegatingAuthorizationOptions

Master string
Kubeconfig string
Master string
Kubeconfig string
ShowHiddenMetricsForVersion string
}

// NewKubeControllerManagerOptions creates a new KubeControllerManagerOptions with a default config.
Expand Down Expand Up @@ -250,6 +252,14 @@ func (s *KubeControllerManagerOptions) Flags(allControllers []string, disabledBy
fs.StringVar(&s.Kubeconfig, "kubeconfig", s.Kubeconfig, "Path to kubeconfig file with authorization and master location information.")
utilfeature.DefaultMutableFeatureGate.AddFlag(fss.FlagSet("generic"))

mfs := fss.FlagSet("metrics")
mfs.StringVar(&s.ShowHiddenMetricsForVersion, "show-hidden-metrics-for-version", s.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 <major>.<minor>, 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.")

return fss
}

Expand Down Expand Up @@ -382,6 +392,7 @@ func (s *KubeControllerManagerOptions) Validate(allControllers []string, disable
errs = append(errs, s.InsecureServing.Validate()...)
errs = append(errs, s.Authentication.Validate()...)
errs = append(errs, s.Authorization.Validate()...)
errs = append(errs, metrics.ValidateShowHiddenMetricsVersion(s.ShowHiddenMetricsForVersion)...)

// TODO: validate component config, master and kubeconfig

Expand Down Expand Up @@ -430,6 +441,10 @@ func (s KubeControllerManagerOptions) Config(allControllers []string, disabledBy
return nil, err
}

if len(s.ShowHiddenMetricsForVersion) > 0 {
metrics.SetShowHidden()
}

return c, nil
}

Expand Down

0 comments on commit d9bf22f

Please sign in to comment.