-
Notifications
You must be signed in to change notification settings - Fork 14
HYPERFLEET-862 - feat: add Tier 2 E2E tests for deletion edge cases #94
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
kuudori
wants to merge
2
commits into
openshift-hyperfleet:main
Choose a base branch
from
kuudori:HYPERFLEET-862
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
2 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
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
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,228 @@ | ||
| package cluster | ||
|
|
||
| import ( | ||
| "context" | ||
| "net/http" | ||
| "os" | ||
|
|
||
| "github.com/onsi/ginkgo/v2" | ||
| . "github.com/onsi/gomega" //nolint:staticcheck // dot import for test readability | ||
|
|
||
| "github.com/openshift-hyperfleet/hyperfleet-e2e/pkg/api/openapi" | ||
| "github.com/openshift-hyperfleet/hyperfleet-e2e/pkg/client" | ||
| "github.com/openshift-hyperfleet/hyperfleet-e2e/pkg/helper" | ||
| "github.com/openshift-hyperfleet/hyperfleet-e2e/pkg/labels" | ||
| ) | ||
|
|
||
| var _ = ginkgo.Describe("[Suite: cluster][negative] Stuck Deletion -- Adapter Unable to Finalize Prevents Hard-Delete", | ||
| ginkgo.Serial, | ||
| ginkgo.Label(labels.Tier2, labels.Negative), | ||
| func() { | ||
| var ( | ||
| h *helper.Helper | ||
| adapterChartPath string | ||
| apiChartPath string | ||
| baseDeployOpts helper.AdapterDeploymentOptions | ||
| ) | ||
|
|
||
| ginkgo.BeforeEach(func(ctx context.Context) { | ||
| h = helper.New() | ||
|
|
||
| ginkgo.By("Clone adapter Helm chart repository") | ||
| var cleanupAdapterChart func() error | ||
| var err error | ||
| adapterChartPath, cleanupAdapterChart, err = h.CloneHelmChart(ctx, helper.HelmChartCloneOptions{ | ||
| Component: "adapter", | ||
| RepoURL: h.Cfg.AdapterDeployment.ChartRepo, | ||
| Ref: h.Cfg.AdapterDeployment.ChartRef, | ||
| ChartPath: h.Cfg.AdapterDeployment.ChartPath, | ||
| WorkDir: helper.TestWorkDir, | ||
| }) | ||
| Expect(err).NotTo(HaveOccurred(), "failed to clone adapter Helm chart") | ||
|
|
||
| ginkgo.DeferCleanup(func(ctx context.Context) { | ||
| ginkgo.By("Cleanup cloned adapter Helm chart") | ||
| if err := cleanupAdapterChart(); err != nil { | ||
| ginkgo.GinkgoWriter.Printf("Warning: failed to cleanup adapter chart: %v\n", err) | ||
| } | ||
| }) | ||
|
|
||
| ginkgo.By("Clone API Helm chart repository") | ||
| var cleanupAPIChart func() error | ||
| apiChartPath, cleanupAPIChart, err = h.CloneHelmChart(ctx, helper.HelmChartCloneOptions{ | ||
| Component: "api", | ||
| RepoURL: h.Cfg.APIDeployment.ChartRepo, | ||
| Ref: h.Cfg.APIDeployment.ChartRef, | ||
| ChartPath: h.Cfg.APIDeployment.ChartPath, | ||
| WorkDir: helper.TestWorkDir, | ||
| }) | ||
| Expect(err).NotTo(HaveOccurred(), "failed to clone API Helm chart") | ||
|
|
||
| ginkgo.DeferCleanup(func(ctx context.Context) { | ||
| ginkgo.By("Cleanup cloned API Helm chart") | ||
| if err := cleanupAPIChart(); err != nil { | ||
| ginkgo.GinkgoWriter.Printf("Warning: failed to cleanup API chart: %v\n", err) | ||
| } | ||
| }) | ||
|
|
||
| baseDeployOpts = helper.AdapterDeploymentOptions{ | ||
| Namespace: h.Cfg.Namespace, | ||
| ChartPath: adapterChartPath, | ||
| } | ||
| }) | ||
|
|
||
| ginkgo.It("should prevent hard-delete when an adapter cannot finalize", | ||
| func(ctx context.Context) { | ||
| adapterName := "cl-stuck" | ||
|
|
||
| err := os.Setenv("ADAPTER_NAME", adapterName) | ||
| Expect(err).NotTo(HaveOccurred(), "failed to set ADAPTER_NAME environment variable") | ||
| ginkgo.DeferCleanup(func() { | ||
| _ = os.Unsetenv("ADAPTER_NAME") | ||
| }) | ||
|
|
||
| releaseName := helper.GenerateAdapterReleaseName(helper.ResourceTypeClusters, adapterName) | ||
|
|
||
| ginkgo.By("Deploy dedicated stuck-adapter") | ||
| deployOpts := baseDeployOpts | ||
| deployOpts.ReleaseName = releaseName | ||
| deployOpts.AdapterName = adapterName | ||
|
|
||
| err = h.DeployAdapter(ctx, deployOpts) | ||
| ginkgo.DeferCleanup(func(ctx context.Context) { | ||
| ginkgo.By("Uninstall stuck-adapter") | ||
| if err := h.UninstallAdapter(ctx, releaseName, h.Cfg.Namespace); err != nil { | ||
| ginkgo.GinkgoWriter.Printf("Warning: failed to uninstall adapter %s: %v\n", releaseName, err) | ||
| } | ||
|
|
||
| ginkgo.By("Clean up Pub/Sub subscription") | ||
| subscriptionID := h.Cfg.Namespace + "-" + helper.ResourceTypeClusters + "-" + adapterName | ||
| if err := h.DeletePubSubSubscription(ctx, subscriptionID); err != nil { | ||
| ginkgo.GinkgoWriter.Printf("Warning: failed to delete Pub/Sub subscription %s: %v\n", subscriptionID, err) | ||
| } | ||
| }) | ||
| Expect(err).NotTo(HaveOccurred(), "failed to deploy stuck-adapter") | ||
| ginkgo.GinkgoWriter.Printf("Deployed stuck-adapter: release=%s\n", releaseName) | ||
|
|
||
| ginkgo.By("Upgrade API to add stuck-adapter to required adapters") | ||
| originalAdapters := h.GetAPIRequiredClusterAdapters() | ||
| updatedAdapters := append(append([]string{}, originalAdapters...), adapterName) | ||
|
|
||
| // Register API config restore AFTER adapter cleanup registration (LIFO → executes FIRST) | ||
| ginkgo.DeferCleanup(func(ctx context.Context) { | ||
| ginkgo.By("Restore API required adapters to original config") | ||
| if err := h.RestoreAPIRequiredAdaptersWithRetry(ctx, apiChartPath, h.Cfg.Namespace, originalAdapters, 3); err != nil { | ||
| ginkgo.GinkgoWriter.Printf("CRITICAL: %v\n", err) | ||
| } | ||
| }) | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
|
|
||
| err = h.UpgradeAPIRequiredAdapters(ctx, apiChartPath, h.Cfg.Namespace, updatedAdapters) | ||
| Expect(err).NotTo(HaveOccurred(), "failed to upgrade API with stuck-adapter in required adapters") | ||
|
|
||
| deploymentName, err := h.GetDeploymentName(ctx, h.Cfg.Namespace, releaseName) | ||
| Expect(err).NotTo(HaveOccurred(), "failed to find stuck-adapter deployment name") | ||
|
|
||
| ginkgo.By("Create cluster and wait for Reconciled with all adapters including stuck-adapter") | ||
| cluster, err := h.Client.CreateClusterFromPayload(ctx, h.TestDataPath("payloads/clusters/cluster-request.json")) | ||
| Expect(err).NotTo(HaveOccurred(), "failed to create cluster") | ||
| Expect(cluster.Id).NotTo(BeNil(), "cluster ID should be generated") | ||
| clusterID := *cluster.Id | ||
| ginkgo.GinkgoWriter.Printf("Created cluster ID: %s, Name: %s\n", clusterID, cluster.Name) | ||
|
|
||
| ginkgo.DeferCleanup(func(ctx context.Context) { | ||
| ginkgo.By("Cleanup test cluster " + clusterID) | ||
| if err := h.CleanupTestCluster(ctx, clusterID); err != nil { | ||
| ginkgo.GinkgoWriter.Printf("Warning: failed to cleanup cluster %s: %v\n", clusterID, err) | ||
| } | ||
| }) | ||
|
|
||
| Eventually(h.PollCluster(ctx, clusterID), h.Cfg.Timeouts.Cluster.Reconciled, h.Cfg.Polling.Interval). | ||
| Should(helper.HaveResourceCondition(client.ConditionTypeReconciled, openapi.ResourceConditionStatusTrue)) | ||
|
|
||
| ginkgo.By("Verify stuck-adapter reported Applied=True") | ||
| Eventually(func(g Gomega) { | ||
| statuses, err := h.Client.GetClusterStatuses(ctx, clusterID) | ||
| g.Expect(err).NotTo(HaveOccurred(), "failed to get cluster statuses") | ||
|
|
||
| var found bool | ||
| for _, s := range statuses.Items { | ||
| if s.Adapter == adapterName { | ||
| found = true | ||
| g.Expect(h.HasAdapterCondition(s.Conditions, | ||
| client.ConditionTypeApplied, openapi.AdapterConditionStatusTrue)).To(BeTrue(), | ||
| "stuck-adapter should have Applied=True before scale-down") | ||
| break | ||
| } | ||
| } | ||
| g.Expect(found).To(BeTrue(), "stuck-adapter should be present in statuses") | ||
| }, h.Cfg.Timeouts.Adapter.Processing, h.Cfg.Polling.Interval).Should(Succeed()) | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
|
|
||
| ginkgo.By("Scale down stuck-adapter to simulate unavailability") | ||
| err = h.ScaleDeployment(ctx, h.Cfg.Namespace, deploymentName, 0) | ||
| Expect(err).NotTo(HaveOccurred(), "failed to scale down stuck-adapter") | ||
|
|
||
| ginkgo.By("Soft-delete the cluster") | ||
| deletedCluster, err := h.Client.DeleteCluster(ctx, clusterID) | ||
| Expect(err).NotTo(HaveOccurred(), "DELETE request should succeed with 202") | ||
| Expect(deletedCluster.DeletedTime).NotTo(BeNil(), "soft-deleted cluster should have deleted_time set") | ||
|
|
||
| ginkgo.By("Wait for healthy adapters to report Finalized=True") | ||
| Eventually(func(g Gomega) { | ||
| statuses, err := h.Client.GetClusterStatuses(ctx, clusterID) | ||
| g.Expect(err).NotTo(HaveOccurred(), "failed to get cluster statuses") | ||
|
|
||
| adapterMap := make(map[string]openapi.AdapterStatus, len(statuses.Items)) | ||
| for _, s := range statuses.Items { | ||
| adapterMap[s.Adapter] = s | ||
| } | ||
|
|
||
| for _, name := range originalAdapters { | ||
| adapter, exists := adapterMap[name] | ||
| g.Expect(exists).To(BeTrue(), "adapter %s should be present", name) | ||
| g.Expect(h.HasAdapterCondition(adapter.Conditions, | ||
| client.ConditionTypeFinalized, openapi.AdapterConditionStatusTrue)).To(BeTrue(), | ||
| "adapter %s should have Finalized=True", name) | ||
| } | ||
| }, h.Cfg.Timeouts.Adapter.Processing, h.Cfg.Polling.Interval).Should(Succeed()) | ||
|
|
||
| ginkgo.By("Verify cluster remains stuck in soft-deleted state (not hard-deleted)") | ||
| Consistently(func(g Gomega) { | ||
| cl, err := h.Client.GetCluster(ctx, clusterID) | ||
| g.Expect(err).NotTo(HaveOccurred(), "cluster should still be accessible (not hard-deleted)") | ||
| g.Expect(cl.DeletedTime).NotTo(BeNil(), "cluster should still be soft-deleted") | ||
|
|
||
| g.Expect(h.HasResourceCondition(cl.Status.Conditions, | ||
| client.ConditionTypeReconciled, openapi.ResourceConditionStatusFalse)).To(BeTrue(), | ||
| "cluster Reconciled should remain False while stuck-adapter is unavailable") | ||
|
|
||
| statuses, err := h.Client.GetClusterStatuses(ctx, clusterID) | ||
| g.Expect(err).NotTo(HaveOccurred(), "failed to get cluster statuses") | ||
|
|
||
| for _, s := range statuses.Items { | ||
| if s.Adapter == adapterName { | ||
| g.Expect(h.HasAdapterCondition(s.Conditions, | ||
| client.ConditionTypeFinalized, openapi.AdapterConditionStatusTrue)).To(BeFalse(), | ||
| "stuck-adapter should NOT have Finalized=True while scaled to 0") | ||
| break | ||
| } | ||
| } | ||
| }, h.Cfg.Timeouts.Adapter.Processing/2, h.Cfg.Polling.Interval).Should(Succeed()) | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
|
|
||
| ginkgo.GinkgoWriter.Printf("Verified: cluster stuck in soft-deleted state, healthy adapters finalized but stuck-adapter has not\n") | ||
|
|
||
| ginkgo.By("Restore stuck-adapter by scaling up") | ||
| err = h.ScaleDeployment(ctx, h.Cfg.Namespace, deploymentName, 1) | ||
| Expect(err).NotTo(HaveOccurred(), "failed to scale up stuck-adapter") | ||
|
|
||
| ginkgo.By("Verify cluster is hard-deleted after stuck-adapter recovery") | ||
| Eventually(h.PollClusterHTTPStatus(ctx, clusterID), h.Cfg.Timeouts.Cluster.Reconciled, h.Cfg.Polling.Interval). | ||
| Should(Equal(http.StatusNotFound)) | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
|
|
||
| ginkgo.By("Verify downstream K8s namespace is cleaned up") | ||
| Eventually(h.PollNamespacesByPrefix(ctx, clusterID), h.Cfg.Timeouts.Adapter.Processing, h.Cfg.Polling.Interval). | ||
| Should(BeEmpty()) | ||
|
|
||
| ginkgo.GinkgoWriter.Printf("Verified: stuck-adapter recovered, cluster hard-deleted\n") | ||
| }) | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
| }, | ||
| ) | ||
This file was deleted.
Oops, something went wrong.
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,5 @@ | ||
| //go:build tools | ||
|
|
||
| package hack | ||
|
|
||
| import _ "github.com/openshift-hyperfleet/hyperfleet-api-spec/schemas" |
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.
Uh oh!
There was an error while loading. Please reload this page.