Skip to content

Commit

Permalink
Updates tests for MachineSetSync controller
Browse files Browse the repository at this point in the history
  • Loading branch information
theobarberbany committed Nov 6, 2024
1 parent 9e99b90 commit 6e83d24
Show file tree
Hide file tree
Showing 2 changed files with 279 additions and 45 deletions.
15 changes: 13 additions & 2 deletions pkg/controllers/machinesetsync/machineset_sync_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,16 @@ var (

// errUnexpectedInfraClusterType is returned when we receive an unexpected InfraCluster type.
errUnexpectedInfraClusterType = errors.New("unexpected InfraCluster type")

// errCAPIMachineSetNotFound is returned when we have only a MAPI MachineSet with AuthorititaveAPI set to CAPI.
errCAPIMachineSetNotFound = errors.New("error synchronizing CAPI to MAPI, CAPI machineset not found")
)

const (
reasonFailedToGetCAPIInfraResources = "FailedToGetCAPIInfraResources"
reasonFailedToConvertCAPIMachineSetToMAPI = "FailedToConvertCAPIMachineSetToMAPI"
reasonFailedToUpdateMAPIMachineSet = "FailedToUpdateMAPIMachineSet"
reasonFailedToGetCAPIMachineSet = "FailedToGetCAPIMachineSet"
reasonResourceSynchronized = "ResourceSynchronized"

messageSuccessfullySynchronized = "Successfully synchronized CAPI MachineSet to MAPI"
Expand Down Expand Up @@ -121,7 +125,7 @@ func (r *MachineSetSyncReconciler) SetupWithManager(mgr ctrl.Manager) error {

// Reconcile reconciles CAPI and MAPI MachineSets for their respective namespaces.
func (r *MachineSetSyncReconciler) Reconcile(ctx context.Context, req reconcile.Request) (ctrl.Result, error) {
logger := log.FromContext(ctx).WithValues("namespace", req.Namespace, "name", req.Name)
logger := log.FromContext(ctx)
ctx = logr.NewContext(ctx, logger)

logger.V(1).Info("Reconciling machine set")
Expand Down Expand Up @@ -214,9 +218,16 @@ func (r *MachineSetSyncReconciler) syncMachineSets(ctx context.Context, mapiMach
case machinev1beta1.MachineAuthorityMachineAPI:
return r.reconcileMAPIMachineSetToCAPIMachineSet(ctx, mapiMachineSet, capiMachineSet)
case machinev1beta1.MachineAuthorityClusterAPI:
if capiMachineSet == nil {
condErr := r.updateSynchronizedConditionWithPatch(
ctx, mapiMachineSet, corev1.ConditionFalse, reasonFailedToGetCAPIMachineSet, errCAPIMachineSetNotFound.Error(), nil)

return ctrl.Result{}, condErr
}

return r.reconcileCAPIMachineSetToMAPIMachineSet(ctx, capiMachineSet, mapiMachineSet)
case machinev1beta1.MachineAuthorityMigrating:
logger.Info("machine set is currently being migrated", "machine set", mapiMachineSet.GetName())
logger.Info("machine set is currently being migrated")
return ctrl.Result{}, nil
default:
logger.Info("unexpected value for authoritativeAPI", "AuthoritativeAPI", mapiMachineSet.Status.AuthoritativeAPI)
Expand Down
Loading

0 comments on commit 6e83d24

Please sign in to comment.