Skip to content

Conversation

@josvazg
Copy link
Collaborator

@josvazg josvazg commented Dec 16, 2025

Summary

Add a e2e2 test for Flex Clusters.

Proof of Work

Tested locally.

$ time make e2e2 label=flexcluster-ctlr EXPERIMENTAL=1
...
Ran 2 of 18 Specs in 224.121 seconds
SUCCESS! -- 2 Passed | 0 Failed | 0 Pending | 16 Skipped
PASS
Ginkgo ran 1 suite in 3m59.683338625s
Test Suite Passed
make e2e2 label=flexcluster-ctlr EXPERIMENTAL=1  39.52s user 34.56s system 25% cpu 4:46.86 total

Checklist

  • Have you linked a jira ticket and/or is the ticket in the title?
  • Have you checked whether your jira ticket required DOCSP changes?
  • Have you signed our CLA?

@josvazg josvazg requested a review from a team as a code owner December 16, 2025 18:05
@josvazg josvazg marked this pull request as draft December 16, 2025 18:05
@josvazg
Copy link
Collaborator Author

josvazg commented Dec 16, 2025

test is not passing yet, needs debugging

@josvazg josvazg force-pushed the CLOUDP-358677/add-flex-e2e2-test branch 2 times, most recently from a5365e1 to 5ccbafc Compare December 17, 2025 15:12
@josvazg josvazg marked this pull request as ready for review December 17, 2025 15:12
@josvazg josvazg force-pushed the CLOUDP-358677/add-flex-e2e2-test branch 2 times, most recently from 3521cd0 to 3f91d2a Compare December 18, 2025 13:22
@josvazg josvazg marked this pull request as draft December 19, 2025 16:08
@josvazg josvazg requested a review from s-urbaniak December 19, 2025 16:08
@josvazg
Copy link
Collaborator Author

josvazg commented Dec 19, 2025

Something is still wrong with this, I will debug further

@josvazg josvazg force-pushed the CLOUDP-358677/add-flex-e2e2-test branch from a61fab2 to 8d103f4 Compare December 20, 2025 08:40
@josvazg josvazg marked this pull request as ready for review December 22, 2025 10:12
@josvazg josvazg force-pushed the CLOUDP-358677/add-flex-e2e2-test branch from 8d103f4 to 40d30d0 Compare December 22, 2025 10:13
Signed-off-by: jose.vazquez <jose.vazquez@mongodb.com>
Signed-off-by: jose.vazquez <jose.vazquez@mongodb.com>
Signed-off-by: jose.vazquez <jose.vazquez@mongodb.com>
@josvazg josvazg force-pushed the CLOUDP-358677/add-flex-e2e2-test branch from 40d30d0 to 559a636 Compare December 22, 2025 10:15
Signed-off-by: jose.vazquez <jose.vazquez@mongodb.com>
// If Group is not found but we have group ID in status, use it to proceed with deletion.
var statusErr *apierrors.StatusError
if errors.As(err, &statusErr) && apierrors.IsNotFound(statusErr) {
if group := h.getMinimalGroupFromStatusOrSpec(flexcluster); group != nil {
Copy link
Collaborator

@s-urbaniak s-urbaniak Dec 22, 2025

Choose a reason for hiding this comment

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

This is doable in this case but not all objects have Group IDs (i.e. DatabaseUsers). I rather suggest blocking deletion of the Group in the group reconciler in the first place:

func (h *Handlerv20250312) HandleDeletionRequested(ctx context.Context, group *akov2generated.Group) (ctrlstate.Result, error) {
	var dependents []reconcile.Request
	dependents = append(dependents, indexers.NewFlexClusterByGroupMapFunc(h.kubeClient)(ctx, group)...)
	dependents = append(dependents, indexers.NewDatabaseUserByGroupMapFunc(h.kubeClient)(ctx, group)...)
	dependents = append(dependents, indexers.NewClusterByGroupMapFunc(h.kubeClient)(ctx, group)...)
	if len(dependends) > 0 {
		return result.NextState(state.StateDeletionRequested, fmt.Sprintf("failed to delete group because %v resources depend on it.", len(dependents)))
	}

	if customresource.IsResourcePolicyKeepOrDefault(group, h.deletionProtection) {
		return result.NextState(state.StateDeleted, "Group deleted.")
	}

Copy link
Collaborator

Choose a reason for hiding this comment

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

The good news is that we have the mapping functions auto-generated already!

Copy link
Collaborator

Choose a reason for hiding this comment

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

I just tried the above code and it works nicely. I first:

  1. Tried to delete the group. This blocks because a Cluster, a FlexCluster, and a DatabaseUser depend on it:
Screenshot 2025-12-22 at 20 51 37
  1. Deleted the Cluster, a FlexCluster, and a DatabaseUser. In the meantime the count of dependend resources went down:
Screenshot 2025-12-22 at 20 53 14
  1. Finally the deletion in Atlas was initiated and executed:
Screenshot 2025-12-22 at 20 53 33

Copy link
Collaborator

Choose a reason for hiding this comment

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

side note: this is a pretty canonical use of indexes in the combination with finalizers (in our case nicely gated via the universal state machine)

Copy link
Collaborator

@s-urbaniak s-urbaniak left a comment

Choose a reason for hiding this comment

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

I rather suggest blocking the group vs. having smartness in the reconciler as not all resources have a groupId in their status, i.e. DatabaseUsers

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants