Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ unit: .localtestenv ## Run unit tests

.PHONY: e2e
e2e: ## Run e2e tests against active kubeconfig
./hack/test.sh "./e2e/..." 120m
./hack/test.sh "./e2e/..." 180m
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for CI we may want to increase this bit more ? May be we can conclude after all pre-submits are passed like 20% more time than they took ?


run: ## Run the operator against the configured Kubernetes cluster
oc -n openshift-cluster-api patch lease cluster-capi-operator-leader -p '{"spec":{"acquireTime": null, "holderIdentity": null, "renewTime": null}}' --type=merge
Expand Down
244 changes: 119 additions & 125 deletions e2e/machine_migration_capi_authoritative_test.go

Large diffs are not rendered by default.

29 changes: 29 additions & 0 deletions e2e/machine_migration_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@ import (
clusterv1 "sigs.k8s.io/cluster-api/api/core/v1beta2"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/envtest/komega"
yaml "sigs.k8s.io/yaml"
)

func createCAPIMachine(ctx context.Context, cl client.Client, machineName string) *clusterv1.Machine {
GinkgoHelper()
Expect(machineName).NotTo(BeEmpty(), "Machine name cannot be empty")

workerLabelSelector := metav1.LabelSelector{
Expand Down Expand Up @@ -96,6 +98,7 @@ func createCAPIMachine(ctx context.Context, cl client.Client, machineName string
}

func createMAPIMachineWithAuthority(ctx context.Context, cl client.Client, machineName string, authority mapiv1beta1.MachineAuthority) *mapiv1beta1.Machine {
GinkgoHelper()
Expect(machineName).NotTo(BeEmpty(), "Machine name cannot be empty")
workerLabelSelector := metav1.LabelSelector{
MatchLabels: map[string]string{
Expand Down Expand Up @@ -140,6 +143,7 @@ func createMAPIMachineWithAuthority(ctx context.Context, cl client.Client, machi

// verifyMachineRunning verifies that a machine reaches Running state using the machine object directly.
func verifyMachineRunning(cl client.Client, machine client.Object) {
GinkgoHelper()
Expect(machine).NotTo(BeNil(), "Machine parameter cannot be nil")
Expect(machine.GetName()).NotTo(BeEmpty(), "Machine name cannot be empty")
Eventually(func(g Gomega) string {
Expand All @@ -162,6 +166,7 @@ func verifyMachineRunning(cl client.Client, machine client.Object) {
}

func verifyMachineAuthoritative(mapiMachine *mapiv1beta1.Machine, authority mapiv1beta1.MachineAuthority) {
GinkgoHelper()
By(fmt.Sprintf("Verify the Machine authority is %s", authority))
Eventually(komega.Object(mapiMachine), capiframework.WaitMedium, capiframework.RetryMedium).Should(
HaveField("Status.AuthoritativeAPI", Equal(authority)),
Expand All @@ -170,6 +175,7 @@ func verifyMachineAuthoritative(mapiMachine *mapiv1beta1.Machine, authority mapi
}

func verifyMAPIMachineSynchronizedCondition(mapiMachine *mapiv1beta1.Machine, authority mapiv1beta1.MachineAuthority) {
GinkgoHelper()
By("Verify the MAPI Machine synchronized condition is True")
var expectedMessage string
switch authority {
Expand Down Expand Up @@ -202,6 +208,7 @@ func verifyMAPIMachineSynchronizedCondition(mapiMachine *mapiv1beta1.Machine, au
// verifyResourceRemoved verifies that a resource has been removed.
// This is a generic function that works with any client.Object type.
func verifyResourceRemoved(resource client.Object) {
GinkgoHelper()
Expect(resource).NotTo(BeNil(), "Resource parameter cannot be nil")
Expect(resource.GetName()).NotTo(BeEmpty(), "Resource name cannot be empty")
gvk := resource.GetObjectKind().GroupVersionKind()
Expand All @@ -214,6 +221,7 @@ func verifyResourceRemoved(resource client.Object) {
// verifyMachinePausedCondition verifies the Paused condition for either MAPI or CAPI machines.
// This unified function determines the machine type and expected pause state based on the authority.
func verifyMachinePausedCondition(machine client.Object, authority mapiv1beta1.MachineAuthority) {
GinkgoHelper()
Expect(machine).NotTo(BeNil(), "Machine parameter cannot be nil")
Expect(machine.GetName()).NotTo(BeEmpty(), "Machine name cannot be empty")
var conditionMatcher types.GomegaMatcher
Expand Down Expand Up @@ -298,12 +306,14 @@ func cleanupMachineResources(ctx context.Context, cl client.Client, capiMachines
}

func updateMachineAuthoritativeAPI(mapiMachine *mapiv1beta1.Machine, newAuthority mapiv1beta1.MachineAuthority) {
GinkgoHelper()
Eventually(komega.Update(mapiMachine, func() {
mapiMachine.Spec.AuthoritativeAPI = newAuthority
}), capiframework.WaitShort, capiframework.RetryShort).Should(Succeed(), "Failed to update MAPI Machine AuthoritativeAPI to %s", newAuthority)
}

func verifyMachineSynchronizedGeneration(cl client.Client, mapiMachine *mapiv1beta1.Machine, authority mapiv1beta1.MachineAuthority) {
GinkgoHelper()
Eventually(komega.Object(mapiMachine), capiframework.WaitMedium, capiframework.RetryMedium).Should(
HaveField("Status.SynchronizedGeneration", Not(BeZero())),
"MAPI Machine SynchronizedGeneration should not be zero",
Expand Down Expand Up @@ -333,3 +343,22 @@ func verifyMachineSynchronizedGeneration(cl client.Client, mapiMachine *mapiv1be
fmt.Sprintf("MAPI Machine SynchronizedGeneration should equal %s Machine Generation (%d)", authoritativeMachineType, expectedGeneration),
)
}

// verifyMAPIMachineProviderStatus verifies that a MAPI Machine's providerStatus matches the given Gomega matcher.
func verifyMAPIMachineProviderStatus(mapiMachine *mapiv1beta1.Machine, matcher types.GomegaMatcher) {
GinkgoHelper()
By(fmt.Sprintf("Verifying MAPI Machine %s providerStatus matches AWSMachine status", mapiMachine.Name))
Eventually(komega.Object(mapiMachine), capiframework.WaitMedium, capiframework.RetryMedium).Should(
WithTransform(getAWSProviderStatusFromMachine, matcher),
)
}

// getAWSProviderStatusFromMachine extracts and unmarshals the AWSMachineProviderStatus from a MAPI Machine.
func getAWSProviderStatusFromMachine(mapiMachine *mapiv1beta1.Machine) *mapiv1beta1.AWSMachineProviderStatus {
Expect(mapiMachine.Status.ProviderStatus.Raw).ToNot(BeNil())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could call GinkgoHelper() here as well or any specific reason not using it here ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@miyadav this is a stack PR on top of #387
Which originally introduces the Ginkgo helper part, probably worth commenting there

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah got it , Nolan already did , thanks Dam


providerStatus := &mapiv1beta1.AWSMachineProviderStatus{}
Expect(yaml.Unmarshal(mapiMachine.Status.ProviderStatus.Raw, providerStatus)).To(Succeed())

return providerStatus
}
Loading