mirror of https://github.com/k3s-io/k3s
controller-manager: make InsecureServingOptions/Config re-usable
parent
81478b804e
commit
01881d3f0c
|
@ -23,7 +23,6 @@ import (
|
|||
"github.com/spf13/pflag"
|
||||
"k8s.io/apiserver/pkg/server/options"
|
||||
genericcontrollermanager "k8s.io/kubernetes/cmd/controller-manager/app"
|
||||
"k8s.io/kubernetes/pkg/apis/componentconfig"
|
||||
)
|
||||
|
||||
// InsecureServingOptions are for creating an unauthenticated, unauthorized, insecure port.
|
||||
|
@ -43,12 +42,12 @@ type InsecureServingOptions struct {
|
|||
|
||||
// Validate ensures that the insecure port values within the range of the port.
|
||||
func (s *InsecureServingOptions) Validate() []error {
|
||||
errors := []error{}
|
||||
|
||||
if s == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
errors := []error{}
|
||||
|
||||
if s.BindPort < 0 || s.BindPort > 32767 {
|
||||
errors = append(errors, fmt.Errorf("--insecure-port %v must be between 0 and 32767, inclusive. 0 for turning off insecure (HTTP) port", s.BindPort))
|
||||
}
|
||||
|
@ -61,20 +60,10 @@ func (s *InsecureServingOptions) AddFlags(fs *pflag.FlagSet) {
|
|||
if s == nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// AddDeprecatedFlags adds deprecated flags related to insecure serving for controller manager to the specified FlagSet.
|
||||
// TODO: remove it until kops stop using `--address`
|
||||
func (s *InsecureServingOptions) AddDeprecatedFlags(fs *pflag.FlagSet) {
|
||||
if s == nil {
|
||||
return
|
||||
}
|
||||
|
||||
fs.IPVar(&s.BindAddress, "address", s.BindAddress,
|
||||
"DEPRECATED: the IP address on which to listen for the --port port. See --bind-address instead.")
|
||||
fs.IPVar(&s.BindAddress, "address", s.BindAddress, "DEPRECATED: the IP address on which to listen for the --port port. See --bind-address instead.")
|
||||
// MarkDeprecated hides the flag from the help. We don't want that:
|
||||
// fs.MarkDeprecated("address", "see --bind-address instead.")
|
||||
|
||||
fs.IntVar(&s.BindPort, "port", s.BindPort, "DEPRECATED: the port on which to serve HTTP insecurely without authentication and authorization. If 0, don't serve HTTPS at all. See --secure-port instead.")
|
||||
// MarkDeprecated hides the flag from the help. We don't want that:
|
||||
// fs.MarkDeprecated("port", "see --secure-port instead.")
|
||||
|
@ -82,7 +71,7 @@ func (s *InsecureServingOptions) AddDeprecatedFlags(fs *pflag.FlagSet) {
|
|||
|
||||
// ApplyTo adds InsecureServingOptions to the insecureserverinfo amd kube-controller manager configuration.
|
||||
// Note: the double pointer allows to set the *InsecureServingInfo to nil without referencing the struct hosting this pointer.
|
||||
func (s *InsecureServingOptions) ApplyTo(c **genericcontrollermanager.InsecureServingInfo, cfg *componentconfig.KubeCloudSharedConfiguration) error {
|
||||
func (s *InsecureServingOptions) ApplyTo(c **genericcontrollermanager.InsecureServingInfo) error {
|
||||
if s == nil {
|
||||
return nil
|
||||
}
|
||||
|
@ -103,10 +92,5 @@ func (s *InsecureServingOptions) ApplyTo(c **genericcontrollermanager.InsecureSe
|
|||
Listener: s.Listener,
|
||||
}
|
||||
|
||||
// sync back to component config
|
||||
// TODO: find more elegant way than synching back the values.
|
||||
cfg.Port = int32(s.BindPort)
|
||||
cfg.Address = s.BindAddress.String()
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -225,7 +225,6 @@ func (o *GenericControllerManagerOptions) AddFlags(fs *pflag.FlagSet) {
|
|||
o.ServiceController.AddFlags(fs)
|
||||
o.SecureServing.AddFlags(fs)
|
||||
o.InsecureServing.AddFlags(fs)
|
||||
o.InsecureServing.AddDeprecatedFlags(fs)
|
||||
o.Authentication.AddFlags(fs)
|
||||
o.Authorization.AddFlags(fs)
|
||||
}
|
||||
|
@ -304,7 +303,7 @@ func (o *GenericControllerManagerOptions) ApplyTo(c *genericcontrollermanager.Co
|
|||
if err := o.SecureServing.ApplyTo(&c.SecureServing); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := o.InsecureServing.ApplyTo(&c.InsecureServing, &c.ComponentConfig.KubeCloudShared); err != nil {
|
||||
if err := o.InsecureServing.ApplyTo(&c.InsecureServing); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := o.Authentication.ApplyTo(&c.Authentication, c.SecureServing, nil); err != nil {
|
||||
|
@ -314,6 +313,11 @@ func (o *GenericControllerManagerOptions) ApplyTo(c *genericcontrollermanager.Co
|
|||
return err
|
||||
}
|
||||
|
||||
// sync back to component config
|
||||
// TODO: find more elegant way than synching back the values.
|
||||
c.ComponentConfig.KubeCloudShared.Port = int32(o.InsecureServing.BindPort)
|
||||
c.ComponentConfig.KubeCloudShared.Address = o.InsecureServing.BindAddress.String()
|
||||
|
||||
var err error
|
||||
c.Kubeconfig, err = clientcmd.BuildConfigFromFlags(o.Master, o.Kubeconfig)
|
||||
if err != nil {
|
||||
|
|
Loading…
Reference in New Issue