Merge pull request #128824 from yongruilin/flagz-controller-manager

feat: Add flagz endpoint for kube-controller-manager
This commit is contained in:
Kubernetes Prow Robot 2025-03-12 13:35:47 -07:00 committed by GitHub
commit 9693eea5c3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 22 additions and 0 deletions

View File

@ -22,11 +22,15 @@ import (
restclient "k8s.io/client-go/rest"
"k8s.io/client-go/tools/record"
basecompatibility "k8s.io/component-base/compatibility"
"k8s.io/component-base/zpages/flagz"
kubectrlmgrconfig "k8s.io/kubernetes/pkg/controller/apis/config"
)
// Config is the main context object for the controller manager.
type Config struct {
// Flagz is the Reader interface to get flags for the flagz page.
Flagz flagz.Reader
ComponentConfig kubectrlmgrconfig.KubeControllerManagerConfiguration
SecureServing *apiserver.SecureServingInfo

View File

@ -66,6 +66,7 @@ import (
utilversion "k8s.io/component-base/version"
"k8s.io/component-base/version/verflag"
zpagesfeatures "k8s.io/component-base/zpages/features"
"k8s.io/component-base/zpages/flagz"
"k8s.io/component-base/zpages/statusz"
genericcontrollermanager "k8s.io/controller-manager/app"
"k8s.io/controller-manager/controller"
@ -156,6 +157,7 @@ controller, and serviceaccounts controller.`,
fs := cmd.Flags()
namedFlagSets := s.Flags(KnownControllers(), ControllersDisabledByDefault(), ControllerAliases())
s.ParsedFlags = &namedFlagSets
verflag.AddFlags(namedFlagSets.FlagSet("global"))
globalflag.AddGlobalFlags(namedFlagSets.FlagSet("global"), cmd.Name(), logs.SkipLoggingConfigurationFlags())
for _, f := range namedFlagSets.FlagSets {
@ -213,6 +215,11 @@ func Run(ctx context.Context, c *config.CompletedConfig) error {
if c.SecureServing != nil {
unsecuredMux = genericcontrollermanager.NewBaseHandler(&c.ComponentConfig.Generic.Debugging, healthzHandler)
slis.SLIMetricsWithReset{}.Install(unsecuredMux)
if utilfeature.DefaultFeatureGate.Enabled(zpagesfeatures.ComponentFlagz) {
if c.Flagz != nil {
flagz.Install(unsecuredMux, kubeControllerManager, c.Flagz)
}
}
if utilfeature.DefaultFeatureGate.Enabled(zpagesfeatures.ComponentStatusz) {
statusz.Install(unsecuredMux, kubeControllerManager, statusz.NewRegistry(c.ComponentGlobalsRegistry.EffectiveVersionFor(basecompatibility.DefaultKubeComponent)))

View File

@ -42,6 +42,7 @@ import (
"k8s.io/component-base/logs"
logsapi "k8s.io/component-base/logs/api/v1"
"k8s.io/component-base/metrics"
"k8s.io/component-base/zpages/flagz"
cmoptions "k8s.io/controller-manager/options"
"k8s.io/klog/v2"
kubectrlmgrconfigv1alpha1 "k8s.io/kube-controller-manager/config/v1alpha1"
@ -108,6 +109,9 @@ type KubeControllerManagerOptions struct {
// ComponentGlobalsRegistry is the registry where the effective versions and feature gates for all components are stored.
ComponentGlobalsRegistry basecompatibility.ComponentGlobalsRegistry
// Parsedflags holds the parsed CLI flags.
ParsedFlags *cliflag.NamedFlagSets
}
// NewKubeControllerManagerOptions creates a new KubeControllerManagerOptions with a default config.
@ -510,5 +514,11 @@ func (s KubeControllerManagerOptions) Config(allControllers []string, disabledBy
}
s.Metrics.Apply()
if s.ParsedFlags != nil {
c.Flagz = flagz.NamedFlagSetsReader{
FlagSets: *s.ParsedFlags,
}
}
return c, nil
}

View File

@ -102,6 +102,7 @@ func StartTestServer(ctx context.Context, customFlags []string) (result TestServ
fs.AddFlagSet(f)
}
fs.Parse(customFlags)
s.ParsedFlags = &namedFlagSets
if s.SecureServing.BindPort != 0 {
s.SecureServing.Listener, s.SecureServing.BindPort, err = createListenerOnFreePort()