Skip to content

Commit db51743

Browse files
authored
refactor: provider an entrypoint to the infra provider meta handlers (#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. -->
1 parent 6ace5a6 commit db51743

File tree

4 files changed

+123
-40
lines changed

4 files changed

+123
-40
lines changed

cmd/main.go

Lines changed: 21 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,10 @@ import (
2727
caaphv1 "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/api/external/sigs.k8s.io/cluster-api-addon-provider-helm/api/v1alpha1"
2828
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/common/pkg/capi/clustertopology/handlers"
2929
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/common/pkg/server"
30-
awsclusterconfig "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/pkg/handlers/aws/clusterconfig"
31-
awsmutation "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/pkg/handlers/aws/mutation"
32-
awsworkerconfig "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/pkg/handlers/aws/workerconfig"
33-
dockerclusterconfig "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/pkg/handlers/docker/clusterconfig"
34-
dockermutation "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/pkg/handlers/docker/mutation"
35-
dockerworkerconfig "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/pkg/handlers/docker/workerconfig"
30+
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/pkg/handlers/aws"
31+
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/pkg/handlers/docker"
3632
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/pkg/handlers/generic/lifecycle"
37-
nutanixclusterconfig "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/pkg/handlers/nutanix/clusterconfig"
38-
nutanixmutation "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/pkg/handlers/nutanix/mutation"
39-
nutanixworkerconfig "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/pkg/handlers/nutanix/workerconfig"
33+
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/pkg/handlers/nutanix"
4034
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/pkg/handlers/options"
4135
)
4236

@@ -84,12 +78,27 @@ func main() {
8478

8579
genericLifecycleHandlers := lifecycle.New(globalOptions)
8680

81+
// awsMetaHandlers combines all AWS patch and variable handlers under a single handler.
82+
// It allows to specify configuration under a single variable.
83+
awsMetaHandlers := aws.New(globalOptions)
84+
85+
// dockerMetaHandlers combines all Docker patch and variable handlers under a single handler.
86+
// It allows to specify configuration under a single variable.
87+
dockerMetaHandlers := docker.New(globalOptions)
88+
89+
// nutanixMetaHandlers combines all Nutanix patch and variable handlers under a single handler.
90+
// It allows to specify configuration under a single variable.
91+
nutanixMetaHandlers := nutanix.New(globalOptions)
92+
8793
// Initialize and parse command line flags.
8894
logs.AddFlags(pflag.CommandLine, logs.SkipLoggingConfigurationFlags())
8995
logsv1.AddFlags(logOptions, pflag.CommandLine)
9096
globalOptions.AddFlags(pflag.CommandLine)
9197
runtimeWebhookServerOpts.AddFlags(pflag.CommandLine)
9298
genericLifecycleHandlers.AddFlags(pflag.CommandLine)
99+
awsMetaHandlers.AddFlags(pflag.CommandLine)
100+
dockerMetaHandlers.AddFlags(pflag.CommandLine)
101+
nutanixMetaHandlers.AddFlags(pflag.CommandLine)
93102
pflag.CommandLine.SetNormalizeFunc(cliflag.WordSepNormalizeFunc)
94103
pflag.CommandLine.AddGoFlagSet(flag.CommandLine)
95104
pflag.Parse()
@@ -113,39 +122,11 @@ func main() {
113122
os.Exit(1)
114123
}
115124

116-
// This genericMetaPatchHandlers combines all other patch and variable handlers under a single handler.
117-
// It allows to specify configuration under a single variable.
118-
// awsMetaHandlers combines all AWS patch and variable handlers under a single handler.
119-
awsMetaHandlers := []handlers.Named{
120-
awsclusterconfig.NewVariable(),
121-
awsworkerconfig.NewVariable(),
122-
awsmutation.MetaPatchHandler(mgr),
123-
awsmutation.MetaWorkerPatchHandler(mgr),
124-
}
125-
126-
// dockerMetaHandlers combines all Docker patch and variable handlers under a single handler.
127-
// It allows to specify configuration under a single variable.
128-
dockerMetaHandlers := []handlers.Named{
129-
dockerclusterconfig.NewVariable(),
130-
dockerworkerconfig.NewVariable(),
131-
dockermutation.MetaPatchHandler(mgr),
132-
dockermutation.MetaWorkerPatchHandler(mgr),
133-
}
134-
135-
// nutanixMetaHandlers combines all Nutanix patch and variable handlers under a single handler.
136-
// It allows to specify configuration under a single variable.
137-
nutanixMetaHandlers := []handlers.Named{
138-
nutanixclusterconfig.NewVariable(),
139-
nutanixworkerconfig.NewVariable(),
140-
nutanixmutation.MetaPatchHandler(mgr),
141-
nutanixmutation.MetaWorkerPatchHandler(mgr),
142-
}
143-
144125
var allHandlers []handlers.Named
145126
allHandlers = append(allHandlers, genericLifecycleHandlers.AllHandlers(mgr)...)
146-
allHandlers = append(allHandlers, awsMetaHandlers...)
147-
allHandlers = append(allHandlers, dockerMetaHandlers...)
148-
allHandlers = append(allHandlers, nutanixMetaHandlers...)
127+
allHandlers = append(allHandlers, awsMetaHandlers.AllHandlers(mgr)...)
128+
allHandlers = append(allHandlers, dockerMetaHandlers.AllHandlers(mgr)...)
129+
allHandlers = append(allHandlers, nutanixMetaHandlers.AllHandlers(mgr)...)
149130

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

pkg/handlers/aws/handlers.go

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// Copyright 2023 D2iQ, Inc. All rights reserved.
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
package aws
5+
6+
import (
7+
"github.com/spf13/pflag"
8+
"sigs.k8s.io/controller-runtime/pkg/manager"
9+
10+
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/common/pkg/capi/clustertopology/handlers"
11+
awsclusterconfig "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/pkg/handlers/aws/clusterconfig"
12+
awsmutation "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/pkg/handlers/aws/mutation"
13+
awsworkerconfig "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/pkg/handlers/aws/workerconfig"
14+
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/pkg/handlers/options"
15+
)
16+
17+
type Handlers struct{}
18+
19+
func New(
20+
_ *options.GlobalOptions,
21+
) *Handlers {
22+
return &Handlers{}
23+
}
24+
25+
func (h *Handlers) AllHandlers(mgr manager.Manager) []handlers.Named {
26+
return []handlers.Named{
27+
awsclusterconfig.NewVariable(),
28+
awsworkerconfig.NewVariable(),
29+
awsmutation.MetaPatchHandler(mgr),
30+
awsmutation.MetaWorkerPatchHandler(mgr),
31+
}
32+
}
33+
34+
func (h *Handlers) AddFlags(_ *pflag.FlagSet) {}

pkg/handlers/docker/handlers.go

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// Copyright 2023 D2iQ, Inc. All rights reserved.
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
package docker
5+
6+
import (
7+
"github.com/spf13/pflag"
8+
"sigs.k8s.io/controller-runtime/pkg/manager"
9+
10+
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/common/pkg/capi/clustertopology/handlers"
11+
dockerclusterconfig "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/pkg/handlers/docker/clusterconfig"
12+
dockermutation "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/pkg/handlers/docker/mutation"
13+
dockerworkerconfig "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/pkg/handlers/docker/workerconfig"
14+
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/pkg/handlers/options"
15+
)
16+
17+
type Handlers struct{}
18+
19+
func New(
20+
_ *options.GlobalOptions,
21+
) *Handlers {
22+
return &Handlers{}
23+
}
24+
25+
func (h *Handlers) AllHandlers(mgr manager.Manager) []handlers.Named {
26+
return []handlers.Named{
27+
dockerclusterconfig.NewVariable(),
28+
dockerworkerconfig.NewVariable(),
29+
dockermutation.MetaPatchHandler(mgr),
30+
dockermutation.MetaWorkerPatchHandler(mgr),
31+
}
32+
}
33+
34+
func (h *Handlers) AddFlags(_ *pflag.FlagSet) {}

pkg/handlers/nutanix/handlers.go

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// Copyright 2023 D2iQ, Inc. All rights reserved.
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
package nutanix
5+
6+
import (
7+
"github.com/spf13/pflag"
8+
"sigs.k8s.io/controller-runtime/pkg/manager"
9+
10+
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/common/pkg/capi/clustertopology/handlers"
11+
nutanixclusterconfig "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/pkg/handlers/nutanix/clusterconfig"
12+
nutanixmutation "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/pkg/handlers/nutanix/mutation"
13+
nutanixworkerconfig "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/pkg/handlers/nutanix/workerconfig"
14+
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/pkg/handlers/options"
15+
)
16+
17+
type Handlers struct{}
18+
19+
func New(
20+
_ *options.GlobalOptions,
21+
) *Handlers {
22+
return &Handlers{}
23+
}
24+
25+
func (h *Handlers) AllHandlers(mgr manager.Manager) []handlers.Named {
26+
return []handlers.Named{
27+
nutanixclusterconfig.NewVariable(),
28+
nutanixworkerconfig.NewVariable(),
29+
nutanixmutation.MetaPatchHandler(mgr),
30+
nutanixmutation.MetaWorkerPatchHandler(mgr),
31+
}
32+
}
33+
34+
func (h *Handlers) AddFlags(_ *pflag.FlagSet) {}

0 commit comments

Comments
 (0)