diff --git a/go.mod b/go.mod index a6bf3f9e..6aaf7809 100644 --- a/go.mod +++ b/go.mod @@ -4,7 +4,7 @@ go 1.21.3 require ( code.gitea.io/sdk/gitea v0.16.0 - github.com/cnoe-io/argocd-api v0.0.0-20240529000425-926dd47185f1 + github.com/cnoe-io/argocd-api v0.0.0-20240529230753-bb9d05f9e1d8 github.com/docker/docker v24.0.7+incompatible github.com/go-git/go-billy/v5 v5.5.0 github.com/go-git/go-git/v5 v5.12.0 diff --git a/go.sum b/go.sum index 2a989e11..d6b7f2a2 100644 --- a/go.sum +++ b/go.sum @@ -28,6 +28,8 @@ github.com/cloudflare/circl v1.3.7 h1:qlCDlTPz2n9fu58M0Nh1J/JzcFpfgkFHHX3O35r5vc github.com/cloudflare/circl v1.3.7/go.mod h1:sRTcRWXGLrKw6yIGJ+l7amYJFfAXbZG0kBSc8r4zxgA= github.com/cnoe-io/argocd-api v0.0.0-20240529000425-926dd47185f1 h1:n8GUS1AZnCLUQ77agVjFxmcJ/OoEn481H6U/PRX+3Ic= github.com/cnoe-io/argocd-api v0.0.0-20240529000425-926dd47185f1/go.mod h1:vc5mQ/ctD9dFYbWrYHyOclTdbbYU5p+QoFgJBG21RQQ= +github.com/cnoe-io/argocd-api v0.0.0-20240529230753-bb9d05f9e1d8 h1:BYnQciuk2mQl3rE2B+P3u4Od7PK7PMUxUfRlz3cXIeA= +github.com/cnoe-io/argocd-api v0.0.0-20240529230753-bb9d05f9e1d8/go.mod h1:vc5mQ/ctD9dFYbWrYHyOclTdbbYU5p+QoFgJBG21RQQ= github.com/cpuguy83/go-md2man/v2 v2.0.1/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= github.com/cyphar/filepath-securejoin v0.2.4 h1:Ugdm7cg7i6ZK6x3xDF1oEu1nfkyfH53EtKeQYTC3kyg= diff --git a/pkg/controllers/custompackage/controller.go b/pkg/controllers/custompackage/controller.go index 7213479c..8a4b9847 100644 --- a/pkg/controllers/custompackage/controller.go +++ b/pkg/controllers/custompackage/controller.go @@ -78,12 +78,7 @@ func (r *Reconciler) reconcileCustomPackage(ctx context.Context, resource *v1alp return ctrl.Result{}, fmt.Errorf("reading file %s%s: %w", resource.Spec.ArgoCD.ApplicationFile, resource.Spec.ArgoCD.ApplicationSetFile, err) } - var returnedRawResource []byte - if returnedRawResource, err = util.ApplyTemplate(b, r.Config); err != nil { - return ctrl.Result{}, err - } - - objs, err := k8s.ConvertYamlToObjects(r.Scheme, returnedRawResource) + objs, err := k8s.ConvertYamlToObjects(r.Scheme, b) if err != nil { return ctrl.Result{}, fmt.Errorf("converting yaml to object %w", err) } @@ -161,78 +156,10 @@ func (r *Reconciler) reconcileCustomPackage(ctx context.Context, resource *v1alp default: return ctrl.Result{}, fmt.Errorf("file is not a supported argocd kind %s %s", resource.Spec.ArgoCD.ApplicationFile, resource.Spec.ArgoCD.ApplicationSetFile) } - - //appName := app.GetName() - //if resource.Spec.Replicate { - // appSourcesSynced := false - // repoRefs := make([]v1alpha1.ObjectRef, 0, 1) - // if appSpec.HasMultipleSources() { - // notSyncedRepos := 0 - // for j := range appSpec.Sources { - // s := &appSpec.Sources[j] - // res, repo, sErr := r.reconcileArgoCDSource(ctx, resource, s.RepoURL, appName) - // if sErr != nil { - // return res, sErr - // } - // if repo != nil { - // if repo.Status.InternalGitRepositoryUrl == "" { - // notSyncedRepos += 1 - // } - // s.RepoURL = repo.Status.InternalGitRepositoryUrl - // repoRefs = append(repoRefs, v1alpha1.ObjectRef{ - // Namespace: repo.Namespace, - // Name: repo.Name, - // UID: string(repo.ObjectMeta.UID), - // }) - // } - // } - // appSourcesSynced = notSyncedRepos == 0 - // } else { - // s := appSpec.Source - // res, repo, sErr := r.reconcileArgoCDSource(ctx, resource, s.RepoURL, appName) - // if sErr != nil { - // return res, sErr - // } - // if repo != nil { - // appSourcesSynced = repo.Status.InternalGitRepositoryUrl != "" - // s.RepoURL = repo.Status.InternalGitRepositoryUrl - // repoRefs = append(repoRefs, v1alpha1.ObjectRef{ - // Namespace: repo.Namespace, - // Name: repo.Name, - // UID: string(repo.ObjectMeta.UID), - // }) - // } - // } - // resource.Status.GitRepositoryRefs = repoRefs - // resource.Status.Synced = appSourcesSynced && gitGeneratorsSynced - //} - // - //foundAppObj := argov1alpha1.Application{} - //err = r.Client.Get(ctx, client.ObjectKeyFromObject(app), &foundAppObj) - //if err != nil { - // if errors.IsNotFound(err) { - // err = r.Client.Create(ctx, app) - // if err != nil { - // return ctrl.Result{}, fmt.Errorf("creating %s app CR: %w", appName, err) - // } - // - // return ctrl.Result{RequeueAfter: requeueTime}, nil - // } - // return ctrl.Result{}, fmt.Errorf("getting argocd application object: %w", err) - //} - // - //foundAppObj.Spec = *appSpec - //foundAppObj.ObjectMeta.Annotations = app.GetAnnotations() - //foundAppObj.ObjectMeta.Labels = app.GetLabels() - //err = r.Client.Update(ctx, &foundAppObj) - //if err != nil { - // return ctrl.Result{}, fmt.Errorf("updating argocd application object %s: %w", appName, err) - //} - //return ctrl.Result{RequeueAfter: requeueTime}, nil } func (r *Reconciler) reconcileArgoCDApp(ctx context.Context, resource *v1alpha1.CustomPackage, app *argov1alpha1.Application) (ctrl.Result, error) { - appSourcesSynced := false + appSourcesSynced := true repoRefs := make([]v1alpha1.ObjectRef, 0, 1) if app.Spec.HasMultipleSources() { notSyncedRepos := 0 @@ -298,6 +225,7 @@ func (r *Reconciler) reconcileArgoCDAppSet(ctx context.Context, resource *v1alph app := argov1alpha1.Application{ ObjectMeta: metav1.ObjectMeta{Name: appSet.GetName(), Namespace: appSet.Namespace}, } + app.Spec = appSet.Spec.Template.Spec _, err := r.reconcileArgoCDApp(ctx, resource, &app) if err != nil {