Skip to content

CLOUDP-316083: Third Party Integrations Controller #2313

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

Draft
wants to merge 12 commits into
base: main
Choose a base branch
from

Conversation

josvazg
Copy link
Collaborator

@josvazg josvazg commented Apr 30, 2025

Summary

Internal-only implementation for the integrations controller

Proof of Work

TBD including new tests

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 checked for release_note changes?
  • Have you signed our CLA?

Reminder (Please remove this when merging)

  • Please try to Approve or Reject Changes the PR, keep PRs in review as short as possible
  • Remember the following Communication Standards - use comment prefixes for clarity:
    • blocking: Must be addressed before approval.
    • follow-up: Can be addressed in a later PR or ticket.
    • q: Clarifying question.
    • nit: Non-blocking suggestions.
    • note: Side-note, non-actionable. Example: Praise
    • --> no prefix is considered a question

@josvazg josvazg requested a review from a team as a code owner April 30, 2025 08:27
@josvazg josvazg marked this pull request as draft April 30, 2025 08:27
@josvazg josvazg changed the title CLOUDP-316083: Integration Controller CLOUDP-316083: Third Party Integrations Controller Apr 30, 2025
@josvazg josvazg force-pushed the CLOUDP-316083/integrations-ctlr branch 14 times, most recently from 105c5be to d35b1f4 Compare May 24, 2025 08:46
@josvazg josvazg force-pushed the CLOUDP-316083/integrations-ctlr branch 4 times, most recently from 67fd52f to 0fa07a0 Compare May 27, 2025 11:32
@josvazg josvazg force-pushed the CLOUDP-316083/integrations-ctlr branch 2 times, most recently from 8375d68 to fc928bf Compare May 29, 2025 08:38
@josvazg josvazg force-pushed the CLOUDP-316083/integrations-ctlr branch from fc928bf to 38ac42f Compare May 29, 2025 10:03
@josvazg josvazg force-pushed the CLOUDP-316083/integrations-ctlr branch from 38ac42f to b653cd5 Compare May 29, 2025 12:23
Watches(
&akov2.AtlasProject{},
handler.EnqueueRequestsFromMapFunc(h.integrationForProjectMapFunc()),
builder.WithPredicates(integrationPredicates),
Copy link
Collaborator

Choose a reason for hiding this comment

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

we want to watch for generation changes only here.

Watches(
&akov2.AtlasProject{},
handler.EnqueueRequestsFromMapFunc(h.integrationForProjectMapFunc()),
builder.WithPredicates(integrationPredicates),
Copy link
Collaborator

@s-urbaniak s-urbaniak May 30, 2025

Choose a reason for hiding this comment

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

the global variable integrationPredicates obfuscates what predicates we're having so reading through it makes it hard to reason about what predicates are actually applied. I suggest using predicate.GenerationChangedPredicate{} and predicate.ResourceVersionChangedPredicate{} to make it explicit and readable to the reader.

In addition you risk faulty behaviour in case controller-runtime decides to have internal state inside the predicate struct. I'd be careful reusing it.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Should I use a function instead?
the reason to introduce a variable is we are setting the same predicates in several places. We set one predicate in 3 or 4 places and a different one on another. To avoid mistakes, all same occurrences should be the same reference in code. If a variable is not good, a function returning a fresh instance every time might work instead.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I will just drop the var and funcs in the end.

&corev1.Secret{},
handler.EnqueueRequestsFromMapFunc(h.integrationForSecretMapFunc()),
builder.WithPredicates(integrationPredicates),
).
Copy link
Collaborator

@s-urbaniak s-urbaniak May 30, 2025

Choose a reason for hiding this comment

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

really just a nit: rather than watching twice for Secret, we can just make one combined enqueue function, gathering both from the AtlasThirdPartyIntegrationCredentialsIndex and AtlasThirdPartyIntegrationBySecretsIndex index.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Those secrets are semantically different. One if for operator credentials, and the other are for integration credentials. The indexers are totally different, even if they map secret<-> integration.

I will try to combine, but it might not be that easy.

return h.update(ctx, currentState, req, integrationSpec)
}
return result.NextState(
state.StateCreated,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
state.StateCreated,
state.StateUpdated,

Copy link
Collaborator

Choose a reason for hiding this comment

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

alternative: pass a nextState var as well, callers would be then:

func (h *AtlasThirdPartyIntegrationHandler) HandleInitial(ctx context.Context, integration *akov2next.AtlasThirdPartyIntegration) (ctrlstate.Result, error) {
	return h.upsert(ctx, state.StateInitial, state.StateCreated, integration)
}

func (h *AtlasThirdPartyIntegrationHandler) HandleCreated(ctx context.Context, integration *akov2next.AtlasThirdPartyIntegration) (ctrlstate.Result, error) {
	return h.upsert(ctx, state.StateCreated, state.StateUpdated, integration)
}

func (h *AtlasThirdPartyIntegrationHandler) HandleUpdated(ctx context.Context, integration *akov2next.AtlasThirdPartyIntegration) (ctrlstate.Result, error) {
	return h.upsert(ctx, state.StateUpdated, state.StateUpdated, integration)
}

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I think I go for the simpler static fix.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I think I go for the simpler static fix.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Actually, the next step is best, as if it was already created and it did not change, we want it to stay saying created.

}
if err != nil {
return result.Error(
state.StateInitial,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
state.StateInitial,
state.StateDeletionRequested

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.

unified state machine for the win 👏 this looks great!

return ctrlstate.NewStateReconciler(
handler,
ctrlstate.WithCluster[akov2next.AtlasThirdPartyIntegration](c),
ctrlstate.WithReapplySupport[akov2next.AtlasThirdPartyIntegration](reapplySupport),
Copy link
Collaborator

Choose a reason for hiding this comment

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

this looks very very tasty, great job! 👏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants