Add rollback controller reconcile loop - #438
Conversation
| return false | ||
| } | ||
|
|
||
| // TODO: move this into api/deploy/v1alpha1/release_helpers.go once release reconciler PR is merged |
e41713a to
2adf735
Compare
1eb2a73 to
05eccce
Compare
05eccce to
c203ff0
Compare
0x0013
left a comment
There was a problem hiding this comment.
Nicely done!
Added a couple comments.
| meta.SetStatusCondition(&rollback.Status.Conditions, metav1.Condition{ | ||
| Type: deployv1alpha1.RollbackConditionInProgress, | ||
| Status: metav1.ConditionTrue, | ||
| Reason: "Retrying", | ||
| Message: fmt.Sprintf("Deployment attempt %d failed: %s. Retrying...", rollback.Status.AttemptCount, statusResp.Message), | ||
| LastTransitionTime: now, | ||
| }) |
There was a problem hiding this comment.
we're setting the condition here, but it seems it will get overwritten almost immediately in triggerDeployment.
There was a problem hiding this comment.
Not necessarily - if triggerDeployment fails to trigger the deployment with a retryable error, the condition won't be updated and the Rollback will get requeued for reconciliation. That said, I'm now wondering if the rollback.Status.Message message set on line 144 would be better set on the InProgress condition.
There was a problem hiding this comment.
@0x0013 I've decided to simplify this a bit and agree it doesn't make sense to set the InProgress=True condition here in pollDeploymentStatus. Instead, we now set it once at the start of triggerDeployment with Reason=DeploymentTriggering and once at the end after a successful trigger with Reason=DeploymentTriggered.
This should make the behaviour clearer when a Rollback gets stuck trying and failing to trigger a deployment via the cicd backend, as the reason DeploymentTriggering will remain, whilst the failures themselves will be recorded in the rollback.Status.Message.
| Status: metav1.ConditionFalse, | ||
| Reason: "Completed", | ||
| Message: "Rollback deployment completed", | ||
| LastTransitionTime: now, |
There was a problem hiding this comment.
Same as noted previously, the transition time should get set by setStatusCondition.
There was a problem hiding this comment.
I'm leaning towards leaving this (and the LastTransitionTime below) as set explicitly since this is the only transition the InProgress condition will make to False (and likewise below with the Succeeded condition to True).
The value I see is that by setting rollback.Status.CompletionTime and the LastTransitionTime of both conditions in this function to the same now value, it'll be clearer that the conditions transitioned to the terminal states as part of the completion of the rollback (particularly programmatically, if we ever need to compare the timestamps).
aa85c7c to
a7ac338
Compare
0x0013
left a comment
There was a problem hiding this comment.
Added a few more comments.
One thing I'm not fully convinced about, is setting the RollbackConditionInProgress with the "DeploymentTriggering" reason. While I understand the idea behind the behavior, I think I would prefer for RollbackConditionInProgress==True to mean that Deployment has already been triggered. It would make it clearer what the condition state implies.
However, I'm not yet fully convinced myself, and I will think a little more whether the current approach could be problematic down the line.
|
@IsaacJames another thing not directly related to changes in this PR, but rather the reference fields in the CRD: See Object References section in API Conventions for details. Using the example in the doc, the full ref would then be: toReleaseRef:
name: foo |
0x0013
left a comment
There was a problem hiding this comment.
I've left another small comment, in case you have ideas how to refactor it. But otherwise, this looks good - great job!
| } | ||
| } | ||
|
|
||
| func createDeployer(ctx context.Context, backend, githubToken string) (cicd.Deployer, error) { |
There was a problem hiding this comment.
I'm not a fan of having a github-specific argument, given that you've nicely made the Deployer an interface.. But I can't currently come up with an elegant way to do it otherwise, so I guess it's OK, with the argument only being checked when github is being used.
There was a problem hiding this comment.
Actually, given githubToken is a global variable, I can just get rid of the argument in this method.
Rollback Controller Implementation
This PR implements the RollbackReconciler which manages
Rollbackresources by triggering deployments via a configurable CICD backend and polling for completion.internal/controller/deploy/rollback_controller.goInProgress,Succeeded)FromReleaseNamecmd/rollback-manager/main.go--cicd-backendflag (noop, github)--github-tokenflag /ROLLBACK_MANAGER_GITHUB_TOKENenv var--rollback-history-limitflagReconcile Loop
Error Handling
RollbackStatus ConditionsInProgressTrueInProgressFalse+SucceededSucceededTrueSucceededFalseManager Configuration