Skip to content

Let Argo CD Commit Status Controller work without Source Hydrator #674

@seankhliao

Description

@seankhliao

The Argo CD Commit Status Controller currently has the note: https://argo-gitops-promoter.readthedocs.io/en/latest/commit-status-controllers/argocd/

Currently this controller only works with Argo CD Applications that are configured to use the Source Hydrator.

Looking at the code, it appears the hydrator config is used for a few sanity checks (same repo, target branch) but nothing that won't work if the sync revision is just the target branch.

func (r *ArgoCDCommitStatusReconciler) groupArgoCDApplicationsWithPhase(promotionStrategy *promoterv1alpha1.PromotionStrategy, argoCDCommitStatus *promoterv1alpha1.ArgoCDCommitStatus, apps []ApplicationsInEnvironment) (map[string][]*aggregate, error) {
aggregates := map[string][]*aggregate{}
argoCDCommitStatus.Status.ApplicationsSelected = []promoterv1alpha1.ApplicationsSelected{}
repo := ""
for _, clusterApps := range apps {
for _, application := range clusterApps.Items {
if application.Spec.SourceHydrator == nil {
return map[string][]*aggregate{}, fmt.Errorf("application %s/%s does not have a SourceHydrator configured", application.GetNamespace(), application.GetName())
}
// Check that all the applications are configured with the same repo
if repo == "" {
repo = application.Spec.SourceHydrator.DrySource.RepoURL
} else if repo != application.Spec.SourceHydrator.DrySource.RepoURL {
return map[string][]*aggregate{}, errors.New("all applications must have the same repo configured")
}
// Check that TargetBranch is not empty
if application.Spec.SourceHydrator.SyncSource.TargetBranch == "" {
return map[string][]*aggregate{}, fmt.Errorf("application %s/%s spec.sourceHydrator.syncSource.targetBranch must not be empty", application.GetNamespace(), application.GetName())
}
aggregateItem := &aggregate{
application: &application,
}
phase := promoterv1alpha1.CommitPhasePending
if application.Status.Health.Status == argocd.HealthStatusHealthy && application.Status.Sync.Status == argocd.SyncStatusCodeSynced {
phase = promoterv1alpha1.CommitPhaseSuccess
} else if application.Status.Health.Status == argocd.HealthStatusDegraded {
phase = promoterv1alpha1.CommitPhaseFailure
}
// This is an in memory version of the desired CommitStatus for a single application, this will be used to figure out
// the aggregated phase of all applications for a particular environment
aggregateItem.commitStatus = &promoterv1alpha1.CommitStatus{
Spec: promoterv1alpha1.CommitStatusSpec{
Sha: application.Status.Sync.Revision,
Phase: phase,
},
}
argoCDCommitStatus.Status.ApplicationsSelected = append(argoCDCommitStatus.Status.ApplicationsSelected, promoterv1alpha1.ApplicationsSelected{
Namespace: application.GetNamespace(),
Name: application.GetName(),
Phase: phase,
Sha: application.Status.Sync.Revision,
LastTransitionTime: application.Status.Health.LastTransitionTime,
Environment: application.Spec.SourceHydrator.SyncSource.TargetBranch,
ClusterName: clusterApps.ClusterName,
})
aggregates[application.Spec.SourceHydrator.SyncSource.TargetBranch] = append(aggregates[application.Spec.SourceHydrator.SyncSource.TargetBranch], aggregateItem)
}
}

We currently have quite a few ArgoCD applications that deploy using ArgoCD's Helm support.
While fully rendered manifests may be a goal in the future the immediate benefits are less clear, compared to having something like Gitops Promoter manage deployments across environments.

The way I see it working is:

  • our CI will manage the hydration part (push commits to -next branches, create hydrator.metadata, update helm values with image.tag: latest -> image.tag: $commit_sha), resulting in a half hydrated manifest.
  • Argo CD will sync from the target branches, and render helm charts on demand as they do now
  • Gitops Promoter will watch the ArgoCD applications for health status to gate rollouts.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions