Skip to content

Commit 9693eea

Browse files
authored
Merge pull request kubernetes#128824 from yongruilin/flagz-controller-manager
feat: Add flagz endpoint for kube-controller-manager
2 parents 21f7eaa + 97db9a7 commit 9693eea

File tree

4 files changed

+22
-0
lines changed

4 files changed

+22
-0
lines changed

cmd/kube-controller-manager/app/config/config.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,15 @@ import (
2222
restclient "k8s.io/client-go/rest"
2323
"k8s.io/client-go/tools/record"
2424
basecompatibility "k8s.io/component-base/compatibility"
25+
"k8s.io/component-base/zpages/flagz"
2526
kubectrlmgrconfig "k8s.io/kubernetes/pkg/controller/apis/config"
2627
)
2728

2829
// Config is the main context object for the controller manager.
2930
type Config struct {
31+
// Flagz is the Reader interface to get flags for the flagz page.
32+
Flagz flagz.Reader
33+
3034
ComponentConfig kubectrlmgrconfig.KubeControllerManagerConfiguration
3135

3236
SecureServing *apiserver.SecureServingInfo

cmd/kube-controller-manager/app/controllermanager.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ import (
6666
utilversion "k8s.io/component-base/version"
6767
"k8s.io/component-base/version/verflag"
6868
zpagesfeatures "k8s.io/component-base/zpages/features"
69+
"k8s.io/component-base/zpages/flagz"
6970
"k8s.io/component-base/zpages/statusz"
7071
genericcontrollermanager "k8s.io/controller-manager/app"
7172
"k8s.io/controller-manager/controller"
@@ -156,6 +157,7 @@ controller, and serviceaccounts controller.`,
156157

157158
fs := cmd.Flags()
158159
namedFlagSets := s.Flags(KnownControllers(), ControllersDisabledByDefault(), ControllerAliases())
160+
s.ParsedFlags = &namedFlagSets
159161
verflag.AddFlags(namedFlagSets.FlagSet("global"))
160162
globalflag.AddGlobalFlags(namedFlagSets.FlagSet("global"), cmd.Name(), logs.SkipLoggingConfigurationFlags())
161163
for _, f := range namedFlagSets.FlagSets {
@@ -213,6 +215,11 @@ func Run(ctx context.Context, c *config.CompletedConfig) error {
213215
if c.SecureServing != nil {
214216
unsecuredMux = genericcontrollermanager.NewBaseHandler(&c.ComponentConfig.Generic.Debugging, healthzHandler)
215217
slis.SLIMetricsWithReset{}.Install(unsecuredMux)
218+
if utilfeature.DefaultFeatureGate.Enabled(zpagesfeatures.ComponentFlagz) {
219+
if c.Flagz != nil {
220+
flagz.Install(unsecuredMux, kubeControllerManager, c.Flagz)
221+
}
222+
}
216223

217224
if utilfeature.DefaultFeatureGate.Enabled(zpagesfeatures.ComponentStatusz) {
218225
statusz.Install(unsecuredMux, kubeControllerManager, statusz.NewRegistry(c.ComponentGlobalsRegistry.EffectiveVersionFor(basecompatibility.DefaultKubeComponent)))

cmd/kube-controller-manager/app/options/options.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ import (
4242
"k8s.io/component-base/logs"
4343
logsapi "k8s.io/component-base/logs/api/v1"
4444
"k8s.io/component-base/metrics"
45+
"k8s.io/component-base/zpages/flagz"
4546
cmoptions "k8s.io/controller-manager/options"
4647
"k8s.io/klog/v2"
4748
kubectrlmgrconfigv1alpha1 "k8s.io/kube-controller-manager/config/v1alpha1"
@@ -108,6 +109,9 @@ type KubeControllerManagerOptions struct {
108109

109110
// ComponentGlobalsRegistry is the registry where the effective versions and feature gates for all components are stored.
110111
ComponentGlobalsRegistry basecompatibility.ComponentGlobalsRegistry
112+
113+
// Parsedflags holds the parsed CLI flags.
114+
ParsedFlags *cliflag.NamedFlagSets
111115
}
112116

113117
// NewKubeControllerManagerOptions creates a new KubeControllerManagerOptions with a default config.
@@ -510,5 +514,11 @@ func (s KubeControllerManagerOptions) Config(allControllers []string, disabledBy
510514
}
511515
s.Metrics.Apply()
512516

517+
if s.ParsedFlags != nil {
518+
c.Flagz = flagz.NamedFlagSetsReader{
519+
FlagSets: *s.ParsedFlags,
520+
}
521+
}
522+
513523
return c, nil
514524
}

cmd/kube-controller-manager/app/testing/testserver.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ func StartTestServer(ctx context.Context, customFlags []string) (result TestServ
102102
fs.AddFlagSet(f)
103103
}
104104
fs.Parse(customFlags)
105+
s.ParsedFlags = &namedFlagSets
105106

106107
if s.SecureServing.BindPort != 0 {
107108
s.SecureServing.Listener, s.SecureServing.BindPort, err = createListenerOnFreePort()

0 commit comments

Comments
 (0)