Skip to content

Commit

Permalink
fixup! refactor: provider an entrypoint to the infra provider meta ha…
Browse files Browse the repository at this point in the history
…ndlers
  • Loading branch information
dkoshkin committed Apr 22, 2024
1 parent f7ea208 commit 7efb0f7
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 25 deletions.
15 changes: 4 additions & 11 deletions pkg/handlers/nutanix/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,30 +10,23 @@ import (
"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"
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/pkg/handlers/nutanix/mutation/controlplaneendpoint"
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 {
nutanixControlPlaneEndpointConfig *controlplaneendpoint.Config
}
type Handlers struct{}

func New(
globalOptions *options.GlobalOptions,
_ *options.GlobalOptions,
) *Handlers {
return &Handlers{
nutanixControlPlaneEndpointConfig: &controlplaneendpoint.Config{
GlobalOptions: globalOptions,
},
}
return &Handlers{}
}

func (h *Handlers) AllHandlers(mgr manager.Manager) []handlers.Named {
return []handlers.Named{
nutanixclusterconfig.NewVariable(),
nutanixworkerconfig.NewVariable(),
nutanixmutation.MetaPatchHandler(mgr, h.nutanixControlPlaneEndpointConfig),
nutanixmutation.MetaPatchHandler(mgr),
nutanixmutation.MetaWorkerPatchHandler(mgr),
}
}
Expand Down
12 changes: 1 addition & 11 deletions pkg/handlers/nutanix/mutation/controlplaneendpoint/inject.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,41 +22,31 @@ import (
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/common/pkg/capi/clustertopology/patches/selectors"
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/common/pkg/capi/clustertopology/variables"
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/pkg/handlers/generic/clusterconfig"
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/pkg/handlers/options"
)

const (
// VariableName is the external patch variable name.
VariableName = "controlPlaneEndpoint"
)

type Config struct {
*options.GlobalOptions
}

type nutanixControlPlaneEndpoint struct {
config *Config

variableName string
variableFieldPath []string
}

func NewPatch(cfg *Config) *nutanixControlPlaneEndpoint {
func NewPatch() *nutanixControlPlaneEndpoint {
return newNutanixControlPlaneEndpoint(
cfg,
clusterconfig.MetaVariableName,
v1alpha1.NutanixVariableName,
VariableName,
)
}

func newNutanixControlPlaneEndpoint(
cfg *Config,
variableName string,
variableFieldPath ...string,
) *nutanixControlPlaneEndpoint {
return &nutanixControlPlaneEndpoint{
config: cfg,
variableName: variableName,
variableFieldPath: variableFieldPath,
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func TestControlPlaneEndpointPatch(t *testing.T) {

var _ = Describe("Generate Nutanix ControlPlane endpoint patches", func() {
patchGenerator := func() mutation.GeneratePatches {
return mutation.NewMetaGeneratePatchesHandler("", helpers.TestEnv.Client, NewPatch(nil)).(mutation.GeneratePatches)
return mutation.NewMetaGeneratePatchesHandler("", helpers.TestEnv.Client, NewPatch()).(mutation.GeneratePatches)
}

testDefs := []capitest.PatchTestDef{
Expand Down
4 changes: 2 additions & 2 deletions pkg/handlers/nutanix/mutation/metapatch_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ import (
)

// MetaPatchHandler returns a meta patch handler for mutating CAPX clusters.
func MetaPatchHandler(mgr manager.Manager, cfg *controlplaneendpoint.Config) handlers.Named {
func MetaPatchHandler(mgr manager.Manager) handlers.Named {
patchHandlers := append(
[]mutation.MetaMutator{
controlplaneendpoint.NewPatch(cfg),
controlplaneendpoint.NewPatch(),
prismcentralendpoint.NewPatch(),
machinedetails.NewControlPlanePatch(),
},
Expand Down

0 comments on commit 7efb0f7

Please sign in to comment.