@@ -19,6 +19,7 @@ import (
1919 clusterv1 "sigs.k8s.io/cluster-api/api/core/v1beta2"
2020 "sigs.k8s.io/controller-runtime/pkg/client"
2121 "sigs.k8s.io/controller-runtime/pkg/envtest/komega"
22+ yaml "sigs.k8s.io/yaml"
2223)
2324
2425func createCAPIMachine (ctx context.Context , cl client.Client , machineName string ) * clusterv1.Machine {
@@ -333,3 +334,21 @@ func verifyMachineSynchronizedGeneration(cl client.Client, mapiMachine *mapiv1be
333334 fmt .Sprintf ("MAPI Machine SynchronizedGeneration should equal %s Machine Generation (%d)" , authoritativeMachineType , expectedGeneration ),
334335 )
335336}
337+
338+ // verifyMAPIMachineProviderStatus verifies that a MAPI Machine's providerStatus matches the given Gomega matcher.
339+ func verifyMAPIMachineProviderStatus (mapiMachine * mapiv1beta1.Machine , matcher types.GomegaMatcher ) {
340+ By (fmt .Sprintf ("Verifying MAPI MachineSet %s providerStatus matches AWSMachine status" , mapiMachine .Name ))
341+ Eventually (komega .Object (mapiMachine ), capiframework .WaitMedium , capiframework .RetryMedium ).Should (
342+ WithTransform (getAWSProviderStatusFromMachine , matcher ),
343+ )
344+ }
345+
346+ // getAWSProviderStatusFromMachine extracts and unmarshals the AWSMachineProviderStatus from a MAPI Machine.
347+ func getAWSProviderStatusFromMachine (mapiMachine * mapiv1beta1.Machine ) * mapiv1beta1.AWSMachineProviderStatus {
348+ Expect (mapiMachine .Status .ProviderStatus .Raw ).ToNot (BeNil ())
349+
350+ providerStatus := & mapiv1beta1.AWSMachineProviderStatus {}
351+ Expect (yaml .Unmarshal (mapiMachine .Status .ProviderStatus .Raw , providerStatus )).To (Succeed ())
352+
353+ return providerStatus
354+ }
0 commit comments