Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: provider an entrypoint to the infra provider meta handlers #554

Merged
merged 2 commits into from
Apr 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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) {}
Loading