-
Notifications
You must be signed in to change notification settings - Fork 94
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
base: main
Are you sure you want to change the base?
Conversation
105c5be
to
d35b1f4
Compare
67fd52f
to
0fa07a0
Compare
8375d68
to
fc928bf
Compare
fc928bf
to
38ac42f
Compare
38ac42f
to
b653cd5
Compare
Watches( | ||
&akov2.AtlasProject{}, | ||
handler.EnqueueRequestsFromMapFunc(h.integrationForProjectMapFunc()), | ||
builder.WithPredicates(integrationPredicates), |
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.
we want to watch for generation changes only here.
Watches( | ||
&akov2.AtlasProject{}, | ||
handler.EnqueueRequestsFromMapFunc(h.integrationForProjectMapFunc()), | ||
builder.WithPredicates(integrationPredicates), |
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.
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.
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.
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.
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 will just drop the var and funcs in the end.
&corev1.Secret{}, | ||
handler.EnqueueRequestsFromMapFunc(h.integrationForSecretMapFunc()), | ||
builder.WithPredicates(integrationPredicates), | ||
). |
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.
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.
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.
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, |
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.
state.StateCreated, | |
state.StateUpdated, |
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.
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)
}
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 think I go for the simpler static fix.
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 think I go for the simpler static fix.
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.
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, |
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.
state.StateInitial, | |
state.StateDeletionRequested |
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.
unified state machine for the win 👏 this looks great!
return ctrlstate.NewStateReconciler( | ||
handler, | ||
ctrlstate.WithCluster[akov2next.AtlasThirdPartyIntegration](c), | ||
ctrlstate.WithReapplySupport[akov2next.AtlasThirdPartyIntegration](reapplySupport), |
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.
this looks very very tasty, great job! 👏
Signed-off-by: jose.vazquez <[email protected]>
Summary
Internal-only implementation for the integrations controller
Proof of Work
TBD including new tests
Checklist
Reminder (Please remove this when merging)