From e8c354b027ea3f0f9306690768a2e602cb2d88e2 Mon Sep 17 00:00:00 2001 From: gmuselli Date: Fri, 24 Nov 2023 17:33:11 -0500 Subject: [PATCH] fix(11164): Put back argov1alpha1 Signed-off-by: gmuselli --- .../controllers/applicationset_controller.go | 284 +++++++++--------- 1 file changed, 142 insertions(+), 142 deletions(-) diff --git a/applicationset/controllers/applicationset_controller.go b/applicationset/controllers/applicationset_controller.go index 53dbe500aba64..541c49279b585 100644 --- a/applicationset/controllers/applicationset_controller.go +++ b/applicationset/controllers/applicationset_controller.go @@ -47,7 +47,7 @@ import ( "github.com/argoproj/argo-cd/v2/util/db" "github.com/argoproj/argo-cd/v2/util/glob" - appv1 "github.com/argoproj/argo-cd/v2/pkg/apis/application/v1alpha1" + argov1alpha1 "github.com/argoproj/argo-cd/v2/pkg/apis/application/v1alpha1" appclientset "github.com/argoproj/argo-cd/v2/pkg/client/clientset/versioned" argoutil "github.com/argoproj/argo-cd/v2/util/argo" @@ -65,7 +65,7 @@ const ( var ( defaultPreservedAnnotations = []string{ NotifiedAnnotationKey, - appv1.AnnotationKeyRefresh, + argov1alpha1.AnnotationKeyRefresh, } ) @@ -78,7 +78,7 @@ type ApplicationSetReconciler struct { ArgoDB db.ArgoDB ArgoAppClientset appclientset.Interface KubeClientset kubernetes.Interface - Policy appv1.ApplicationsSyncPolicy + Policy argov1alpha1.ApplicationsSyncPolicy EnablePolicyOverride bool utils.Renderer ArgoCDNamespace string @@ -96,7 +96,7 @@ type ApplicationSetReconciler struct { func (r *ApplicationSetReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) { logCtx := log.WithField("applicationset", req.NamespacedName) - var applicationSetInfo appv1.ApplicationSet + var applicationSetInfo argov1alpha1.ApplicationSet parametersGenerated := false if err := r.Get(ctx, req.NamespacedName, &applicationSetInfo); err != nil { @@ -108,13 +108,13 @@ func (r *ApplicationSetReconciler) Reconcile(ctx context.Context, req ctrl.Reque // Do not attempt to further reconcile the ApplicationSet if it is being deleted. if applicationSetInfo.ObjectMeta.DeletionTimestamp != nil { - if controllerutil.ContainsFinalizer(&applicationSetInfo, appv1.ResourcesFinalizerName) { + if controllerutil.ContainsFinalizer(&applicationSetInfo, argov1alpha1.ResourcesFinalizerName) { deleteAllowed := utils.DefaultPolicy(applicationSetInfo.Spec.SyncPolicy, r.Policy, r.EnablePolicyOverride).AllowDelete() if !deleteAllowed { if err := r.removeOwnerReferencesOnDeleteAppSet(ctx, applicationSetInfo); err != nil { return ctrl.Result{}, err } - controllerutil.RemoveFinalizer(&applicationSetInfo, appv1.ResourcesFinalizerName) + controllerutil.RemoveFinalizer(&applicationSetInfo, argov1alpha1.ResourcesFinalizerName) if err := r.Update(ctx, &applicationSetInfo); err != nil { return ctrl.Result{}, err } @@ -130,11 +130,11 @@ func (r *ApplicationSetReconciler) Reconcile(ctx context.Context, req ctrl.Reque if err != nil { _ = r.setApplicationSetStatusCondition(ctx, &applicationSetInfo, - appv1.ApplicationSetCondition{ - Type: appv1.ApplicationSetConditionErrorOccurred, + argov1alpha1.ApplicationSetCondition{ + Type: argov1alpha1.ApplicationSetConditionErrorOccurred, Message: err.Error(), Reason: string(applicationSetReason), - Status: appv1.ApplicationSetConditionStatusTrue, + Status: argov1alpha1.ApplicationSetConditionStatusTrue, }, parametersGenerated, ) return ctrl.Result{}, err @@ -155,18 +155,18 @@ func (r *ApplicationSetReconciler) Reconcile(ctx context.Context, req ctrl.Reque _ = r.setApplicationSetStatusCondition(ctx, &applicationSetInfo, - appv1.ApplicationSetCondition{ - Type: appv1.ApplicationSetConditionErrorOccurred, + argov1alpha1.ApplicationSetCondition{ + Type: argov1alpha1.ApplicationSetConditionErrorOccurred, Message: err.Error(), - Reason: appv1.ApplicationSetReasonApplicationValidationError, - Status: appv1.ApplicationSetConditionStatusTrue, + Reason: argov1alpha1.ApplicationSetReasonApplicationValidationError, + Status: argov1alpha1.ApplicationSetConditionStatusTrue, }, parametersGenerated, ) return ctrl.Result{RequeueAfter: ReconcileRequeueOnValidationError}, nil } // appMap is a name->app collection of Applications in this ApplicationSet. - appMap := map[string]appv1.Application{} + appMap := map[string]argov1alpha1.Application{} // appSyncMap tracks which apps will be synced during this reconciliation. appSyncMap := map[string]bool{} @@ -175,7 +175,7 @@ func (r *ApplicationSetReconciler) Reconcile(ctx context.Context, req ctrl.Reque // If appset used progressive sync but stopped, clean up the progressive sync application statuses logCtx.Infof("Removing %v unnecessary AppStatus entries from ApplicationSet %v", len(applicationSetInfo.Status.ApplicationStatus), applicationSetInfo.Name) - err := r.setAppSetApplicationStatus(ctx, logCtx, &applicationSetInfo, []appv1.ApplicationSetApplicationStatus{}) + err := r.setAppSetApplicationStatus(ctx, logCtx, &applicationSetInfo, []argov1alpha1.ApplicationSetApplicationStatus{}) if err != nil { return ctrl.Result{}, fmt.Errorf("failed to clear previous AppSet application statuses for %v: %w", applicationSetInfo.Name, err) } @@ -197,7 +197,7 @@ func (r *ApplicationSetReconciler) Reconcile(ctx context.Context, req ctrl.Reque } } - var validApps []appv1.Application + var validApps []argov1alpha1.Application for i := range desiredApplications { if validateErrors[i] == nil { validApps = append(validApps, desiredApplications[i]) @@ -216,11 +216,11 @@ func (r *ApplicationSetReconciler) Reconcile(ctx context.Context, req ctrl.Reque } _ = r.setApplicationSetStatusCondition(ctx, &applicationSetInfo, - appv1.ApplicationSetCondition{ - Type: appv1.ApplicationSetConditionErrorOccurred, + argov1alpha1.ApplicationSetCondition{ + Type: argov1alpha1.ApplicationSetConditionErrorOccurred, Message: message, - Reason: appv1.ApplicationSetReasonApplicationValidationError, - Status: appv1.ApplicationSetConditionStatusTrue, + Reason: argov1alpha1.ApplicationSetReasonApplicationValidationError, + Status: argov1alpha1.ApplicationSetConditionStatusTrue, }, parametersGenerated, ) } @@ -233,11 +233,11 @@ func (r *ApplicationSetReconciler) Reconcile(ctx context.Context, req ctrl.Reque if err != nil { _ = r.setApplicationSetStatusCondition(ctx, &applicationSetInfo, - appv1.ApplicationSetCondition{ - Type: appv1.ApplicationSetConditionErrorOccurred, + argov1alpha1.ApplicationSetCondition{ + Type: argov1alpha1.ApplicationSetConditionErrorOccurred, Message: err.Error(), - Reason: appv1.ApplicationSetReasonSyncApplicationError, - Status: appv1.ApplicationSetConditionStatusTrue, + Reason: argov1alpha1.ApplicationSetReasonSyncApplicationError, + Status: argov1alpha1.ApplicationSetConditionStatusTrue, }, parametersGenerated, ) return ctrl.Result{}, err @@ -250,11 +250,11 @@ func (r *ApplicationSetReconciler) Reconcile(ctx context.Context, req ctrl.Reque if err != nil { _ = r.setApplicationSetStatusCondition(ctx, &applicationSetInfo, - appv1.ApplicationSetCondition{ - Type: appv1.ApplicationSetConditionErrorOccurred, + argov1alpha1.ApplicationSetCondition{ + Type: argov1alpha1.ApplicationSetConditionErrorOccurred, Message: err.Error(), - Reason: appv1.ApplicationSetReasonUpdateApplicationError, - Status: appv1.ApplicationSetConditionStatusTrue, + Reason: argov1alpha1.ApplicationSetReasonUpdateApplicationError, + Status: argov1alpha1.ApplicationSetConditionStatusTrue, }, parametersGenerated, ) return ctrl.Result{}, err @@ -264,11 +264,11 @@ func (r *ApplicationSetReconciler) Reconcile(ctx context.Context, req ctrl.Reque if err != nil { _ = r.setApplicationSetStatusCondition(ctx, &applicationSetInfo, - appv1.ApplicationSetCondition{ - Type: appv1.ApplicationSetConditionErrorOccurred, + argov1alpha1.ApplicationSetCondition{ + Type: argov1alpha1.ApplicationSetConditionErrorOccurred, Message: err.Error(), - Reason: appv1.ApplicationSetReasonCreateApplicationError, - Status: appv1.ApplicationSetConditionStatusTrue, + Reason: argov1alpha1.ApplicationSetReasonCreateApplicationError, + Status: argov1alpha1.ApplicationSetConditionStatusTrue, }, parametersGenerated, ) return ctrl.Result{}, err @@ -280,11 +280,11 @@ func (r *ApplicationSetReconciler) Reconcile(ctx context.Context, req ctrl.Reque if err != nil { _ = r.setApplicationSetStatusCondition(ctx, &applicationSetInfo, - appv1.ApplicationSetCondition{ - Type: appv1.ApplicationSetConditionResourcesUpToDate, + argov1alpha1.ApplicationSetCondition{ + Type: argov1alpha1.ApplicationSetConditionResourcesUpToDate, Message: err.Error(), - Reason: appv1.ApplicationSetReasonDeleteApplicationError, - Status: appv1.ApplicationSetConditionStatusTrue, + Reason: argov1alpha1.ApplicationSetReasonDeleteApplicationError, + Status: argov1alpha1.ApplicationSetConditionStatusTrue, }, parametersGenerated, ) return ctrl.Result{}, err @@ -298,11 +298,11 @@ func (r *ApplicationSetReconciler) Reconcile(ctx context.Context, req ctrl.Reque logCtx.Warnf("error occurred while updating ApplicationSet: %v", err) _ = r.setApplicationSetStatusCondition(ctx, &applicationSetInfo, - appv1.ApplicationSetCondition{ - Type: appv1.ApplicationSetConditionErrorOccurred, + argov1alpha1.ApplicationSetCondition{ + Type: argov1alpha1.ApplicationSetConditionErrorOccurred, Message: err.Error(), - Reason: appv1.ApplicationSetReasonRefreshApplicationError, - Status: appv1.ApplicationSetConditionStatusTrue, + Reason: argov1alpha1.ApplicationSetReasonRefreshApplicationError, + Status: argov1alpha1.ApplicationSetConditionStatusTrue, }, parametersGenerated, ) return ctrl.Result{}, err @@ -314,11 +314,11 @@ func (r *ApplicationSetReconciler) Reconcile(ctx context.Context, req ctrl.Reque if len(validateErrors) == 0 { if err := r.setApplicationSetStatusCondition(ctx, &applicationSetInfo, - appv1.ApplicationSetCondition{ - Type: appv1.ApplicationSetConditionResourcesUpToDate, + argov1alpha1.ApplicationSetCondition{ + Type: argov1alpha1.ApplicationSetConditionResourcesUpToDate, Message: "All applications have been generated successfully", - Reason: appv1.ApplicationSetReasonApplicationSetUpToDate, - Status: appv1.ApplicationSetConditionStatusTrue, + Reason: argov1alpha1.ApplicationSetReasonApplicationSetUpToDate, + Status: argov1alpha1.ApplicationSetConditionStatusTrue, }, parametersGenerated, ); err != nil { return ctrl.Result{}, err @@ -335,67 +335,67 @@ func (r *ApplicationSetReconciler) Reconcile(ctx context.Context, req ctrl.Reque }, nil } -func getParametersGeneratedCondition(parametersGenerated bool, message string) appv1.ApplicationSetCondition { - var paramtersGeneratedCondition appv1.ApplicationSetCondition +func getParametersGeneratedCondition(parametersGenerated bool, message string) argov1alpha1.ApplicationSetCondition { + var paramtersGeneratedCondition argov1alpha1.ApplicationSetCondition if parametersGenerated { - paramtersGeneratedCondition = appv1.ApplicationSetCondition{ - Type: appv1.ApplicationSetConditionParametersGenerated, + paramtersGeneratedCondition = argov1alpha1.ApplicationSetCondition{ + Type: argov1alpha1.ApplicationSetConditionParametersGenerated, Message: "Successfully generated parameters for all Applications", - Reason: appv1.ApplicationSetReasonParametersGenerated, - Status: appv1.ApplicationSetConditionStatusTrue, + Reason: argov1alpha1.ApplicationSetReasonParametersGenerated, + Status: argov1alpha1.ApplicationSetConditionStatusTrue, } } else { - paramtersGeneratedCondition = appv1.ApplicationSetCondition{ - Type: appv1.ApplicationSetConditionParametersGenerated, + paramtersGeneratedCondition = argov1alpha1.ApplicationSetCondition{ + Type: argov1alpha1.ApplicationSetConditionParametersGenerated, Message: message, - Reason: appv1.ApplicationSetReasonErrorOccurred, - Status: appv1.ApplicationSetConditionStatusFalse, + Reason: argov1alpha1.ApplicationSetReasonErrorOccurred, + Status: argov1alpha1.ApplicationSetConditionStatusFalse, } } return paramtersGeneratedCondition } -func getResourceUpToDateCondition(errorOccurred bool, message string, reason string) appv1.ApplicationSetCondition { - var resourceUpToDateCondition appv1.ApplicationSetCondition +func getResourceUpToDateCondition(errorOccurred bool, message string, reason string) argov1alpha1.ApplicationSetCondition { + var resourceUpToDateCondition argov1alpha1.ApplicationSetCondition if errorOccurred { - resourceUpToDateCondition = appv1.ApplicationSetCondition{ - Type: appv1.ApplicationSetConditionResourcesUpToDate, + resourceUpToDateCondition = argov1alpha1.ApplicationSetCondition{ + Type: argov1alpha1.ApplicationSetConditionResourcesUpToDate, Message: message, Reason: reason, - Status: appv1.ApplicationSetConditionStatusFalse, + Status: argov1alpha1.ApplicationSetConditionStatusFalse, } } else { - resourceUpToDateCondition = appv1.ApplicationSetCondition{ - Type: appv1.ApplicationSetConditionResourcesUpToDate, + resourceUpToDateCondition = argov1alpha1.ApplicationSetCondition{ + Type: argov1alpha1.ApplicationSetConditionResourcesUpToDate, Message: "ApplicationSet up to date", - Reason: appv1.ApplicationSetReasonApplicationSetUpToDate, - Status: appv1.ApplicationSetConditionStatusTrue, + Reason: argov1alpha1.ApplicationSetReasonApplicationSetUpToDate, + Status: argov1alpha1.ApplicationSetConditionStatusTrue, } } return resourceUpToDateCondition } -func (r *ApplicationSetReconciler) setApplicationSetStatusCondition(ctx context.Context, applicationSet *appv1.ApplicationSet, condition appv1.ApplicationSetCondition, paramtersGenerated bool) error { +func (r *ApplicationSetReconciler) setApplicationSetStatusCondition(ctx context.Context, applicationSet *argov1alpha1.ApplicationSet, condition argov1alpha1.ApplicationSetCondition, paramtersGenerated bool) error { // check if error occurred during reconcile process - errOccurred := condition.Type == appv1.ApplicationSetConditionErrorOccurred + errOccurred := condition.Type == argov1alpha1.ApplicationSetConditionErrorOccurred - var errOccurredCondition appv1.ApplicationSetCondition + var errOccurredCondition argov1alpha1.ApplicationSetCondition if errOccurred { errOccurredCondition = condition } else { - errOccurredCondition = appv1.ApplicationSetCondition{ - Type: appv1.ApplicationSetConditionErrorOccurred, + errOccurredCondition = argov1alpha1.ApplicationSetCondition{ + Type: argov1alpha1.ApplicationSetConditionErrorOccurred, Message: "Successfully generated parameters for all Applications", - Reason: appv1.ApplicationSetReasonApplicationSetUpToDate, - Status: appv1.ApplicationSetConditionStatusFalse, + Reason: argov1alpha1.ApplicationSetReasonApplicationSetUpToDate, + Status: argov1alpha1.ApplicationSetConditionStatusFalse, } } paramtersGeneratedCondition := getParametersGeneratedCondition(paramtersGenerated, condition.Message) resourceUpToDateCondition := getResourceUpToDateCondition(errOccurred, condition.Message, condition.Reason) - newConditions := []appv1.ApplicationSetCondition{errOccurredCondition, paramtersGeneratedCondition, resourceUpToDateCondition} + newConditions := []argov1alpha1.ApplicationSetCondition{errOccurredCondition, paramtersGeneratedCondition, resourceUpToDateCondition} needToUpdateConditions := false for _, condition := range newConditions { @@ -407,10 +407,10 @@ func (r *ApplicationSetReconciler) setApplicationSetStatusCondition(ctx context. } } } - evaluatedTypes := map[appv1.ApplicationSetConditionType]bool{ - appv1.ApplicationSetConditionErrorOccurred: true, - appv1.ApplicationSetConditionParametersGenerated: true, - appv1.ApplicationSetConditionResourcesUpToDate: true, + evaluatedTypes := map[argov1alpha1.ApplicationSetConditionType]bool{ + argov1alpha1.ApplicationSetConditionErrorOccurred: true, + argov1alpha1.ApplicationSetConditionParametersGenerated: true, + argov1alpha1.ApplicationSetConditionResourcesUpToDate: true, } if needToUpdateConditions || len(applicationSet.Status.Conditions) < 3 { @@ -439,7 +439,7 @@ func (r *ApplicationSetReconciler) setApplicationSetStatusCondition(ctx context. // validateGeneratedApplications uses the Argo CD validation functions to verify the correctness of the // generated applications. -func (r *ApplicationSetReconciler) validateGeneratedApplications(ctx context.Context, desiredApplications []appv1.Application, applicationSetInfo appv1.ApplicationSet) (map[int]error, error) { +func (r *ApplicationSetReconciler) validateGeneratedApplications(ctx context.Context, desiredApplications []argov1alpha1.Application, applicationSetInfo argov1alpha1.ApplicationSet) (map[int]error, error) { errorsByIndex := map[int]error{} namesSet := map[string]bool{} for i, app := range desiredApplications { @@ -469,7 +469,7 @@ func (r *ApplicationSetReconciler) validateGeneratedApplications(ctx context.Con return errorsByIndex, nil } -func (r *ApplicationSetReconciler) getMinRequeueAfter(applicationSetInfo *appv1.ApplicationSet) time.Duration { +func (r *ApplicationSetReconciler) getMinRequeueAfter(applicationSetInfo *argov1alpha1.ApplicationSet) time.Duration { var res time.Duration for _, requestedGenerator := range applicationSetInfo.Spec.Generators { @@ -489,8 +489,8 @@ func (r *ApplicationSetReconciler) getMinRequeueAfter(applicationSetInfo *appv1. return res } -func getTempApplication(applicationSetTemplate appv1.ApplicationSetTemplate) *appv1.Application { - var tmplApplication appv1.Application +func getTempApplication(applicationSetTemplate argov1alpha1.ApplicationSetTemplate) *argov1alpha1.Application { + var tmplApplication argov1alpha1.Application tmplApplication.Annotations = applicationSetTemplate.Annotations tmplApplication.Labels = applicationSetTemplate.Labels tmplApplication.Namespace = applicationSetTemplate.Namespace @@ -501,11 +501,11 @@ func getTempApplication(applicationSetTemplate appv1.ApplicationSetTemplate) *ap return &tmplApplication } -func (r *ApplicationSetReconciler) generateApplications(logCtx *log.Entry, applicationSetInfo appv1.ApplicationSet) ([]appv1.Application, appv1.ApplicationSetReasonType, error) { - var res []appv1.Application +func (r *ApplicationSetReconciler) generateApplications(logCtx *log.Entry, applicationSetInfo argov1alpha1.ApplicationSet) ([]argov1alpha1.Application, argov1alpha1.ApplicationSetReasonType, error) { + var res []argov1alpha1.Application var firstError error - var applicationSetReason appv1.ApplicationSetReasonType + var applicationSetReason argov1alpha1.ApplicationSetReasonType for _, requestedGenerator := range applicationSetInfo.Spec.Generators { t, err := generators.Transform(requestedGenerator, r.Generators, applicationSetInfo.Spec.Template, &applicationSetInfo, map[string]interface{}{}) @@ -514,7 +514,7 @@ func (r *ApplicationSetReconciler) generateApplications(logCtx *log.Entry, appli Error("error generating application from params") if firstError == nil { firstError = err - applicationSetReason = appv1.ApplicationSetReasonApplicationParamsGenerationError + applicationSetReason = argov1alpha1.ApplicationSetReasonApplicationParamsGenerationError } continue } @@ -531,7 +531,7 @@ func (r *ApplicationSetReconciler) generateApplications(logCtx *log.Entry, appli if firstError == nil { firstError = err - applicationSetReason = appv1.ApplicationSetReasonRenderTemplateParamsError + applicationSetReason = argov1alpha1.ApplicationSetReasonRenderTemplateParamsError } continue } @@ -545,7 +545,7 @@ func (r *ApplicationSetReconciler) generateApplications(logCtx *log.Entry, appli if firstError == nil { firstError = err - applicationSetReason = appv1.ApplicationSetReasonRenderTemplateParamsError + applicationSetReason = argov1alpha1.ApplicationSetReasonRenderTemplateParamsError } continue } @@ -564,7 +564,7 @@ func (r *ApplicationSetReconciler) generateApplications(logCtx *log.Entry, appli return res, applicationSetReason, firstError } -func (r *ApplicationSetReconciler) applyTemplatePatch(app *appv1.Application, applicationSetInfo appv1.ApplicationSet, params map[string]interface{}) (*appv1.Application, error) { +func (r *ApplicationSetReconciler) applyTemplatePatch(app *argov1alpha1.Application, applicationSetInfo argov1alpha1.ApplicationSet, params map[string]interface{}) (*argov1alpha1.Application, error) { replacedTemplate, err := r.Renderer.Replace(*applicationSetInfo.Spec.TemplatePatch, params, applicationSetInfo.Spec.GoTemplate, applicationSetInfo.Spec.GoTemplateOptions) if err != nil { @@ -584,13 +584,13 @@ func ignoreNotAllowedNamespaces(namespaces []string) predicate.Predicate { func appControllerIndexer(rawObj client.Object) []string { // grab the job object, extract the owner... - app := rawObj.(*appv1.Application) + app := rawObj.(*argov1alpha1.Application) owner := metav1.GetControllerOf(app) if owner == nil { return nil } // ...make sure it's a application set... - if owner.APIVersion != appv1.SchemeGroupVersion.String() || owner.Kind != "ApplicationSet" { + if owner.APIVersion != argov1alpha1.SchemeGroupVersion.String() || owner.Kind != "ApplicationSet" { return nil } @@ -599,7 +599,7 @@ func appControllerIndexer(rawObj client.Object) []string { } func (r *ApplicationSetReconciler) SetupWithManager(mgr ctrl.Manager, enableProgressiveSyncs bool, maxConcurrentReconciliations int) error { - if err := mgr.GetFieldIndexer().IndexField(context.TODO(), &appv1.Application{}, ".metadata.controller", appControllerIndexer); err != nil { + if err := mgr.GetFieldIndexer().IndexField(context.TODO(), &argov1alpha1.Application{}, ".metadata.controller", appControllerIndexer); err != nil { return fmt.Errorf("error setting up with manager: %w", err) } @@ -607,8 +607,8 @@ func (r *ApplicationSetReconciler) SetupWithManager(mgr ctrl.Manager, enableProg return ctrl.NewControllerManagedBy(mgr).WithOptions(controller.Options{ MaxConcurrentReconciles: maxConcurrentReconciliations, - }).For(&appv1.ApplicationSet{}). - Owns(&appv1.Application{}, builder.WithPredicates(ownsHandler)). + }).For(&argov1alpha1.ApplicationSet{}). + Owns(&argov1alpha1.Application{}, builder.WithPredicates(ownsHandler)). WithEventFilter(ignoreNotAllowedNamespaces(r.ApplicationSetNamespaces)). Watches( &source.Kind{Type: &corev1.Secret{}}, @@ -643,7 +643,7 @@ func (r *ApplicationSetReconciler) updateCache(ctx context.Context, obj client.O // - For new applications, it will call create // - For existing application, it will call update // The function also adds owner reference to all applications, and uses it to delete them. -func (r *ApplicationSetReconciler) createOrUpdateInCluster(ctx context.Context, logCtx *log.Entry, applicationSet appv1.ApplicationSet, desiredApplications []appv1.Application) error { +func (r *ApplicationSetReconciler) createOrUpdateInCluster(ctx context.Context, logCtx *log.Entry, applicationSet argov1alpha1.ApplicationSet, desiredApplications []argov1alpha1.Application) error { var firstError error // Creates or updates the application in appList @@ -655,7 +655,7 @@ func (r *ApplicationSetReconciler) createOrUpdateInCluster(ctx context.Context, // Normalize to avoid fighting with the application controller. generatedApp.Spec = *argoutil.NormalizeApplicationSpec(&generatedApp.Spec) - found := &appv1.Application{ + found := &argov1alpha1.Application{ ObjectMeta: metav1.ObjectMeta{ Name: generatedApp.Name, Namespace: generatedApp.Namespace, @@ -746,9 +746,9 @@ func (r *ApplicationSetReconciler) createOrUpdateInCluster(ctx context.Context, // createInCluster will filter from the desiredApplications only the application that needs to be created // Then it will call createOrUpdateInCluster to do the actual create -func (r *ApplicationSetReconciler) createInCluster(ctx context.Context, logCtx *log.Entry, applicationSet appv1.ApplicationSet, desiredApplications []appv1.Application) error { +func (r *ApplicationSetReconciler) createInCluster(ctx context.Context, logCtx *log.Entry, applicationSet argov1alpha1.ApplicationSet, desiredApplications []argov1alpha1.Application) error { - var createApps []appv1.Application + var createApps []argov1alpha1.Application current, err := r.getCurrentApplications(ctx, applicationSet) if err != nil { return fmt.Errorf("error getting current applications: %w", err) @@ -772,8 +772,8 @@ func (r *ApplicationSetReconciler) createInCluster(ctx context.Context, logCtx * return r.createOrUpdateInCluster(ctx, logCtx, applicationSet, createApps) } -func (r *ApplicationSetReconciler) getCurrentApplications(ctx context.Context, applicationSet appv1.ApplicationSet) ([]appv1.Application, error) { - var current appv1.ApplicationList +func (r *ApplicationSetReconciler) getCurrentApplications(ctx context.Context, applicationSet argov1alpha1.ApplicationSet) ([]argov1alpha1.Application, error) { + var current argov1alpha1.ApplicationList err := r.Client.List(ctx, ¤t, client.MatchingFields{".metadata.controller": applicationSet.Name}, client.InNamespace(applicationSet.Namespace)) if err != nil { @@ -785,7 +785,7 @@ func (r *ApplicationSetReconciler) getCurrentApplications(ctx context.Context, a // deleteInCluster will delete Applications that are currently on the cluster, but not in appList. // The function must be called after all generators had been called and generated applications -func (r *ApplicationSetReconciler) deleteInCluster(ctx context.Context, logCtx *log.Entry, applicationSet appv1.ApplicationSet, desiredApplications []appv1.Application) error { +func (r *ApplicationSetReconciler) deleteInCluster(ctx context.Context, logCtx *log.Entry, applicationSet argov1alpha1.ApplicationSet, desiredApplications []argov1alpha1.Application) error { // settingsMgr := settings.NewSettingsManager(context.TODO(), r.KubeClientset, applicationSet.Namespace) // argoDB := db.NewDB(applicationSet.Namespace, settingsMgr, r.KubeClientset) // clusterList, err := argoDB.ListClusters(ctx) @@ -840,7 +840,7 @@ func (r *ApplicationSetReconciler) deleteInCluster(ctx context.Context, logCtx * } // removeFinalizerOnInvalidDestination removes the Argo CD resources finalizer if the application contains an invalid target (eg missing cluster) -func (r *ApplicationSetReconciler) removeFinalizerOnInvalidDestination(ctx context.Context, applicationSet appv1.ApplicationSet, app *appv1.Application, clusterList *appv1.ClusterList, appLog *log.Entry) error { +func (r *ApplicationSetReconciler) removeFinalizerOnInvalidDestination(ctx context.Context, applicationSet argov1alpha1.ApplicationSet, app *argov1alpha1.Application, clusterList *argov1alpha1.ClusterList, appLog *log.Entry) error { // Only check if the finalizers need to be removed IF there are finalizers to remove if len(app.Finalizers) == 0 { @@ -887,7 +887,7 @@ func (r *ApplicationSetReconciler) removeFinalizerOnInvalidDestination(ctx conte // Filter out the Argo CD finalizer from the finalizer list var newFinalizers []string for _, existingFinalizer := range app.Finalizers { - if existingFinalizer != appv1.ResourcesFinalizerName { // only remove this one + if existingFinalizer != argov1alpha1.ResourcesFinalizerName { // only remove this one newFinalizers = append(newFinalizers, existingFinalizer) } } @@ -915,7 +915,7 @@ func (r *ApplicationSetReconciler) removeFinalizerOnInvalidDestination(ctx conte return nil } -func (r *ApplicationSetReconciler) removeOwnerReferencesOnDeleteAppSet(ctx context.Context, applicationSet appv1.ApplicationSet) error { +func (r *ApplicationSetReconciler) removeOwnerReferencesOnDeleteAppSet(ctx context.Context, applicationSet argov1alpha1.ApplicationSet) error { applications, err := r.getCurrentApplications(ctx, applicationSet) if err != nil { return err @@ -932,7 +932,7 @@ func (r *ApplicationSetReconciler) removeOwnerReferencesOnDeleteAppSet(ctx conte return nil } -func (r *ApplicationSetReconciler) performProgressiveSyncs(ctx context.Context, logCtx *log.Entry, appset appv1.ApplicationSet, applications []appv1.Application, desiredApplications []appv1.Application, appMap map[string]appv1.Application) (map[string]bool, error) { +func (r *ApplicationSetReconciler) performProgressiveSyncs(ctx context.Context, logCtx *log.Entry, appset argov1alpha1.ApplicationSet, applications []argov1alpha1.Application, desiredApplications []argov1alpha1.Application, appMap map[string]argov1alpha1.Application) (map[string]bool, error) { appDependencyList, appStepMap, err := r.buildAppDependencyList(logCtx, appset, desiredApplications) if err != nil { @@ -970,13 +970,13 @@ func (r *ApplicationSetReconciler) performProgressiveSyncs(ctx context.Context, } // this list tracks which Applications belong to each RollingUpdate step -func (r *ApplicationSetReconciler) buildAppDependencyList(logCtx *log.Entry, applicationSet appv1.ApplicationSet, applications []appv1.Application) ([][]string, map[string]int, error) { +func (r *ApplicationSetReconciler) buildAppDependencyList(logCtx *log.Entry, applicationSet argov1alpha1.ApplicationSet, applications []argov1alpha1.Application) ([][]string, map[string]int, error) { if applicationSet.Spec.Strategy == nil || applicationSet.Spec.Strategy.Type == "" || applicationSet.Spec.Strategy.Type == "AllAtOnce" { return [][]string{}, map[string]int{}, nil } - steps := []appv1.ApplicationSetRolloutStep{} + steps := []argov1alpha1.ApplicationSetRolloutStep{} if progressiveSyncsStrategyEnabled(&applicationSet, "RollingSync") { steps = applicationSet.Spec.Strategy.RollingSync.Steps } @@ -1023,7 +1023,7 @@ func (r *ApplicationSetReconciler) buildAppDependencyList(logCtx *log.Entry, app return appDependencyList, appStepMap, nil } -func labelMatchedExpression(logCtx *log.Entry, val string, matchExpression appv1.ApplicationMatchExpression) bool { +func labelMatchedExpression(logCtx *log.Entry, val string, matchExpression argov1alpha1.ApplicationMatchExpression) bool { if matchExpression.Operator != "In" && matchExpression.Operator != "NotIn" { logCtx.Errorf("skipping AppSet rollingUpdate step Application selection, invalid matchExpression operator provided: %q ", matchExpression.Operator) return false @@ -1044,7 +1044,7 @@ func labelMatchedExpression(logCtx *log.Entry, val string, matchExpression appv1 } // this map is used to determine which stage of Applications are ready to be updated in the reconciler loop -func (r *ApplicationSetReconciler) buildAppSyncMap(ctx context.Context, applicationSet appv1.ApplicationSet, appDependencyList [][]string, appMap map[string]appv1.Application) (map[string]bool, error) { +func (r *ApplicationSetReconciler) buildAppSyncMap(ctx context.Context, applicationSet argov1alpha1.ApplicationSet, appDependencyList [][]string, appMap map[string]argov1alpha1.Application) (map[string]bool, error) { appSyncMap := map[string]bool{} syncEnabled := true @@ -1086,7 +1086,7 @@ func (r *ApplicationSetReconciler) buildAppSyncMap(ctx context.Context, applicat return appSyncMap, nil } -func appSyncEnabledForNextStep(appset *appv1.ApplicationSet, app appv1.Application, appStatus appv1.ApplicationSetApplicationStatus) bool { +func appSyncEnabledForNextStep(appset *argov1alpha1.ApplicationSet, app argov1alpha1.Application, appStatus argov1alpha1.ApplicationSetApplicationStatus) bool { if progressiveSyncsStrategyEnabled(appset, "RollingSync") { // we still need to complete the current step if the Application is not yet Healthy or there are still pending Application changes @@ -1096,7 +1096,7 @@ func appSyncEnabledForNextStep(appset *appv1.ApplicationSet, app appv1.Applicati return true } -func progressiveSyncsStrategyEnabled(appset *appv1.ApplicationSet, strategyType string) bool { +func progressiveSyncsStrategyEnabled(appset *argov1alpha1.ApplicationSet, strategyType string) bool { if appset.Spec.Strategy == nil || appset.Spec.Strategy.Type != strategyType { return false } @@ -1108,7 +1108,7 @@ func progressiveSyncsStrategyEnabled(appset *appv1.ApplicationSet, strategyType return true } -func isApplicationHealthy(app appv1.Application) bool { +func isApplicationHealthy(app argov1alpha1.Application) bool { healthStatusString, syncStatusString, operationPhaseString := statusStrings(app) if healthStatusString == "Healthy" && syncStatusString != "OutOfSync" && (operationPhaseString == "Succeeded" || operationPhaseString == "") { @@ -1117,7 +1117,7 @@ func isApplicationHealthy(app appv1.Application) bool { return false } -func statusStrings(app appv1.Application) (string, string, string) { +func statusStrings(app argov1alpha1.Application) (string, string, string) { healthStatusString := string(app.Status.Health.Status) syncStatusString := string(app.Status.Sync.Status) operationPhaseString := "" @@ -1129,10 +1129,10 @@ func statusStrings(app appv1.Application) (string, string, string) { } // check the status of each Application's status and promote Applications to the next status if needed -func (r *ApplicationSetReconciler) updateApplicationSetApplicationStatus(ctx context.Context, logCtx *log.Entry, applicationSet *appv1.ApplicationSet, applications []appv1.Application, appStepMap map[string]int) ([]appv1.ApplicationSetApplicationStatus, error) { +func (r *ApplicationSetReconciler) updateApplicationSetApplicationStatus(ctx context.Context, logCtx *log.Entry, applicationSet *argov1alpha1.ApplicationSet, applications []argov1alpha1.Application, appStepMap map[string]int) ([]argov1alpha1.ApplicationSetApplicationStatus, error) { now := metav1.Now() - appStatuses := make([]appv1.ApplicationSetApplicationStatus, 0, len(applications)) + appStatuses := make([]argov1alpha1.ApplicationSetApplicationStatus, 0, len(applications)) for _, app := range applications { @@ -1140,11 +1140,11 @@ func (r *ApplicationSetReconciler) updateApplicationSetApplicationStatus(ctx con idx := findApplicationStatusIndex(applicationSet.Status.ApplicationStatus, app.Name) - currentAppStatus := appv1.ApplicationSetApplicationStatus{} + currentAppStatus := argov1alpha1.ApplicationSetApplicationStatus{} if idx == -1 { // AppStatus not found, set default status of "Waiting" - currentAppStatus = appv1.ApplicationSetApplicationStatus{ + currentAppStatus = argov1alpha1.ApplicationSetApplicationStatus{ Application: app.Name, LastTransitionTime: &now, Message: "No Application status found, defaulting status to Waiting.", @@ -1218,10 +1218,10 @@ func (r *ApplicationSetReconciler) updateApplicationSetApplicationStatus(ctx con } // check Applications that are in Waiting status and promote them to Pending if needed -func (r *ApplicationSetReconciler) updateApplicationSetApplicationStatusProgress(ctx context.Context, logCtx *log.Entry, applicationSet *appv1.ApplicationSet, appSyncMap map[string]bool, appStepMap map[string]int, appMap map[string]appv1.Application) ([]appv1.ApplicationSetApplicationStatus, error) { +func (r *ApplicationSetReconciler) updateApplicationSetApplicationStatusProgress(ctx context.Context, logCtx *log.Entry, applicationSet *argov1alpha1.ApplicationSet, appSyncMap map[string]bool, appStepMap map[string]int, appMap map[string]argov1alpha1.Application) ([]argov1alpha1.ApplicationSetApplicationStatus, error) { now := metav1.Now() - appStatuses := make([]appv1.ApplicationSetApplicationStatus, 0, len(applicationSet.Status.ApplicationStatus)) + appStatuses := make([]argov1alpha1.ApplicationSetApplicationStatus, 0, len(applicationSet.Status.ApplicationStatus)) // if we have no RollingUpdate steps, clear out the existing ApplicationStatus entries if applicationSet.Spec.Strategy != nil && applicationSet.Spec.Strategy.Type != "" && applicationSet.Spec.Strategy.Type != "AllAtOnce" { @@ -1297,7 +1297,7 @@ func (r *ApplicationSetReconciler) updateApplicationSetApplicationStatusProgress return appStatuses, nil } -func (r *ApplicationSetReconciler) updateApplicationSetApplicationStatusConditions(ctx context.Context, applicationSet *appv1.ApplicationSet) ([]appv1.ApplicationSetCondition, error) { +func (r *ApplicationSetReconciler) updateApplicationSetApplicationStatusConditions(ctx context.Context, applicationSet *argov1alpha1.ApplicationSet) ([]argov1alpha1.ApplicationSetCondition, error) { appSetProgressing := false for _, appStatus := range applicationSet.Status.ApplicationStatus { @@ -1309,7 +1309,7 @@ func (r *ApplicationSetReconciler) updateApplicationSetApplicationStatusConditio appSetConditionProgressing := false for _, appSetCondition := range applicationSet.Status.Conditions { - if appSetCondition.Type == appv1.ApplicationSetConditionRolloutProgressing && appSetCondition.Status == appv1.ApplicationSetConditionStatusTrue { + if appSetCondition.Type == argov1alpha1.ApplicationSetConditionRolloutProgressing && appSetCondition.Status == argov1alpha1.ApplicationSetConditionStatusTrue { appSetConditionProgressing = true break } @@ -1318,21 +1318,21 @@ func (r *ApplicationSetReconciler) updateApplicationSetApplicationStatusConditio if appSetProgressing && !appSetConditionProgressing { _ = r.setApplicationSetStatusCondition(ctx, applicationSet, - appv1.ApplicationSetCondition{ - Type: appv1.ApplicationSetConditionRolloutProgressing, + argov1alpha1.ApplicationSetCondition{ + Type: argov1alpha1.ApplicationSetConditionRolloutProgressing, Message: "ApplicationSet Rollout Rollout started", - Reason: appv1.ApplicationSetReasonApplicationSetModified, - Status: appv1.ApplicationSetConditionStatusTrue, + Reason: argov1alpha1.ApplicationSetReasonApplicationSetModified, + Status: argov1alpha1.ApplicationSetConditionStatusTrue, }, false, ) } else if !appSetProgressing && appSetConditionProgressing { _ = r.setApplicationSetStatusCondition(ctx, applicationSet, - appv1.ApplicationSetCondition{ - Type: appv1.ApplicationSetConditionRolloutProgressing, + argov1alpha1.ApplicationSetCondition{ + Type: argov1alpha1.ApplicationSetConditionRolloutProgressing, Message: "ApplicationSet Rollout Rollout complete", - Reason: appv1.ApplicationSetReasonApplicationSetRolloutComplete, - Status: appv1.ApplicationSetConditionStatusFalse, + Reason: argov1alpha1.ApplicationSetReasonApplicationSetRolloutComplete, + Status: argov1alpha1.ApplicationSetConditionStatusFalse, }, false, ) } @@ -1340,7 +1340,7 @@ func (r *ApplicationSetReconciler) updateApplicationSetApplicationStatusConditio return applicationSet.Status.Conditions, nil } -func findApplicationStatusIndex(appStatuses []appv1.ApplicationSetApplicationStatus, application string) int { +func findApplicationStatusIndex(appStatuses []argov1alpha1.ApplicationSetApplicationStatus, application string) int { for i := range appStatuses { if appStatuses[i].Application == application { return i @@ -1351,7 +1351,7 @@ func findApplicationStatusIndex(appStatuses []appv1.ApplicationSetApplicationSta // setApplicationSetApplicationStatus updates the ApplicatonSet's status field // with any new/changed Application statuses. -func (r *ApplicationSetReconciler) setAppSetApplicationStatus(ctx context.Context, logCtx *log.Entry, applicationSet *appv1.ApplicationSet, applicationStatuses []appv1.ApplicationSetApplicationStatus) error { +func (r *ApplicationSetReconciler) setAppSetApplicationStatus(ctx context.Context, logCtx *log.Entry, applicationSet *argov1alpha1.ApplicationSet, applicationStatuses []argov1alpha1.ApplicationSetApplicationStatus) error { needToUpdateStatus := false if len(applicationStatuses) != len(applicationSet.Status.ApplicationStatus) { @@ -1376,7 +1376,7 @@ func (r *ApplicationSetReconciler) setAppSetApplicationStatus(ctx context.Contex namespacedName := types.NamespacedName{Namespace: applicationSet.Namespace, Name: applicationSet.Name} // rebuild ApplicationStatus from scratch, we don't need any previous status history - applicationSet.Status.ApplicationStatus = []appv1.ApplicationSetApplicationStatus{} + applicationSet.Status.ApplicationStatus = []argov1alpha1.ApplicationSetApplicationStatus{} for i := range applicationStatuses { applicationSet.Status.SetApplicationStatus(applicationStatuses[i]) } @@ -1400,8 +1400,8 @@ func (r *ApplicationSetReconciler) setAppSetApplicationStatus(ctx context.Contex return nil } -func (r *ApplicationSetReconciler) syncValidApplications(logCtx *log.Entry, applicationSet *appv1.ApplicationSet, appSyncMap map[string]bool, appMap map[string]appv1.Application, validApps []appv1.Application) ([]appv1.Application, error) { - rolloutApps := []appv1.Application{} +func (r *ApplicationSetReconciler) syncValidApplications(logCtx *log.Entry, applicationSet *argov1alpha1.ApplicationSet, appSyncMap map[string]bool, appMap map[string]argov1alpha1.Application, validApps []argov1alpha1.Application) ([]argov1alpha1.Application, error) { + rolloutApps := []argov1alpha1.Application{} for i := range validApps { pruneEnabled := false @@ -1429,20 +1429,20 @@ func (r *ApplicationSetReconciler) syncValidApplications(logCtx *log.Entry, appl } // used by the RollingSync Progressive Sync strategy to trigger a sync of a particular Application resource -func syncApplication(application appv1.Application, prune bool) (appv1.Application, error) { +func syncApplication(application argov1alpha1.Application, prune bool) (argov1alpha1.Application, error) { - operation := appv1.Operation{ - InitiatedBy: appv1.OperationInitiator{ + operation := argov1alpha1.Operation{ + InitiatedBy: argov1alpha1.OperationInitiator{ Username: "applicationset-controller", Automated: true, }, - Info: []*appv1.Info{ + Info: []*argov1alpha1.Info{ { Name: "Reason", Value: "ApplicationSet RollingSync triggered a sync of this Application resource.", }, }, - Sync: &appv1.SyncOperation{}, + Sync: &argov1alpha1.SyncOperation{}, } if application.Spec.SyncPolicy != nil { @@ -1466,7 +1466,7 @@ func getOwnsHandlerPredicates(enableProgressiveSyncs bool) predicate.Funcs { // re-reconcile if log.IsLevelEnabled(log.DebugLevel) { var appName string - app, isApp := e.Object.(*appv1.Application) + app, isApp := e.Object.(*argov1alpha1.Application) if isApp { appName = app.QualifiedName() } @@ -1477,7 +1477,7 @@ func getOwnsHandlerPredicates(enableProgressiveSyncs bool) predicate.Funcs { DeleteFunc: func(e event.DeleteEvent) bool { if log.IsLevelEnabled(log.DebugLevel) { var appName string - app, isApp := e.Object.(*appv1.Application) + app, isApp := e.Object.(*argov1alpha1.Application) if isApp { appName = app.QualifiedName() } @@ -1486,13 +1486,13 @@ func getOwnsHandlerPredicates(enableProgressiveSyncs bool) predicate.Funcs { return true }, UpdateFunc: func(e event.UpdateEvent) bool { - appOld, isApp := e.ObjectOld.(*appv1.Application) + appOld, isApp := e.ObjectOld.(*argov1alpha1.Application) if !isApp { return false } logCtx := log.WithField("app", appOld.QualifiedName()) logCtx.Debugln("received update event from owning an application") - appNew, isApp := e.ObjectNew.(*appv1.Application) + appNew, isApp := e.ObjectNew.(*argov1alpha1.Application) if !isApp { return false } @@ -1503,7 +1503,7 @@ func getOwnsHandlerPredicates(enableProgressiveSyncs bool) predicate.Funcs { GenericFunc: func(e event.GenericEvent) bool { if log.IsLevelEnabled(log.DebugLevel) { var appName string - app, isApp := e.Object.(*appv1.Application) + app, isApp := e.Object.(*argov1alpha1.Application) if isApp { appName = app.QualifiedName() } @@ -1520,7 +1520,7 @@ func getOwnsHandlerPredicates(enableProgressiveSyncs bool) predicate.Funcs { // We do not need to re-reconcile if parts of the application change outside the applicationset's control. // An example being, Application.ApplicationStatus.ReconciledAt which gets updated by the application controller. // Additionally, Application.ObjectMeta.ResourceVersion and Application.ObjectMeta.Generation which are set by K8s. -func shouldRequeueApplicationSet(appOld *appv1.Application, appNew *appv1.Application, enableProgressiveSyncs bool) bool { +func shouldRequeueApplicationSet(appOld *argov1alpha1.Application, appNew *argov1alpha1.Application, enableProgressiveSyncs bool) bool { if appOld == nil || appNew == nil { return false }