Skip to content

Commit

Permalink
refactor: provider an entrypoint to the infra provider meta handlers (#…
Browse files Browse the repository at this point in the history
…554)

**What problem does this PR solve?**:
This aligns the structure to how the lifecycle handlers are created.
More importantly it enables us to pass globalOptions to those infra
handlers that need it.

The goal of this is to use for the eventual refactor to support a more
generic kube-vip implementation. But for that I need to be able to read
a ConfigMap from the "default" namespace where all of these CMs are
created. Again similar to how its done for the CAAPH addons
https://github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/blob/33b29dc368622777d8dbea004077532c2a84d27a/pkg/handlers/generic/lifecycle/nfd/strategy_helmaddon.go#L56-L61

**Which issue(s) this PR fixes**:
Refactor to support work for https://jira.nutanix.com/browse/D2IQ-100364

**How Has This Been Tested?**:
<!--
Please describe the tests that you ran to verify your changes.
Provide output from the tests and any manual steps needed to replicate
the tests.
-->

**Special notes for your reviewer**:
<!--
Use this to provide any additional information to the reviewers.
This may include:
- Best way to review the PR.
- Where the author wants the most review attention on.
- etc.
-->
  • Loading branch information
dkoshkin committed Apr 25, 2024
1 parent 6ace5a6 commit db51743
Show file tree
Hide file tree
Showing 4 changed files with 123 additions and 40 deletions.
61 changes: 21 additions & 40 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,10 @@ import (
caaphv1 "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/api/external/sigs.k8s.io/cluster-api-addon-provider-helm/api/v1alpha1"
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/common/pkg/capi/clustertopology/handlers"
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/common/pkg/server"
awsclusterconfig "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/pkg/handlers/aws/clusterconfig"
awsmutation "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/pkg/handlers/aws/mutation"
awsworkerconfig "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/pkg/handlers/aws/workerconfig"
dockerclusterconfig "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/pkg/handlers/docker/clusterconfig"
dockermutation "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/pkg/handlers/docker/mutation"
dockerworkerconfig "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/pkg/handlers/docker/workerconfig"
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/pkg/handlers/aws"
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/pkg/handlers/docker"
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/pkg/handlers/generic/lifecycle"
nutanixclusterconfig "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/pkg/handlers/nutanix/clusterconfig"
nutanixmutation "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/pkg/handlers/nutanix/mutation"
nutanixworkerconfig "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/pkg/handlers/nutanix/workerconfig"
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/pkg/handlers/nutanix"
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/pkg/handlers/options"
)

