mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-30 06:54:01 +00:00
[cloud-controller-manager]output flags in logical sections
This commit is contained in:
parent
6daaf5af77
commit
a14673cfbd
@ -29,6 +29,7 @@ import (
|
||||
|
||||
"k8s.io/apimachinery/pkg/util/uuid"
|
||||
"k8s.io/apimachinery/pkg/util/wait"
|
||||
apiserverflag "k8s.io/apiserver/pkg/util/flag"
|
||||
"k8s.io/client-go/kubernetes"
|
||||
"k8s.io/client-go/tools/leaderelection"
|
||||
"k8s.io/client-go/tools/leaderelection/resourcelock"
|
||||
@ -77,7 +78,23 @@ the cloud specific control loops shipped with Kubernetes.`,
|
||||
|
||||
},
|
||||
}
|
||||
s.AddFlags(cmd.Flags())
|
||||
|
||||
fs := cmd.Flags()
|
||||
namedFlagSets := s.Flags()
|
||||
for _, f := range namedFlagSets.FlagSets {
|
||||
fs.AddFlagSet(f)
|
||||
}
|
||||
usageFmt := "Usage:\n %s\n"
|
||||
cols, _, _ := apiserverflag.TerminalSize(cmd.OutOrStdout())
|
||||
cmd.SetUsageFunc(func(cmd *cobra.Command) error {
|
||||
fmt.Fprintf(cmd.OutOrStderr(), usageFmt, cmd.UseLine())
|
||||
apiserverflag.PrintSections(cmd.OutOrStderr(), namedFlagSets, cols)
|
||||
return nil
|
||||
})
|
||||
cmd.SetHelpFunc(func(cmd *cobra.Command, args []string) {
|
||||
fmt.Fprintf(cmd.OutOrStdout(), "%s\n\n"+usageFmt, cmd.Long, cmd.UseLine())
|
||||
apiserverflag.PrintSections(cmd.OutOrStdout(), namedFlagSets, cols)
|
||||
})
|
||||
|
||||
return cmd
|
||||
}
|
||||
|
@ -28,6 +28,7 @@ import (
|
||||
utilerrors "k8s.io/apimachinery/pkg/util/errors"
|
||||
apiserveroptions "k8s.io/apiserver/pkg/server/options"
|
||||
utilfeature "k8s.io/apiserver/pkg/util/feature"
|
||||
apiserverflag "k8s.io/apiserver/pkg/util/flag"
|
||||
"k8s.io/client-go/informers"
|
||||
clientset "k8s.io/client-go/kubernetes"
|
||||
v1core "k8s.io/client-go/kubernetes/typed/core/v1"
|
||||
@ -45,7 +46,6 @@ import (
|
||||
_ "k8s.io/kubernetes/pkg/features"
|
||||
|
||||
"github.com/golang/glog"
|
||||
"github.com/spf13/pflag"
|
||||
)
|
||||
|
||||
const (
|
||||
@ -131,24 +131,27 @@ func NewDefaultComponentConfig(insecurePort int32) (componentconfig.CloudControl
|
||||
return internal, nil
|
||||
}
|
||||
|
||||
// AddFlags adds flags for a specific ExternalCMServer to the specified FlagSet
|
||||
func (o *CloudControllerManagerOptions) AddFlags(fs *pflag.FlagSet) {
|
||||
o.CloudProvider.AddFlags(fs)
|
||||
o.Debugging.AddFlags(fs)
|
||||
o.GenericComponent.AddFlags(fs)
|
||||
o.KubeCloudShared.AddFlags(fs)
|
||||
o.ServiceController.AddFlags(fs)
|
||||
// Flags returns flags for a specific APIServer by section name
|
||||
func (o *CloudControllerManagerOptions) Flags() (fss apiserverflag.NamedFlagSets) {
|
||||
o.CloudProvider.AddFlags(fss.FlagSet("cloud provider"))
|
||||
o.Debugging.AddFlags(fss.FlagSet("debugging"))
|
||||
o.GenericComponent.AddFlags(fss.FlagSet("generic"))
|
||||
o.KubeCloudShared.AddFlags(fss.FlagSet("generic"))
|
||||
o.ServiceController.AddFlags(fss.FlagSet("service controller"))
|
||||
|
||||
o.SecureServing.AddFlags(fs)
|
||||
o.InsecureServing.AddUnqualifiedFlags(fs)
|
||||
o.Authentication.AddFlags(fs)
|
||||
o.Authorization.AddFlags(fs)
|
||||
o.SecureServing.AddFlags(fss.FlagSet("secure serving"))
|
||||
o.InsecureServing.AddUnqualifiedFlags(fss.FlagSet("insecure serving"))
|
||||
o.Authentication.AddFlags(fss.FlagSet("authentication"))
|
||||
o.Authorization.AddFlags(fss.FlagSet("authorization"))
|
||||
|
||||
fs := fss.FlagSet("misc")
|
||||
fs.StringVar(&o.Master, "master", o.Master, "The address of the Kubernetes API server (overrides any value in kubeconfig).")
|
||||
fs.StringVar(&o.Kubeconfig, "kubeconfig", o.Kubeconfig, "Path to kubeconfig file with authorization and master location information.")
|
||||
fs.DurationVar(&o.NodeStatusUpdateFrequency.Duration, "node-status-update-frequency", o.NodeStatusUpdateFrequency.Duration, "Specifies how often the controller updates nodes' status.")
|
||||
|
||||
utilfeature.DefaultFeatureGate.AddFlag(fs)
|
||||
utilfeature.DefaultFeatureGate.AddFlag(fss.FlagSet("generic"))
|
||||
|
||||
return fss
|
||||
}
|
||||
|
||||
// ApplyTo fills up cloud controller manager config with options.
|
||||
|
@ -94,9 +94,11 @@ func TestDefaultFlags(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestAddFlags(t *testing.T) {
|
||||
f := pflag.NewFlagSet("addflagstest", pflag.ContinueOnError)
|
||||
fs := pflag.NewFlagSet("addflagstest", pflag.ContinueOnError)
|
||||
s, _ := NewCloudControllerManagerOptions()
|
||||
s.AddFlags(f)
|
||||
for _, f := range s.Flags().FlagSets {
|
||||
fs.AddFlagSet(f)
|
||||
}
|
||||
|
||||
args := []string{
|
||||
"--address=192.168.4.10",
|
||||
@ -129,7 +131,7 @@ func TestAddFlags(t *testing.T) {
|
||||
"--secure-port=10001",
|
||||
"--use-service-account-credentials=false",
|
||||
}
|
||||
f.Parse(args)
|
||||
fs.Parse(args)
|
||||
|
||||
expected := &CloudControllerManagerOptions{
|
||||
CloudProvider: &cmoptions.CloudProviderOptions{
|
||||
|
Loading…
Reference in New Issue
Block a user