Skip to content

Commit

Permalink
chore: add applications selected sha and state
Browse files Browse the repository at this point in the history
Signed-off-by: Zach Aller <[email protected]>
  • Loading branch information
zachaller committed Jan 20, 2025
1 parent c7486f2 commit 5080ec5
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 29 deletions.
10 changes: 6 additions & 4 deletions api/v1alpha1/argocdcommitstatus_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
32 changes: 16 additions & 16 deletions api/v1alpha1/zz_generated.deepcopy.go

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
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions dist/install.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
40 changes: 31 additions & 9 deletions internal/controller/argocdcommitstatus_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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{}

Check failure on line 118 in internal/controller/argocdcommitstatus_controller.go

View workflow job for this annotation

GitHub Actions / Continuous Integration

commentFormatting: put a space between `//` and comment text (gocritic)
//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 {
Expand All @@ -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)
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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{}

Check failure on line 240 in internal/controller/argocdcommitstatus_controller.go

View workflow job for this annotation

GitHub Actions / Continuous Integration

commentFormatting: put a space between `//` and comment text (gocritic)
//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)
Expand Down

0 comments on commit 5080ec5

Please sign in to comment.