Expand Down Expand Up @@ -84,12 +78,27 @@ func main() {

genericLifecycleHandlers := lifecycle.New(globalOptions)

// awsMetaHandlers combines all AWS patch and variable handlers under a single handler.
// It allows to specify configuration under a single variable.
awsMetaHandlers := aws.New(globalOptions)

// dockerMetaHandlers combines all Docker patch and variable handlers under a single handler.
// It allows to specify configuration under a single variable.
dockerMetaHandlers := docker.New(globalOptions)

// nutanixMetaHandlers combines all Nutanix patch and variable handlers under a single handler.
// It allows to specify configuration under a single variable.
nutanixMetaHandlers := nutanix.New(globalOptions)

// Initialize and parse command line flags.
logs.AddFlags(pflag.CommandLine, logs.SkipLoggingConfigurationFlags())
logsv1.AddFlags(logOptions, pflag.CommandLine)
globalOptions.AddFlags(pflag.CommandLine)
runtimeWebhookServerOpts.AddFlags(pflag.CommandLine)
genericLifecycleHandlers.AddFlags(pflag.CommandLine)
awsMetaHandlers.AddFlags(pflag.CommandLine)
dockerMetaHandlers.AddFlags(pflag.CommandLine)
nutanixMetaHandlers.AddFlags(pflag.CommandLine)
pflag.CommandLine.SetNormalizeFunc(cliflag.WordSepNormalizeFunc)
pflag.CommandLine.AddGoFlagSet(flag.CommandLine)
pflag.Parse()
Expand All @@ -113,39 +122,11 @@ func main() {
os.Exit(1)
}

// This genericMetaPatchHandlers combines all other patch and variable handlers under a single handler.
// It allows to specify configuration under a single variable.
// awsMetaHandlers combines all AWS patch and variable handlers under a single handler.
awsMetaHandlers := []handlers.Named{
awsclusterconfig.NewVariable(),
awsworkerconfig.NewVariable(),
awsmutation.MetaPatchHandler(mgr),
awsmutation.MetaWorkerPatchHandler(mgr),
}

// dockerMetaHandlers combines all Docker patch and variable handlers under a single handler.
// It allows to specify configuration under a single variable.
dockerMetaHandlers := []handlers.Named{
dockerclusterconfig.NewVariable(),
dockerworkerconfig.NewVariable(),
dockermutation.MetaPatchHandler(mgr),
dockermutation.MetaWorkerPatchHandler(mgr),
}

// nutanixMetaHandlers combines all Nutanix patch and variable handlers under a single handler.
// It allows to specify configuration under a single variable.
nutanixMetaHandlers := []handlers.Named{
nutanixclusterconfig.NewVariable(),
nutanixworkerconfig.NewVariable(),
nutanixmutation.MetaPatchHandler(mgr),
nutanixmutation.MetaWorkerPatchHandler(mgr),
}

var allHandlers []handlers.Named
allHandlers = append(allHandlers, genericLifecycleHandlers.AllHandlers(mgr)...)
allHandlers = append(allHandlers, awsMetaHandlers...)
allHandlers = append(allHandlers, dockerMetaHandlers...)
allHandlers = append(allHandlers, nutanixMetaHandlers...)
allHandlers = append(allHandlers, awsMetaHandlers.AllHandlers(mgr)...)
allHandlers = append(allHandlers, dockerMetaHandlers.AllHandlers(mgr)...)
allHandlers = append(allHandlers, nutanixMetaHandlers.AllHandlers(mgr)...)

runtimeWebhookServer := server.NewServer(runtimeWebhookServerOpts, allHandlers...)

Expand Down
34 changes: 34 additions & 0 deletions pkg/handlers/aws/handlers.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Copyright 2023 D2iQ, Inc. All rights reserved.
// SPDX-License-Identifier: Apache-2.0

package aws

import (
"github.com/spf13/pflag"
"sigs.k8s.io/controller-runtime/pkg/manager"

"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/common/pkg/capi/clustertopology/handlers"
awsclusterconfig "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/pkg/handlers/aws/clusterconfig"
awsmutation "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/pkg/handlers/aws/mutation"
awsworkerconfig "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/pkg/handlers/aws/workerconfig"
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/pkg/handlers/options"
)

type Handlers struct{}

func New(
_ *options.GlobalOptions,
) *Handlers {
return &Handlers{}
}

func (h *Handlers) AllHandlers(mgr manager.Manager) []handlers.Named {
return []handlers.Named{
awsclusterconfig.NewVariable(),
awsworkerconfig.NewVariable(),
awsmutation.MetaPatchHandler(mgr),
awsmutation.MetaWorkerPatchHandler(mgr),
}
}

func (h *Handlers) AddFlags(_ *pflag.FlagSet) {}
34 changes: 34 additions & 0 deletions pkg/handlers/docker/handlers.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Copyright 2023 D2iQ, Inc. All rights reserved.
// SPDX-License-Identifier: Apache-2.0

package docker

import (
"github.com/spf13/pflag"
"sigs.k8s.io/controller-runtime/pkg/manager"

"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/common/pkg/capi/clustertopology/handlers"
dockerclusterconfig "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/pkg/handlers/docker/clusterconfig"
dockermutation "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/pkg/handlers/docker/mutation"
dockerworkerconfig "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/pkg/handlers/docker/workerconfig"
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/pkg/handlers/options"
)

type Handlers struct{}

func New(
_ *options.GlobalOptions,
) *Handlers {
return &Handlers{}
}

func (h *Handlers) AllHandlers(mgr manager.Manager) []handlers.Named {
return []handlers.Named{
dockerclusterconfig.NewVariable(),
dockerworkerconfig.NewVariable(),
dockermutation.MetaPatchHandler(mgr),
dockermutation.MetaWorkerPatchHandler(mgr),
}
}

func (h *Handlers) AddFlags(_ *pflag.FlagSet) {}
34 changes: 34 additions & 0 deletions pkg/handlers/nutanix/handlers.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Copyright 2023 D2iQ, Inc. All rights reserved.
// SPDX-License-Identifier: Apache-2.0

package nutanix

import (
"github.com/spf13/pflag"
"sigs.k8s.io/controller-runtime/pkg/manager"

"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/common/pkg/capi/clustertopology/handlers"
nutanixclusterconfig "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/pkg/handlers/nutanix/clusterconfig"
nutanixmutation "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/pkg/handlers/nutanix/mutation"
nutanixworkerconfig "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/pkg/handlers/nutanix/workerconfig"
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/pkg/handlers/options"
)

type Handlers struct{}

func New(
_ *options.GlobalOptions,
) *Handlers {
return &Handlers{}
}

func (h *Handlers) AllHandlers(mgr manager.Manager) []handlers.Named {
return []handlers.Named{
nutanixclusterconfig.NewVariable(),
nutanixworkerconfig.NewVariable(),
nutanixmutation.MetaPatchHandler(mgr),
nutanixmutation.MetaWorkerPatchHandler(mgr),
}
}

func (h *Handlers) AddFlags(_ *pflag.FlagSet) {}

0 comments on commit db51743

Please sign in to comment.