From 5080ec5b1e7f7ef322a2a6a76ff357199a69c84a Mon Sep 17 00:00:00 2001 From: Zach Aller Date: Mon, 20 Jan 2025 17:00:12 -0600 Subject: [PATCH] chore: add applications selected sha and state Signed-off-by: Zach Aller --- api/v1alpha1/argocdcommitstatus_types.go | 10 +++-- api/v1alpha1/zz_generated.deepcopy.go | 32 +++++++-------- ...oter.argoproj.io_argocdcommitstatuses.yaml | 6 +++ dist/install.yaml | 6 +++ .../argocdcommitstatus_controller.go | 40 ++++++++++++++----- 5 files changed, 65 insertions(+), 29 deletions(-) diff --git a/api/v1alpha1/argocdcommitstatus_types.go b/api/v1alpha1/argocdcommitstatus_types.go index 1a29268..7ac8454 100644 --- a/api/v1alpha1/argocdcommitstatus_types.go +++ b/api/v1alpha1/argocdcommitstatus_types.go @@ -36,12 +36,14 @@ type ArgoCDCommitStatusSpec struct { type ArgoCDCommitStatusStatus struct { // INSERT ADDITIONAL STATUS FIELD - define observed state of cluster // Important: Run "make" to regenerate code after modifying this file - ApplicationsSelected []NamespacedName `json:"applicationsSelected,omitempty"` + ApplicationsSelected []SelectedApplications `json:"applicationsSelected,omitempty"` } -type NamespacedName struct { - Namespace string `json:"namespace"` - Name string `json:"name"` +type SelectedApplications struct { + Namespace string `json:"namespace"` + Name string `json:"name"` + Sate CommitStatusPhase `json:"state"` + Sha string `json:"sha"` } // +kubebuilder:object:root=true diff --git a/api/v1alpha1/zz_generated.deepcopy.go b/api/v1alpha1/zz_generated.deepcopy.go index dc022ad..e58138a 100644 --- a/api/v1alpha1/zz_generated.deepcopy.go +++ b/api/v1alpha1/zz_generated.deepcopy.go @@ -111,7 +111,7 @@ func (in *ArgoCDCommitStatusStatus) DeepCopyInto(out *ArgoCDCommitStatusStatus) *out = *in if in.ApplicationsSelected != nil { in, out := &in.ApplicationsSelected, &out.ApplicationsSelected - *out = make([]NamespacedName, len(*in)) + *out = make([]SelectedApplications, len(*in)) copy(*out, *in) } } @@ -581,21 +581,6 @@ func (in *HealthyDryShas) DeepCopy() *HealthyDryShas { return out } -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *NamespacedName) DeepCopyInto(out *NamespacedName) { - *out = *in -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new NamespacedName. -func (in *NamespacedName) DeepCopy() *NamespacedName { - if in == nil { - return nil - } - out := new(NamespacedName) - in.DeepCopyInto(out) - return out -} - // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *ObjectReference) DeepCopyInto(out *ObjectReference) { *out = *in @@ -1041,3 +1026,18 @@ func (in *ScmProviderStatus) DeepCopy() *ScmProviderStatus { in.DeepCopyInto(out) return out } + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *SelectedApplications) DeepCopyInto(out *SelectedApplications) { + *out = *in +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new SelectedApplications. +func (in *SelectedApplications) DeepCopy() *SelectedApplications { + if in == nil { + return nil + } + out := new(SelectedApplications) + in.DeepCopyInto(out) + return out +} diff --git a/config/crd/bases/promoter.argoproj.io_argocdcommitstatuses.yaml b/config/crd/bases/promoter.argoproj.io_argocdcommitstatuses.yaml index e718c15..d22be3d 100644 --- a/config/crd/bases/promoter.argoproj.io_argocdcommitstatuses.yaml +++ b/config/crd/bases/promoter.argoproj.io_argocdcommitstatuses.yaml @@ -113,9 +113,15 @@ spec: type: string namespace: type: string + sha: + type: string + state: + type: string required: - name - namespace + - sha + - state type: object type: array type: object diff --git a/dist/install.yaml b/dist/install.yaml index 710c222..1476288 100644 --- a/dist/install.yaml +++ b/dist/install.yaml @@ -125,9 +125,15 @@ spec: type: string namespace: type: string + sha: + type: string + state: + type: string required: - name - namespace + - sha + - state type: object type: array type: object diff --git a/internal/controller/argocdcommitstatus_controller.go b/internal/controller/argocdcommitstatus_controller.go index 9fd2fc5..37fe526 100644 --- a/internal/controller/argocdcommitstatus_controller.go +++ b/internal/controller/argocdcommitstatus_controller.go @@ -53,8 +53,9 @@ var gvk = schema.GroupVersionKind{ } type Aggregate struct { - application *argocd.ArgoCDApplication - commitStatus *promoterv1alpha1.CommitStatus + application *argocd.ArgoCDApplication + commitStatus *promoterv1alpha1.CommitStatus + selectedApplication *promoterv1alpha1.SelectedApplications } type objKey struct { @@ -114,13 +115,13 @@ func (r *ArgoCDCommitStatusReconciler) Reconcile(ctx context.Context, req ctrl.R return ctrl.Result{}, fmt.Errorf("failed to list CommitStatus objects: %w", err) } - argoCDCommitStatus.Status.ApplicationsSelected = []promoterv1alpha1.NamespacedName{} - for _, item := range ul.Items { - argoCDCommitStatus.Status.ApplicationsSelected = append(argoCDCommitStatus.Status.ApplicationsSelected, promoterv1alpha1.NamespacedName{ - Namespace: item.GetNamespace(), - Name: item.GetName(), - }) - } + //argoCDCommitStatus.Status.ApplicationsSelected = []promoterv1alpha1.SelectedApplications{} + //for _, item := range ul.Items { + // argoCDCommitStatus.Status.ApplicationsSelected = append(argoCDCommitStatus.Status.ApplicationsSelected, promoterv1alpha1.SelectedApplications{ + // Namespace: item.GetNamespace(), + // Name: item.GetName(), + // }) + //} ps, err := r.getPromotionStrategy(ctx, argoCDCommitStatus.GetNamespace(), argoCDCommitStatus.Spec.PromotionStrategyRef) if err != nil { @@ -137,6 +138,7 @@ func (r *ArgoCDCommitStatusReconciler) Reconcile(ctx context.Context, req ctrl.R return ctrl.Result{}, fmt.Errorf("failed to get git auth provider for ScmProvider %q: %w", scmProvider.Name, err) } + argoCDCommitStatus.Status.ApplicationsSelected = []promoterv1alpha1.SelectedApplications{} for _, obj := range ul.Items { var application argocd.ArgoCDApplication err = runtime.DefaultUnstructuredConverter.FromUnstructured(obj.Object, &application) @@ -172,6 +174,18 @@ func (r *ArgoCDCommitStatusReconciler) Reconcile(ctx context.Context, req ctrl.R Phase: state, }, } + aggregateItem.selectedApplication = &promoterv1alpha1.SelectedApplications{} + aggregateItem.selectedApplication.Sate = state + aggregateItem.selectedApplication.Sha = application.Status.Sync.Revision + aggregateItem.selectedApplication.Name = application.GetName() + aggregateItem.selectedApplication.Namespace = application.GetNamespace() + + argoCDCommitStatus.Status.ApplicationsSelected = append(argoCDCommitStatus.Status.ApplicationsSelected, promoterv1alpha1.SelectedApplications{ + Namespace: application.GetNamespace(), + Name: application.GetName(), + Sate: state, + Sha: application.Status.Sync.Revision, + }) aggregates[key] = append(aggregates[key], aggregateItem) } @@ -222,6 +236,14 @@ func (r *ArgoCDCommitStatusReconciler) Reconcile(ctx context.Context, req ctrl.R if err != nil { return ctrl.Result{}, err } + + //argoCDCommitStatus.Status.ApplicationsSelected = []promoterv1alpha1.SelectedApplications{} + //for _, item := range ul.Items { + // argoCDCommitStatus.Status.ApplicationsSelected = append(argoCDCommitStatus.Status.ApplicationsSelected, promoterv1alpha1.SelectedApplications{ + // Namespace: item.GetNamespace(), + // Name: item.GetName(), + // }) + //} } err = r.Status().Update(ctx, &argoCDCommitStatus)