-
Notifications
You must be signed in to change notification settings - Fork 567
CNTRLPLANE-3562, CNTRLPLANE-3563: test(healthcheck): add unit tests for AWS identity provider #9142
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
mgencur
wants to merge
10
commits into
openshift:main
Choose a base branch
from
mgencur:CNTRLPLANE-3562_idp_deletion_v2
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
10 commits
Select commit
Hold shift + click to select a range
5c0fb03
test(healthcheck): add unit tests for AWS identity provider validation
mgencur 1e876d0
test(aws): add unit tests for identity provider deletion chain
mgencur b64734e
fix(aws): distinguish grace period expiry from invalid credentials in…
mgencur 91354cc
fix(aws): check S3 DeleteObjects partial failures during OIDC cleanup
mgencur ce83e6a
test(aws): fix DeleteOrphanedMachines assertions to verify objects in…
mgencur da01ec3
refactor(healthcheck): fix import formatting (gci)
mgencur e7dd61a
test(hostedcluster): add coverage for AWS endpoint service grace peri…
mgencur eecddbf
fix(hostedcluster): cache AWS credential status during endpoint cleanup
mgencur e950710
test: share HostedCluster credential condition fixture
mgencur e0021d3
test(aws): cover endpoint service cleanup branches
mgencur 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
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
154 changes: 154 additions & 0 deletions
154
hypershift-operator/controllers/hostedcluster/aws_endpoint_services_test.go
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 |
|---|---|---|
| @@ -0,0 +1,154 @@ | ||
| package hostedcluster | ||
|
|
||
| import ( | ||
| "testing" | ||
| "time" | ||
|
|
||
| . "github.com/onsi/gomega" | ||
|
|
||
| hyperv1 "github.com/openshift/hypershift/api/hypershift/v1beta1" | ||
| "github.com/openshift/hypershift/support/api" | ||
| "github.com/openshift/hypershift/support/testutil" | ||
|
|
||
| apierrors "k8s.io/apimachinery/pkg/api/errors" | ||
| metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
|
|
||
| crclient "sigs.k8s.io/controller-runtime/pkg/client" | ||
| "sigs.k8s.io/controller-runtime/pkg/client/fake" | ||
| ) | ||
|
|
||
| func TestDeleteAWSEndpointServices(t *testing.T) { | ||
| cpoFinalizer := "hypershift.openshift.io/control-plane-operator-finalizer" | ||
| namespace := "clusters-test" | ||
|
|
||
| tests := []struct { | ||
| name string | ||
| hc *hyperv1.HostedCluster | ||
| endpoints []hyperv1.AWSEndpointService | ||
| expectPending bool | ||
| expectFinalizerRemoved bool | ||
| expectDeletionTimestamp bool | ||
| }{ | ||
| { | ||
| name: "When endpoint is deleting with invalid creds, it should remove CPO finalizer", | ||
| hc: testutil.NewHostedClusterWithCredentialConditions(metav1.ConditionFalse, metav1.ConditionTrue), | ||
| endpoints: []hyperv1.AWSEndpointService{ | ||
| { | ||
| ObjectMeta: metav1.ObjectMeta{ | ||
| Name: "ep-1", | ||
| Namespace: namespace, | ||
| DeletionTimestamp: &metav1.Time{Time: time.Now().Add(-1 * time.Minute)}, | ||
| Finalizers: []string{cpoFinalizer}, | ||
| }, | ||
| }, | ||
| }, | ||
| expectPending: true, | ||
| expectFinalizerRemoved: true, | ||
| }, | ||
| { | ||
| name: "When endpoint is deleting with valid creds past grace period, it should remove CPO finalizer", | ||
| hc: testutil.NewHostedClusterWithCredentialConditions(metav1.ConditionTrue, metav1.ConditionTrue), | ||
| endpoints: []hyperv1.AWSEndpointService{ | ||
| { | ||
| ObjectMeta: metav1.ObjectMeta{ | ||
| Name: "ep-1", | ||
| Namespace: namespace, | ||
| DeletionTimestamp: &metav1.Time{Time: time.Now().Add(-15 * time.Minute)}, | ||
| Finalizers: []string{cpoFinalizer}, | ||
| }, | ||
| }, | ||
| }, | ||
| expectPending: true, | ||
| expectFinalizerRemoved: true, | ||
| }, | ||
| { | ||
| name: "When endpoint is deleting with valid creds within grace period, it should keep CPO finalizer", | ||
| hc: testutil.NewHostedClusterWithCredentialConditions(metav1.ConditionTrue, metav1.ConditionTrue), | ||
| endpoints: []hyperv1.AWSEndpointService{ | ||
| { | ||
| ObjectMeta: metav1.ObjectMeta{ | ||
| Name: "ep-1", | ||
| Namespace: namespace, | ||
| DeletionTimestamp: &metav1.Time{Time: time.Now().Add(-1 * time.Minute)}, | ||
| Finalizers: []string{cpoFinalizer}, | ||
| }, | ||
| }, | ||
| }, | ||
| expectPending: true, | ||
| expectFinalizerRemoved: false, | ||
| }, | ||
| { | ||
| name: "When no endpoints exist, it should report no pending endpoints", | ||
| hc: testutil.NewHostedClusterWithCredentialConditions(metav1.ConditionTrue, metav1.ConditionTrue), | ||
| endpoints: nil, | ||
| expectPending: false, | ||
| expectFinalizerRemoved: false, | ||
| }, | ||
| { | ||
| name: "When an endpoint is not deleting, it should delete the endpoint", | ||
| hc: testutil.NewHostedClusterWithCredentialConditions(metav1.ConditionTrue, metav1.ConditionTrue), | ||
| endpoints: []hyperv1.AWSEndpointService{ | ||
| { | ||
| ObjectMeta: metav1.ObjectMeta{ | ||
| Name: "ep-1", | ||
| Namespace: namespace, | ||
| Finalizers: []string{cpoFinalizer}, | ||
| }, | ||
| }, | ||
| }, | ||
| expectPending: true, | ||
| expectFinalizerRemoved: false, | ||
| expectDeletionTimestamp: true, | ||
| }, | ||
| } | ||
|
|
||
| for _, tc := range tests { | ||
| t.Run(tc.name, func(t *testing.T) { | ||
| g := NewGomegaWithT(t) | ||
|
|
||
| objects := []crclient.Object{} | ||
| for i := range tc.endpoints { | ||
| objects = append(objects, &tc.endpoints[i]) | ||
| } | ||
|
|
||
| fakeClient := fake.NewClientBuilder(). | ||
| WithScheme(api.Scheme). | ||
| WithObjects(objects...). | ||
| Build() | ||
|
|
||
| pending, err := deleteAWSEndpointServices(t.Context(), fakeClient, tc.hc, namespace) | ||
|
|
||
| g.Expect(err).ToNot(HaveOccurred()) | ||
|
|
||
| g.Expect(pending).To(Equal(tc.expectPending)) | ||
|
|
||
| if tc.expectFinalizerRemoved { | ||
| for _, ep := range tc.endpoints { | ||
| updatedEP := &hyperv1.AWSEndpointService{} | ||
| err := fakeClient.Get(t.Context(), crclient.ObjectKey{ | ||
| Namespace: ep.Namespace, | ||
| Name: ep.Name, | ||
| }, updatedEP) | ||
| if apierrors.IsNotFound(err) { | ||
| continue | ||
| } | ||
| g.Expect(err).ToNot(HaveOccurred()) | ||
| g.Expect(updatedEP.Finalizers).ToNot(ContainElement(cpoFinalizer)) | ||
| } | ||
| } else { | ||
| for _, ep := range tc.endpoints { | ||
| updatedEP := &hyperv1.AWSEndpointService{} | ||
| err := fakeClient.Get(t.Context(), crclient.ObjectKey{ | ||
| Namespace: ep.Namespace, | ||
| Name: ep.Name, | ||
| }, updatedEP) | ||
| g.Expect(err).ToNot(HaveOccurred()) | ||
| g.Expect(updatedEP.Finalizers).To(ContainElement(cpoFinalizer), "expected finalizer to be retained") | ||
| if tc.expectDeletionTimestamp { | ||
| g.Expect(updatedEP.DeletionTimestamp.IsZero()).To(BeFalse(), "expected endpoint to be marked for deletion") | ||
| } | ||
| } | ||
| } | ||
| }) | ||
| } | ||
| } | ||
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.