mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-08 03:33:56 +00:00
Simplify creation of default KubeProxyConfiguration
This commit is contained in:
parent
10a869fc75
commit
0c9f55588c
@ -205,10 +205,22 @@ func (o *Options) AddFlags(fs *pflag.FlagSet) {
|
||||
fs.StringVar(&o.config.DetectLocal.InterfaceNamePrefix, "pod-interface-name-prefix", o.config.DetectLocal.InterfaceNamePrefix, "An interface prefix in the cluster. Kube-proxy considers traffic as local if originating from interfaces that match the given prefix. This argument should be set if DetectLocalMode is set to InterfaceNamePrefix.")
|
||||
}
|
||||
|
||||
// newKubeProxyConfiguration returns a KubeProxyConfiguration with default values
|
||||
func newKubeProxyConfiguration() *kubeproxyconfig.KubeProxyConfiguration {
|
||||
versionedConfig := &v1alpha1.KubeProxyConfiguration{}
|
||||
proxyconfigscheme.Scheme.Default(versionedConfig)
|
||||
internalConfig, err := proxyconfigscheme.Scheme.ConvertToVersion(versionedConfig, kubeproxyconfig.SchemeGroupVersion)
|
||||
if err != nil {
|
||||
panic(fmt.Sprintf("Unable to create default config: %v", err))
|
||||
}
|
||||
|
||||
return internalConfig.(*kubeproxyconfig.KubeProxyConfiguration)
|
||||
}
|
||||
|
||||
// NewOptions returns initialized Options
|
||||
func NewOptions() *Options {
|
||||
return &Options{
|
||||
config: new(kubeproxyconfig.KubeProxyConfiguration),
|
||||
config: newKubeProxyConfiguration(),
|
||||
healthzPort: ports.ProxyHealthzPort,
|
||||
metricsPort: ports.ProxyStatusPort,
|
||||
errCh: make(chan error),
|
||||
@ -438,25 +450,6 @@ func (o *Options) loadConfig(data []byte) (*kubeproxyconfig.KubeProxyConfigurati
|
||||
return proxyConfig, nil
|
||||
}
|
||||
|
||||
// ApplyDefaults applies the default values to Options.
|
||||
func (o *Options) ApplyDefaults(in *kubeproxyconfig.KubeProxyConfiguration) (*kubeproxyconfig.KubeProxyConfiguration, error) {
|
||||
external, err := proxyconfigscheme.Scheme.ConvertToVersion(in, v1alpha1.SchemeGroupVersion)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
proxyconfigscheme.Scheme.Default(external)
|
||||
|
||||
internal, err := proxyconfigscheme.Scheme.ConvertToVersion(external, kubeproxyconfig.SchemeGroupVersion)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
out := internal.(*kubeproxyconfig.KubeProxyConfiguration)
|
||||
|
||||
return out, nil
|
||||
}
|
||||
|
||||
// NewProxyCommand creates a *cobra.Command object with default parameters
|
||||
func NewProxyCommand() *cobra.Command {
|
||||
opts := NewOptions()
|
||||
@ -504,14 +497,6 @@ with the apiserver API to configure the proxy.`,
|
||||
},
|
||||
}
|
||||
|
||||
var err error
|
||||
opts.config, err = opts.ApplyDefaults(opts.config)
|
||||
if err != nil {
|
||||
klog.ErrorS(err, "Unable to create flag defaults")
|
||||
// ACTION REQUIRED: Exit code changed from 255 to 1
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
fs := cmd.Flags()
|
||||
opts.AddFlags(fs)
|
||||
fs.AddGoFlagSet(goflag.CommandLine) // for --boot-id-file and --machine-id-file
|
||||
|
Loading…
Reference in New Issue
Block a user