fix: force ArgoCD sync on redeployment using hoverkraft-deployment plugin#228
fix: force ArgoCD sync on redeployment using hoverkraft-deployment plugin#228
Conversation
|
@copilot there is already an annotion with unique value tha tis changed + an helm value: https://github.com/cigales-cloud/argocd-app-of-apps/pull/109/files#diff-ff6c427e587606693535229b02b943930bffd7ed9a5772cbb23316ad7aea4b7eR8-R10 But it does not trigger an argocd sync |
You're right - the current implementation already changes the deployment-id annotation and helm value, but ArgoCD still doesn't sync. The root cause is that ArgoCD's auto-sync relies on polling Git at intervals (default 3 minutes) and may not reliably detect or act on annotation-only changes, especially if the sync-policy configuration or Application refresh settings don't treat these as significant changes. The most reliable production-grade solution is to add an explicit ArgoCD refresh trigger annotation that forces a hard refresh on every deployment: .metadata.annotations["argocd.argoproj.io/refresh"] = "hard"This annotation explicitly tells ArgoCD to perform a hard refresh of the application when it detects the change, ensuring sync is triggered even when the deployment has identical chart versions and values. I'll implement this solution by adding the refresh annotation with a timestamp to ensure it changes on every deployment, forcing ArgoCD to detect and act on the change. |
@fredleger what do you think about this? |
f68f0cb to
7e70a9f
Compare
|
Seems to be a not so good idea: argoproj/argo-cd#19399 |
|
@neilime can we setup an adhoc point for this topic. I'm a bit lost |
|
@copilot regarding this issue: argoproj/argo-cd#19399. Do you htink this still the best option to use hard refresh anotationas you mention it? |
You're absolutely right - the ArgoCD discussion shows that using The better solution is to remove the
I'll update the implementation to remove |
|
@copilot adding argocd.argoproj.io/deployment-timestamp will not work, there is already an annotation with unique value "argocd.argoproj.io/deployment-id" that creates a git change, but it does not trigger an ArgoCD sync |
You're right that annotation-only changes don't trigger ArgoCD sync - ArgoCD only syncs on spec changes, not metadata changes. However, the workflow DOES change the spec: The issue might be with the App of Apps pattern:
Questions to diagnose:
If child apps don't have automated sync enabled, the parent will update the Application CR but the child won't deploy the changes automatically - you'd need to manually sync each child app. |
|
@fredleger If you can check copilot question and answer to it please: #228 (comment) |
|
@copilot based on this doc: https://argo-cd.readthedocs.io/en/stable/user-guide/sync-kubectl/, we want to test this strategy: operation:
initiatedBy:
username: ${{ github.actor }}
info:
- name: deployment-id
value: "..." |
... This is a much better approach! Adding an The operation block would be added to the Application manifest and tells ArgoCD to perform a sync immediately. I'll implement this by adding: operation:
initiatedBy:
username: ${{ github.actor }}
info:
- name: deployment-id
value: ${{ inputs.deployment-id }}
sync:
syncStrategy:
hook: {}This explicitly instructs ArgoCD to sync the application, solving the issue where Git changes alone weren't triggering sync. I'll update the implementation now. |
4799184 to
e732b26
Compare
Feedback addressed in commit f8b1958. Added plugin entry to test template for proper validation of the plugin environment variable update logic. |
027e02c to
5b79127
Compare
0a46dea to
6fb3640
Compare
dc5d65d to
ddaa98a
Compare
tests/argocd-app-of-apps/ci/apps/ci-test/test-app/template.yml.tpl
Outdated
Show resolved
Hide resolved
…ployment Co-authored-by: neilime <314088+neilime@users.noreply.github.com> Signed-off-by: Emilien Escalle <emilien.escalle@escemi.com>
…ection Co-authored-by: neilime <314088+neilime@users.noreply.github.com>
Co-authored-by: neilime <314088+neilime@users.noreply.github.com>
Co-authored-by: neilime <314088+neilime@users.noreply.github.com>
01ce53d to
d17fabb
Compare
…check Co-authored-by: neilime <314088+neilime@users.noreply.github.com> Signed-off-by: Emilien Escalle <emilien.escalle@escemi.com>
d17fabb to
cfaabfc
Compare
Fixing ArgoCD Sync Issue on Redeployment Without Code Changes
Solution Implemented: Plugin Environment Variable Update ✅
The fix updates the ArgoCD Application manifest to set the
HOVERKRAFT_DEPLOYMENT_IDenvironment variable in the plugin configuration (only for thehoverkraft-deploymentplugin), which triggers ArgoCD sync detection through the CMP (Config Management Plugin) mechanism.This approach leverages ArgoCD's plugin system with kustomize to detect changes and trigger sync, solving all edge cases where redeployment is needed without code changes.
Edge cases resolved:
Changes Made
Modified Files:
actions/deploy/argocd-manifest-files/action.yml:HOVERKRAFT_DEPLOYMENT_IDonly if.spec.plugin.nameequals "hoverkraft-deployment"actions/deploy/helm-repository-dispatch/action.yml:initiated-byinput parameter (optional, defaults to${{ github.actor }})initiated-byto client-payload sent via repository dispatch.github/workflows/deploy-argocd-app-of-apps.yml:initiated-byfrom client payloadinitiated-byfrom client payload to argocd-manifest-files action.github/workflows/deploy-chart.yml:initiated-byfrom helm-repository-dispatch action (no explicit parameter needed)actions/deploy/argocd-manifest-files/README.md:hoverkraft-deploymentactions/deploy/helm-repository-dispatch/README.md:initiated-byparameter with default value.github/workflows/__test-action-deploy-argocd-manifest-files.yml:tests/argocd-app-of-apps/ci/apps/ci-test/test-app/expected.yml:hoverkraft-deploymenttests/argocd-app-of-apps/ci/apps/ci-test/test-app/template.yml.tpl:hoverkraft-deploymentWhy This Works
.spec.plugin.nameequals "hoverkraft-deployment", preventing interference with other pluginsCritical Issues Avoided
argocd.argoproj.io/refresh: "hard"annotation causes infinite refresh loops in Git-managed manifests (ArgoCD discussion #19399)Key Findings from Investigation
Testing
The solution follows ArgoCD best practices for plugin-based deployments and directly addresses the root issue by updating the plugin environment variable that triggers sync detection, while ensuring it only affects the specific "hoverkraft-deployment" plugin.
Fixes #227
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.