controller-manager: make InsecureServingOptions/Config re-usable

pull/8/head
Dr. Stefan Schimanski 2018-02-24 15:45:59 +01:00
parent 81478b804e
commit 01881d3f0c
2 changed files with 10 additions and 22 deletions

View File

@ -23,7 +23,6 @@ import (
"github.com/spf13/pflag" "github.com/spf13/pflag"
"k8s.io/apiserver/pkg/server/options" "k8s.io/apiserver/pkg/server/options"
genericcontrollermanager "k8s.io/kubernetes/cmd/controller-manager/app" genericcontrollermanager "k8s.io/kubernetes/cmd/controller-manager/app"
"k8s.io/kubernetes/pkg/apis/componentconfig"
) )
// InsecureServingOptions are for creating an unauthenticated, unauthorized, insecure port. // 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. // Validate ensures that the insecure port values within the range of the port.
func (s *InsecureServingOptions) Validate() []error { func (s *InsecureServingOptions) Validate() []error {
errors := []error{}
if s == nil { if s == nil {
return nil return nil
} }
errors := []error{}
if s.BindPort < 0 || s.BindPort > 32767 { 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)) 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 { if s == nil {
return return
} }
}
// AddDeprecatedFlags adds deprecated flags related to insecure serving for controller manager to the specified FlagSet. fs.IPVar(&s.BindAddress, "address", s.BindAddress, "DEPRECATED: the IP address on which to listen for the --port port. See --bind-address instead.")
// 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.")
// MarkDeprecated hides the flag from the help. We don't want that: // MarkDeprecated hides the flag from the help. We don't want that:
// fs.MarkDeprecated("address", "see --bind-address instead.") // 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.") 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: // MarkDeprecated hides the flag from the help. We don't want that:
// fs.MarkDeprecated("port", "see --secure-port instead.") // 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. // 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. // 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 { if s == nil {
return nil return nil
} }
@ -103,10 +92,5 @@ func (s *InsecureServingOptions) ApplyTo(c **genericcontrollermanager.InsecureSe
Listener: s.Listener, 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 return nil
} }

View File

@ -225,7 +225,6 @@ func (o *GenericControllerManagerOptions) AddFlags(fs *pflag.FlagSet) {
o.ServiceController.AddFlags(fs) o.ServiceController.AddFlags(fs)
o.SecureServing.AddFlags(fs) o.SecureServing.AddFlags(fs)
o.InsecureServing.AddFlags(fs) o.InsecureServing.AddFlags(fs)
o.InsecureServing.AddDeprecatedFlags(fs)
o.Authentication.AddFlags(fs) o.Authentication.AddFlags(fs)
o.Authorization.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 { if err := o.SecureServing.ApplyTo(&c.SecureServing); err != nil {
return err 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 return err
} }
if err := o.Authentication.ApplyTo(&c.Authentication, c.SecureServing, nil); err != nil { 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 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 var err error
c.Kubeconfig, err = clientcmd.BuildConfigFromFlags(o.Master, o.Kubeconfig) c.Kubeconfig, err = clientcmd.BuildConfigFromFlags(o.Master, o.Kubeconfig)
if err != nil { if err != nil {