Skip to content

Commit

Permalink
Merge pull request #230 from theobarberbany/ms-capi2mapi-test
Browse files Browse the repository at this point in the history
OCPCLOUD-2646: MachineSetSync controller: tests
  • Loading branch information
openshift-merge-bot[bot] authored Nov 9, 2024
2 parents 3953a2a + 393a17c commit ec9120b
Show file tree
Hide file tree
Showing 5 changed files with 304 additions and 50 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ require (
github.com/onsi/gomega v1.35.1
github.com/openshift/api v0.0.0-20241009131553-a1523024209f
github.com/openshift/client-go v0.0.0-20241001162912-da6d55e4611f
github.com/openshift/cluster-api-actuator-pkg/testutils v0.0.0-20241024095219-086923b9d3fd
github.com/openshift/cluster-api-actuator-pkg/testutils v0.0.0-20241029130438-302aefe5af06
github.com/openshift/cluster-control-plane-machine-set-operator v0.0.0-20241008085214-8d85b2cb2c1d
github.com/openshift/library-go v0.0.0-20240919205913-c96b82b3762b
github.com/pkg/errors v0.9.1
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -423,8 +423,8 @@ github.com/openshift/api v0.0.0-20241009131553-a1523024209f h1:nxQl2ZH5Lr7KzM1zH
github.com/openshift/api v0.0.0-20241009131553-a1523024209f/go.mod h1:Shkl4HanLwDiiBzakv+con/aMGnVE2MAGvoKp5oyYUo=
github.com/openshift/client-go v0.0.0-20241001162912-da6d55e4611f h1:FRc0bVNWprihWS0GqQWzb3dY4dkCwpOP3mDw5NwSoR4=
github.com/openshift/client-go v0.0.0-20241001162912-da6d55e4611f/go.mod h1:KiZi2mJRH1TOJ3FtBDYS6YvUL30s/iIXaGSUrSa36mo=
github.com/openshift/cluster-api-actuator-pkg/testutils v0.0.0-20241024095219-086923b9d3fd h1:uJuMyhb2hTo2zy9zZAuqarSi+zcMPaFl9xmmeuaN0g8=
github.com/openshift/cluster-api-actuator-pkg/testutils v0.0.0-20241024095219-086923b9d3fd/go.mod h1:Ns6d57JhMddy6w5c61HHWQ4jqF8Pvrv8mgs2gxg5jKU=
github.com/openshift/cluster-api-actuator-pkg/testutils v0.0.0-20241029130438-302aefe5af06 h1:fOW9q/XdyeDivivOhvTWHeJXIPXpx4wvQrHhNv4iXlo=
github.com/openshift/cluster-api-actuator-pkg/testutils v0.0.0-20241029130438-302aefe5af06/go.mod h1:Ns6d57JhMddy6w5c61HHWQ4jqF8Pvrv8mgs2gxg5jKU=
github.com/openshift/cluster-control-plane-machine-set-operator v0.0.0-20241008085214-8d85b2cb2c1d h1:X4NkXsGOvS5pRBYaaLfLoUVMYbXl00I07dJFnNdxbq0=
github.com/openshift/cluster-control-plane-machine-set-operator v0.0.0-20241008085214-8d85b2cb2c1d/go.mod h1:u+45mmWUg2ld7nsPDXzntjMsxannCV0CVmcUj9tIDvU=
github.com/openshift/library-go v0.0.0-20240919205913-c96b82b3762b h1:y2DduJug7UZqTu0QTkRPAu73nskuUbFA66fmgxVf/fI=
Expand Down
24 changes: 19 additions & 5 deletions pkg/controllers/machinesetsync/machineset_sync_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ const (
reasonFailedToGetCAPIInfraResources = "FailedToGetCAPIInfraResources"
reasonFailedToConvertCAPIMachineSetToMAPI = "FailedToConvertCAPIMachineSetToMAPI"
reasonFailedToUpdateMAPIMachineSet = "FailedToUpdateMAPIMachineSet"
reasonFailedToGetCAPIMachineSet = "FailedToGetCAPIMachineSet"
reasonResourceSynchronized = "ResourceSynchronized"

messageSuccessfullySynchronized = "Successfully synchronized CAPI MachineSet to MAPI"
Expand Down Expand Up @@ -210,18 +211,31 @@ func (r *MachineSetSyncReconciler) fetchCAPIInfraResources(ctx context.Context,
func (r *MachineSetSyncReconciler) syncMachineSets(ctx context.Context, mapiMachineSet *machinev1beta1.MachineSet, capiMachineSet *capiv1beta1.MachineSet) (ctrl.Result, error) {
logger := log.FromContext(ctx)

switch mapiMachineSet.Status.AuthoritativeAPI {
case machinev1beta1.MachineAuthorityMachineAPI:
authoritativeAPI := mapiMachineSet.Status.AuthoritativeAPI

switch {
case authoritativeAPI == machinev1beta1.MachineAuthorityMachineAPI:
return r.reconcileMAPIMachineSetToCAPIMachineSet(ctx, mapiMachineSet, capiMachineSet)
case machinev1beta1.MachineAuthorityClusterAPI:
case authoritativeAPI == machinev1beta1.MachineAuthorityClusterAPI && capiMachineSet == nil:
// We want to create a new CAPI MachineSet from the MAPI one.
// I think we may want to call a lot of the same logic we'll need for reconciling MAPI -> CAPI,
// as such I think we should hold off on implementing this until that logic is worked out
// (and hopefully it's just calling some of the same helper funcs)
// TODO: Implementation
case authoritativeAPI == machinev1beta1.MachineAuthorityClusterAPI && capiMachineSet != nil:
return r.reconcileCAPIMachineSetToMAPIMachineSet(ctx, capiMachineSet, mapiMachineSet)
case machinev1beta1.MachineAuthorityMigrating:
logger.Info("machine set is currently being migrated", "machine set", mapiMachineSet.GetName())

case authoritativeAPI == machinev1beta1.MachineAuthorityMigrating:
logger.Info("machine set is currently being migrated")
return ctrl.Result{}, nil

default:
logger.Info("unexpected value for authoritativeAPI", "AuthoritativeAPI", mapiMachineSet.Status.AuthoritativeAPI)

return ctrl.Result{}, nil
}

return ctrl.Result{}, nil
}

// reconcileMAPIMachineSetToCAPIMachineSet reconciles a MAPI MachineSet to a CAPI MachineSet.
Expand Down
Loading

0 comments on commit ec9120b

Please sign in to comment.