-
Notifications
You must be signed in to change notification settings - Fork 0
feat: Add TriggeredBy field to deployment history entries #36
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -102,7 +102,7 @@ | |
|
|
||
| // Reconcile is part of the main kubernetes reconciliation loop which aims to | ||
| // move the current state of the cluster closer to the desired state. | ||
| func (r *RolloutReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) { | ||
|
Check failure on line 105 in internal/controller/rollout_controller.go
|
||
| log := logf.FromContext(ctx) | ||
|
|
||
| rollout := rolloutv1alpha1.Rollout{} | ||
|
|
@@ -195,7 +195,7 @@ | |
| // Check if user has requested to unblock failed deployment via annotation | ||
| unblockRequested := false | ||
| if rollout.Annotations != nil { | ||
| if unblock, exists := rollout.Annotations["rollout.kuberik.com/unblock-failed"]; exists && unblock == "true" { | ||
|
Check failure on line 198 in internal/controller/rollout_controller.go
|
||
| unblockRequested = true | ||
| log.Info("User requested to unblock failed deployment via annotation") | ||
| } | ||
|
|
@@ -480,7 +480,7 @@ | |
| } | ||
|
|
||
| // parseOCIManifest extracts all metadata from OCI image manifest including version, revision, artifact type, source, title, and description. | ||
| func (r *RolloutReconciler) parseOCIManifest(ctx context.Context, imageRef string, imagePolicy *imagev1beta2.ImagePolicy) (version, revision, artifactType, source, title, description *string, created *metav1.Time, err error) { | ||
|
Check failure on line 483 in internal/controller/rollout_controller.go
|
||
| log := logf.FromContext(ctx) | ||
|
|
||
| // Get authentication keychain from ImageRepository | ||
|
|
@@ -719,7 +719,7 @@ | |
| } | ||
|
|
||
| // evaluateGates lists and evaluates gates, updates rollout status, and returns filtered candidates and gatesPassing. | ||
| func (r *RolloutReconciler) evaluateGates(ctx context.Context, namespace string, rollout *rolloutv1alpha1.Rollout, releaseCandidates []rolloutv1alpha1.VersionInfo) ([]rolloutv1alpha1.VersionInfo, bool, error) { | ||
|
Check failure on line 722 in internal/controller/rollout_controller.go
|
||
| // Check for gate bypass annotation | ||
| bypassVersion := "" | ||
| if rollout.Annotations != nil { | ||
|
|
@@ -1071,7 +1071,7 @@ | |
| } | ||
|
|
||
| // deployRelease finds and patches Flux resources with the wanted version. | ||
| func (r *RolloutReconciler) deployRelease(ctx context.Context, rollout *rolloutv1alpha1.Rollout, wantedRelease string) error { | ||
|
Check failure on line 1074 in internal/controller/rollout_controller.go
|
||
| log := logf.FromContext(ctx) | ||
|
|
||
| // Check if this deployment was done with gate bypass | ||
|
|
@@ -1167,6 +1167,9 @@ | |
| // Generate deployment message | ||
| deploymentMessage := r.generateDeploymentMessage(rollout, wantedRelease, bypassUsed, forceDeployUsed, unblockUsed) | ||
|
|
||
| // Extract triggered by information | ||
| triggeredBy := r.extractTriggeredByInfo(rollout, r.hasManualDeployment(rollout)) | ||
|
|
||
| // Find the version info for the wanted release | ||
| var versionInfo rolloutv1alpha1.VersionInfo | ||
| versionInfo.Tag = wantedRelease | ||
|
|
@@ -1200,6 +1203,7 @@ | |
| Version: versionInfo, | ||
| Timestamp: now, | ||
| Message: &deploymentMessage, | ||
| TriggeredBy: triggeredBy, | ||
| BakeStatus: bakeStatus, | ||
| BakeStatusMessage: bakeStatusMsg, | ||
| BakeStartTime: nil, // Will be set when healthchecks become healthy | ||
|
|
@@ -1288,22 +1292,24 @@ | |
|
|
||
| // Clear annotations based on deployment type | ||
| if forceDeployUsed { | ||
| // Clear both force-deploy and deploy-message annotations when force deploy was used | ||
| // Clear both force-deploy, deploy-message, and deploy-user annotations when force deploy was used | ||
| patch := client.MergeFrom(rollout.DeepCopy()) | ||
| delete(rollout.Annotations, "rollout.kuberik.com/force-deploy") | ||
| delete(rollout.Annotations, "rollout.kuberik.com/deploy-message") | ||
| delete(rollout.Annotations, "rollout.kuberik.com/deploy-user") | ||
|
|
||
| if err := r.Client.Patch(ctx, rollout, patch); err != nil { | ||
| log.Error(err, "Failed to patch rollout to clear force deploy annotations") | ||
| return err | ||
| } | ||
| } else if r.hasManualDeployment(rollout) { | ||
| // Clear only deploy-message annotation when WantedVersion was used | ||
| // Clear deploy-message and deploy-user annotations when WantedVersion was used | ||
| patch := client.MergeFrom(rollout.DeepCopy()) | ||
| delete(rollout.Annotations, "rollout.kuberik.com/deploy-message") | ||
| delete(rollout.Annotations, "rollout.kuberik.com/deploy-user") | ||
|
|
||
| if err := r.Client.Patch(ctx, rollout, patch); err != nil { | ||
| log.Error(err, "Failed to patch rollout to clear deploy-message annotation") | ||
| log.Error(err, "Failed to patch rollout to clear deploy-message and deploy-user annotations") | ||
| return err | ||
| } | ||
| } | ||
|
|
@@ -1459,7 +1465,7 @@ | |
| return nil | ||
| } | ||
|
|
||
| func (r *RolloutReconciler) handleBakeTime(ctx context.Context, namespace string, rollout *rolloutv1alpha1.Rollout) (ctrl.Result, error) { | ||
|
Check failure on line 1468 in internal/controller/rollout_controller.go
|
||
| log := logf.FromContext(ctx) | ||
| now := r.now() | ||
|
|
||
|
|
@@ -1777,6 +1783,26 @@ | |
| return 1 | ||
| } | ||
|
|
||
| // extractTriggeredByInfo extracts triggered by information from annotations. | ||
| // Returns nil if no user annotation is found (indicating a system-triggered deployment). | ||
| func (r *RolloutReconciler) extractTriggeredByInfo(rollout *rolloutv1alpha1.Rollout, isManualDeployment bool) *rolloutv1alpha1.TriggeredByInfo { | ||
| // Check for user annotation (similar to how we check deploy-message annotation) | ||
| if rollout.Annotations != nil { | ||
| if userName, exists := rollout.Annotations["rollout.kuberik.com/deploy-user"]; exists && userName != "" { | ||
| return &rolloutv1alpha1.TriggeredByInfo{ | ||
| Kind: "User", | ||
| Name: userName, | ||
| } | ||
| } | ||
| } | ||
|
|
||
| // If no user annotation found, it's a system-triggered deployment | ||
| return &rolloutv1alpha1.TriggeredByInfo{ | ||
| Kind: "System", | ||
| Name: "rollout-controller", | ||
| } | ||
| } | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Stale deploy-user annotation persists on automatic deploymentsThe Additional Locations (1) |
||
|
|
||
| // generateDeploymentMessage creates a descriptive message for a deployment history entry | ||
| func (r *RolloutReconciler) generateDeploymentMessage(rollout *rolloutv1alpha1.Rollout, wantedRelease string, bypassUsed, forceDeployUsed, unblockUsed bool) string { | ||
| var messageParts []string | ||
|
|
||
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.
Unused parameter causes incorrect deployment trigger attribution
The
extractTriggeredByInfofunction accepts anisManualDeploymentparameter that is explicitly passed at the call site but never used in the function body. When a user triggers a manual deployment viaWantedVersionorforce-deploywithout setting thedeploy-userannotation, the deployment is incorrectly recorded asKind: "System"instead of properly indicating it was user-initiated. The function comment also incorrectly states it "Returns nil if no user annotation is found" but the function never returns nil.Additional Locations (1)
internal/controller/rollout_controller.go#L1170-L1171