-
Notifications
You must be signed in to change notification settings - Fork 54
OCPCLOUD-3355: e2e testing automation: Implement Status Syncing for MAPI/CAPI migration #387
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
sunzhaohua2
wants to merge
4
commits into
openshift:main
Choose a base branch
from
sunzhaohua2:status
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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{ | ||
|
|
@@ -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{ | ||
|
|
@@ -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 { | ||
|
|
@@ -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)), | ||
|
|
@@ -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 { | ||
|
|
@@ -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() | ||
|
|
@@ -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 | ||
|
|
@@ -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", | ||
|
|
@@ -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), | ||
| ) | ||
| } | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
|
|
||
| // getAWSProviderStatusFromMachine extracts and unmarshals the AWSMachineProviderStatus from a MAPI Machine. | ||
| func getAWSProviderStatusFromMachine(mapiMachine *mapiv1beta1.Machine) *mapiv1beta1.AWSMachineProviderStatus { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same comment for |
||
| Expect(mapiMachine.Status.ProviderStatus.Raw).ToNot(BeNil()) | ||
|
|
||
| providerStatus := &mapiv1beta1.AWSMachineProviderStatus{} | ||
| Expect(yaml.Unmarshal(mapiMachine.Status.ProviderStatus.Raw, providerStatus)).To(Succeed()) | ||
|
|
||
| return providerStatus | ||
| } | ||
|
sunzhaohua2 marked this conversation as resolved.
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I haven't looked at the rest of the file, but we should probably start these functions with
GinkgoHelper()See https://onsi.github.io/ginkgo/#mental-model-how-ginkgo-handles-failure, which explains how Ginkgo uses helpers when handling failed assertions.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you @nrb for helping review, I have added.