Skip to content

Commit

Permalink
refactor(mgr) flip flags from disabled to enabled
Browse files Browse the repository at this point in the history
Change the controller flags from disablers to enablers and flip the
logic that handles them.

Remove unnecessary pointer usage.
  • Loading branch information
Travis Raines committed Aug 3, 2021
1 parent 668decb commit 7c34d87
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 49 deletions.
48 changes: 24 additions & 24 deletions internal/manager/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,17 +62,17 @@ type Config struct {
UpdateStatus bool

// Kubernetes API toggling
IngressExtV1beta1Disabled bool
IngressNetV1beta1Disabled bool
IngressNetV1Disabled bool
UDPIngressDisabled bool
TCPIngressDisabled bool
KongIngressDisabled bool
KnativeIngressDisabled bool
KongClusterPluginDisabled bool
KongPluginDisabled bool
KongConsumerDisabled bool
ServiceDisabled bool
IngressExtV1beta1Enabled bool
IngressNetV1beta1Enabled bool
IngressNetV1Enabled bool
UDPIngressEnabled bool
TCPIngressEnabled bool
KongIngressEnabled bool
KnativeIngressEnabled bool
KongClusterPluginEnabled bool
KongPluginEnabled bool
KongConsumerEnabled bool
ServiceEnabled bool

// Admission Webhook server config
AdmissionServer admission.ServerConfig
Expand All @@ -90,7 +90,7 @@ type Config struct {
// FlagSet binds the provided Config to commandline flags.
func (c *Config) FlagSet() *pflag.FlagSet {

flagSet := *pflag.NewFlagSet("", pflag.ExitOnError)
flagSet := pflag.NewFlagSet("", pflag.ExitOnError)

// Logging configurations
flagSet.StringVar(&c.LogLevel, "log-level", "info", `Level of logging for the controller. Allowed values are trace, debug, info, warn, error, fatal and panic.`)
Expand Down Expand Up @@ -148,17 +148,17 @@ func (c *Config) FlagSet() *pflag.FlagSet {
`Indicates if the ingress controller should update the status of resources (e.g. IP/Hostname for v1.Ingress, e.t.c.)`)

// Kubernetes API toggling
flagSet.BoolVar(&c.IngressNetV1Disabled, "disable-controller-ingress-networkingv1", false, "Disable the networking.k8s.io/v1 Ingress controller.")
flagSet.BoolVar(&c.IngressNetV1beta1Disabled, "disable-controller-ingress-networkingv1beta1", false, "Disable the networking.k8s.io/v1beta1 Ingress controller.")
flagSet.BoolVar(&c.IngressExtV1beta1Disabled, "disable-controller-ingress-extensionsv1beta1", false, "Disable the extensions/v1beta1 Ingress controller.")
flagSet.BoolVar(&c.UDPIngressDisabled, "disable-controller-udpingress", false, "Disable the UDPIngress controller.")
flagSet.BoolVar(&c.TCPIngressDisabled, "disable-controller-tcpingress", false, "Disable the TCPIngress controller.")
flagSet.BoolVar(&c.KnativeIngressDisabled, "disable-controller-knativeingress", false, "Disable the KnativeIngress controller.")
flagSet.BoolVar(&c.KongIngressDisabled, "disable-controller-kongingress", false, "Disable the KongIngress controller.")
flagSet.BoolVar(&c.KongClusterPluginDisabled, "disable-controller-kongclusterplugin", false, "Disable the KongClusterPlugin controller.")
flagSet.BoolVar(&c.KongPluginDisabled, "disable-controller-kongplugin", false, "Disable the KongPlugin controller.")
flagSet.BoolVar(&c.KongConsumerDisabled, "disable-controller-kongconsumer", false, "Disable the KongConsumer controller. ")
flagSet.BoolVar(&c.ServiceDisabled, "disable-controller-service", false, "Disable the Service controller.")
flagSet.BoolVar(&c.IngressNetV1Enabled, "enable-controller-ingress-networkingv1", true, "Enable the networking.k8s.io/v1 Ingress controller.")
flagSet.BoolVar(&c.IngressNetV1beta1Enabled, "enable-controller-ingress-networkingv1beta1", true, "Enable the networking.k8s.io/v1beta1 Ingress controller.")
flagSet.BoolVar(&c.IngressExtV1beta1Enabled, "enable-controller-ingress-extensionsv1beta1", true, "Enable the extensions/v1beta1 Ingress controller.")
flagSet.BoolVar(&c.UDPIngressEnabled, "enable-controller-udpingress", true, "Enable the UDPIngress controller.")
flagSet.BoolVar(&c.TCPIngressEnabled, "enable-controller-tcpingress", true, "Enable the TCPIngress controller.")
flagSet.BoolVar(&c.KnativeIngressEnabled, "enable-controller-knativeingress", true, "Enable the KnativeIngress controller.")
flagSet.BoolVar(&c.KongIngressEnabled, "enable-controller-kongingress", true, "Enable the KongIngress controller.")
flagSet.BoolVar(&c.KongClusterPluginEnabled, "enable-controller-kongclusterplugin", true, "Enable the KongClusterPlugin controller.")
flagSet.BoolVar(&c.KongPluginEnabled, "enable-controller-kongplugin", true, "Enable the KongPlugin controller.")
flagSet.BoolVar(&c.KongConsumerEnabled, "enable-controller-kongconsumer", true, "Enable the KongConsumer controller. ")
flagSet.BoolVar(&c.ServiceEnabled, "enable-controller-service", true, "Enable the Service controller.")

// Admission Webhook server config
flagSet.StringVar(&c.AdmissionServer.ListenAddr, "admission-webhook-listen", "off",
Expand Down Expand Up @@ -188,7 +188,7 @@ func (c *Config) FlagSet() *pflag.FlagSet {
flagSet.Int("stderrthreshold", 0, "DEPRECATED: has no effect and will be removed in future releases (see github issue #1297)")
flagSet.Bool("update-status-on-shutdown", false, `DEPRECATED: no longer has any effect and will be removed in a later release (see github issue #1304)`)

return &flagSet
return flagSet
}

func (c *Config) GetKongClient(ctx context.Context) (*kong.Client, error) {
Expand Down
30 changes: 15 additions & 15 deletions internal/manager/controllerdef.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ type AutoHandler func(client.Client) bool

// ControllerDef is a specification of a Controller that can be conditionally registered with Manager.
type ControllerDef struct {
IsDisabled *bool
Enabled bool
AutoHandler AutoHandler
Controller Controller
}
Expand All @@ -44,7 +44,7 @@ func (c *ControllerDef) Name() string {
// MaybeSetupWithManager runs SetupWithManager on the controller if it is enabled
// and its AutoHandler (if any) indicates that it can load
func (c *ControllerDef) MaybeSetupWithManager(mgr ctrl.Manager) error {
if *c.IsDisabled {
if !c.Enabled {
return nil
}

Expand Down Expand Up @@ -72,7 +72,7 @@ func setupControllers(logger logr.Logger, mgr manager.Manager, proxy proxy.Proxy
// Core API Controllers
// ---------------------------------------------------------------------------
{
IsDisabled: &c.IngressNetV1Disabled,
Enabled: c.IngressNetV1Enabled,
AutoHandler: ingressPicker.IsNetV1,
Controller: &configuration.NetV1IngressReconciler{
Client: mgr.GetClient(),
Expand All @@ -83,7 +83,7 @@ func setupControllers(logger logr.Logger, mgr manager.Manager, proxy proxy.Proxy
},
},
{
IsDisabled: &c.IngressNetV1beta1Disabled,
Enabled: c.IngressNetV1beta1Enabled,
AutoHandler: ingressPicker.IsNetV1beta1,
Controller: &configuration.NetV1Beta1IngressReconciler{
Client: mgr.GetClient(),
Expand All @@ -94,7 +94,7 @@ func setupControllers(logger logr.Logger, mgr manager.Manager, proxy proxy.Proxy
},
},
{
IsDisabled: &c.IngressExtV1beta1Disabled,
Enabled: c.IngressExtV1beta1Enabled,
AutoHandler: ingressPicker.IsExtV1beta1,
Controller: &configuration.ExtV1Beta1IngressReconciler{
Client: mgr.GetClient(),
Expand All @@ -105,7 +105,7 @@ func setupControllers(logger logr.Logger, mgr manager.Manager, proxy proxy.Proxy
},
},
{
IsDisabled: &c.ServiceDisabled,
Enabled: c.ServiceEnabled,
Controller: &configuration.CoreV1ServiceReconciler{
Client: mgr.GetClient(),
Log: ctrl.Log.WithName("controllers").WithName("Service"),
Expand All @@ -114,7 +114,7 @@ func setupControllers(logger logr.Logger, mgr manager.Manager, proxy proxy.Proxy
},
},
{
IsDisabled: &c.ServiceDisabled,
Enabled: c.ServiceEnabled,
Controller: &configuration.CoreV1EndpointsReconciler{
Client: mgr.GetClient(),
Log: ctrl.Log.WithName("controllers").WithName("Endpoints"),
Expand All @@ -123,7 +123,7 @@ func setupControllers(logger logr.Logger, mgr manager.Manager, proxy proxy.Proxy
},
},
{
IsDisabled: &neverDisabled,
Enabled: true,
Controller: &configuration.CoreV1SecretReconciler{
Client: mgr.GetClient(),
Log: ctrl.Log.WithName("controllers").WithName("Secrets"),
Expand All @@ -135,7 +135,7 @@ func setupControllers(logger logr.Logger, mgr manager.Manager, proxy proxy.Proxy
// Kong API Controllers
// ---------------------------------------------------------------------------
{
IsDisabled: &c.UDPIngressDisabled,
Enabled: c.UDPIngressEnabled,
Controller: &configuration.KongV1Beta1UDPIngressReconciler{
Client: mgr.GetClient(),
Log: ctrl.Log.WithName("controllers").WithName("UDPIngress"),
Expand All @@ -145,7 +145,7 @@ func setupControllers(logger logr.Logger, mgr manager.Manager, proxy proxy.Proxy
},
},
{
IsDisabled: &c.TCPIngressDisabled,
Enabled: c.TCPIngressEnabled,
Controller: &configuration.KongV1Beta1TCPIngressReconciler{
Client: mgr.GetClient(),
Log: ctrl.Log.WithName("controllers").WithName("TCPIngress"),
Expand All @@ -155,7 +155,7 @@ func setupControllers(logger logr.Logger, mgr manager.Manager, proxy proxy.Proxy
},
},
{
IsDisabled: &c.KongIngressDisabled,
Enabled: c.KongIngressEnabled,
Controller: &configuration.KongV1KongIngressReconciler{
Client: mgr.GetClient(),
Log: ctrl.Log.WithName("controllers").WithName("KongIngress"),
Expand All @@ -164,7 +164,7 @@ func setupControllers(logger logr.Logger, mgr manager.Manager, proxy proxy.Proxy
},
},
{
IsDisabled: &c.KongPluginDisabled,
Enabled: c.KongPluginEnabled,
Controller: &configuration.KongV1KongPluginReconciler{
Client: mgr.GetClient(),
Log: ctrl.Log.WithName("controllers").WithName("KongPlugin"),
Expand All @@ -173,7 +173,7 @@ func setupControllers(logger logr.Logger, mgr manager.Manager, proxy proxy.Proxy
},
},
{
IsDisabled: &c.KongConsumerDisabled,
Enabled: c.KongConsumerEnabled,
Controller: &configuration.KongV1KongConsumerReconciler{
Client: mgr.GetClient(),
Log: ctrl.Log.WithName("controllers").WithName("KongConsumer"),
Expand All @@ -183,7 +183,7 @@ func setupControllers(logger logr.Logger, mgr manager.Manager, proxy proxy.Proxy
},
},
{
IsDisabled: &c.KongClusterPluginDisabled,
Enabled: c.KongClusterPluginEnabled,
AutoHandler: crdExistsChecker{GVR: schema.GroupVersionResource{
Group: konghqcomv1.SchemeGroupVersion.Group,
Version: konghqcomv1.SchemeGroupVersion.Version,
Expand All @@ -198,7 +198,7 @@ func setupControllers(logger logr.Logger, mgr manager.Manager, proxy proxy.Proxy
},
},
{
IsDisabled: &c.KnativeIngressDisabled,
Enabled: c.KnativeIngressEnabled,
AutoHandler: crdExistsChecker{GVR: schema.GroupVersionResource{
Group: knativev1alpha1.SchemeGroupVersion.Group,
Version: knativev1alpha1.SchemeGroupVersion.Version,
Expand Down
6 changes: 3 additions & 3 deletions internal/manager/ingressapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,15 @@ func negotiateIngressAPI(config *Config, client client.Client) (IngressAPI, erro
},
}

if config.IngressNetV1Disabled != true {
if config.IngressNetV1Enabled == true {
allowedAPIs = append(allowedAPIs, NetworkingV1)
}

if config.IngressNetV1beta1Disabled != true {
if config.IngressNetV1beta1Enabled == true {
allowedAPIs = append(allowedAPIs, NetworkingV1beta1)
}

if config.IngressExtV1beta1Disabled != true {
if config.IngressExtV1beta1Enabled == true {
allowedAPIs = append(allowedAPIs, ExtensionsV1beta1)
}

Expand Down
7 changes: 0 additions & 7 deletions internal/manager/vars.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,3 @@ var (
// See: "go doc cmd/link" for details, and "Dockerfile" for invocation via "go build".
Commit = "UNKNOWN"
)

// -----------------------------------------------------------------------------
// Controller Manager - Configuration Vars
// -----------------------------------------------------------------------------

// neverDisabled is a convenience alias to indicate that a controller cannot be disabled
var neverDisabled = false

0 comments on commit 7c34d87

Please sign in to comment.