From ffa6c9439a0d8a26f5e7f4b7311f62d896ba8d46 Mon Sep 17 00:00:00 2001 From: Manabu McCloskey Date: Mon, 17 Jun 2024 18:05:00 +0000 Subject: [PATCH] ensure core package customizations are processed --- api/v1alpha1/localbuild_types.go | 8 +++-- api/v1alpha1/zz_generated.deepcopy.go | 16 ++++----- pkg/build/build.go | 8 ++--- pkg/cmd/create/root.go | 2 +- pkg/controllers/localbuild/argo.go | 7 +++- pkg/controllers/localbuild/controller.go | 18 +++++----- pkg/controllers/localbuild/gitea.go | 7 +++- pkg/controllers/localbuild/installer.go | 2 +- pkg/controllers/localbuild/nginx.go | 7 +++- .../idpbuilder.cnoe.io_localbuilds.yaml | 33 +++++++++---------- 10 files changed, 63 insertions(+), 45 deletions(-) diff --git a/api/v1alpha1/localbuild_types.go b/api/v1alpha1/localbuild_types.go index fe27e6d1..8e8cd67f 100644 --- a/api/v1alpha1/localbuild_types.go +++ b/api/v1alpha1/localbuild_types.go @@ -17,6 +17,10 @@ const ( CLISecretLabelKey = "cnoe.io/cli-secret" CLISecretLabelValue = "true" PackageNameLabelKey = "cnoe.io/package-name" + + ArgoCDPackageName = "argocd" + GiteaPackageName = "gitea" + IngressNginxPackageName = "nginx" ) // ArgoPackageConfigSpec Allows for configuration of the ArgoCD Installation. @@ -30,8 +34,6 @@ type ArgoPackageConfigSpec struct { type EmbeddedArgoApplicationsPackageConfigSpec struct { // Enabled controls whether to install the embedded argo applications and the associated GitServer Enabled bool `json:"enabled,omitempty"` - // +kubebuilder:validation:Optional - PackageCustomization map[string]PackageCustomization `json:"packageCustomization,omitempty"` } type PackageConfigsSpec struct { @@ -39,6 +41,8 @@ type PackageConfigsSpec struct { EmbeddedArgoApplications EmbeddedArgoApplicationsPackageConfigSpec `json:"embeddedArgoApplicationsPackageConfigs,omitempty"` CustomPackageDirs []string `json:"customPackageDirs,omitempty"` CustomPackageUrls []string `json:"customPackageUrls,omitempty"` + // +kubebuilder:validation:Optional + CorePackageCustomization map[string]PackageCustomization `json:"packageCustomization,omitempty"` } type LocalbuildSpec struct { diff --git a/api/v1alpha1/zz_generated.deepcopy.go b/api/v1alpha1/zz_generated.deepcopy.go index 1061d56d..db881cb3 100644 --- a/api/v1alpha1/zz_generated.deepcopy.go +++ b/api/v1alpha1/zz_generated.deepcopy.go @@ -184,13 +184,6 @@ func (in *CustomPackageStatus) DeepCopy() *CustomPackageStatus { // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *EmbeddedArgoApplicationsPackageConfigSpec) DeepCopyInto(out *EmbeddedArgoApplicationsPackageConfigSpec) { *out = *in - if in.PackageCustomization != nil { - in, out := &in.PackageCustomization, &out.PackageCustomization - *out = make(map[string]PackageCustomization, len(*in)) - for key, val := range *in { - (*out)[key] = val - } - } } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new EmbeddedArgoApplicationsPackageConfigSpec. @@ -455,7 +448,7 @@ func (in *ObjectRef) DeepCopy() *ObjectRef { func (in *PackageConfigsSpec) DeepCopyInto(out *PackageConfigsSpec) { *out = *in out.Argo = in.Argo - in.EmbeddedArgoApplications.DeepCopyInto(&out.EmbeddedArgoApplications) + out.EmbeddedArgoApplications = in.EmbeddedArgoApplications if in.CustomPackageDirs != nil { in, out := &in.CustomPackageDirs, &out.CustomPackageDirs *out = make([]string, len(*in)) @@ -466,6 +459,13 @@ func (in *PackageConfigsSpec) DeepCopyInto(out *PackageConfigsSpec) { *out = make([]string, len(*in)) copy(*out, *in) } + if in.CorePackageCustomization != nil { + in, out := &in.CorePackageCustomization, &out.CorePackageCustomization + *out = make(map[string]PackageCustomization, len(*in)) + for key, val := range *in { + (*out)[key] = val + } + } } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new PackageConfigsSpec. diff --git a/pkg/build/build.go b/pkg/build/build.go index 47036f02..4c1e8b6a 100644 --- a/pkg/build/build.go +++ b/pkg/build/build.go @@ -198,11 +198,11 @@ func (b *Build) Run(ctx context.Context, recreateCluster bool) error { Enabled: true, }, EmbeddedArgoApplications: v1alpha1.EmbeddedArgoApplicationsPackageConfigSpec{ - Enabled: true, - PackageCustomization: b.packageCustomization, + Enabled: true, }, - CustomPackageDirs: b.customPackageDirs, - CustomPackageUrls: b.customPackageUrls, + CustomPackageDirs: b.customPackageDirs, + CustomPackageUrls: b.customPackageUrls, + CorePackageCustomization: b.packageCustomization, }, } diff --git a/pkg/cmd/create/root.go b/pkg/cmd/create/root.go index 6408050c..191ab086 100644 --- a/pkg/cmd/create/root.go +++ b/pkg/cmd/create/root.go @@ -192,7 +192,7 @@ func getPackageCustomFile(input string) (v1alpha1.PackageCustomization, error) { return v1alpha1.PackageCustomization{}, err } - corePkgs := map[string]struct{}{"argocd": {}, "gitea": {}, "nginx": {}} + corePkgs := map[string]struct{}{v1alpha1.ArgoCDPackageName: {}, v1alpha1.GiteaPackageName: {}, v1alpha1.IngressNginxPackageName: {}} name := s[0] _, ok := corePkgs[name] if !ok { diff --git a/pkg/controllers/localbuild/argo.go b/pkg/controllers/localbuild/argo.go index b912a772..10e11f0d 100644 --- a/pkg/controllers/localbuild/argo.go +++ b/pkg/controllers/localbuild/argo.go @@ -48,7 +48,12 @@ func (r *LocalbuildReconciler) ReconcileArgo(ctx context.Context, req ctrl.Reque skipReadinessCheck: true, } - if result, err := argocd.Install(ctx, req, resource, r.Client, r.Scheme, r.Config); err != nil { + v, ok := resource.Spec.PackageConfigs.CorePackageCustomization[v1alpha1.ArgoCDPackageName] + if ok { + argocd.customization = v + } + + if result, err := argocd.Install(ctx, resource, r.Client, r.Scheme, r.Config); err != nil { return result, err } diff --git a/pkg/controllers/localbuild/controller.go b/pkg/controllers/localbuild/controller.go index 0a399308..2887fa46 100644 --- a/pkg/controllers/localbuild/controller.go +++ b/pkg/controllers/localbuild/controller.go @@ -103,9 +103,9 @@ func (r *LocalbuildReconciler) installCorePackages(ctx context.Context, req ctrl var wg sync.WaitGroup installers := map[string]subReconciler{ - "nginx": r.ReconcileNginx, - "argocd": r.ReconcileArgo, - "gitea": r.ReconcileGitea, + v1alpha1.IngressNginxPackageName: r.ReconcileNginx, + v1alpha1.ArgoCDPackageName: r.ReconcileArgo, + v1alpha1.GiteaPackageName: r.ReconcileGitea, } logger.V(1).Info("installing core packages") for k, v := range installers { @@ -177,7 +177,7 @@ func (r *LocalbuildReconciler) ReconcileArgoAppsWithGitea(ctx context.Context, r // push bootstrap app manifests to Gitea. let ArgoCD take over // will need a way to filter them based on user input - bootStrapApps := []string{"argocd", "nginx", "gitea"} + bootStrapApps := []string{v1alpha1.ArgoCDPackageName, v1alpha1.IngressNginxPackageName, v1alpha1.GiteaPackageName} for _, n := range bootStrapApps { result, err := r.reconcileEmbeddedApp(ctx, n, resource) if err != nil { @@ -221,7 +221,7 @@ func (r *LocalbuildReconciler) reconcileEmbeddedApp(ctx context.Context, appName app := &argov1alpha1.Application{ ObjectMeta: metav1.ObjectMeta{ Name: appName, - Namespace: "argocd", + Namespace: argocdNamespace, }, } @@ -518,7 +518,7 @@ func (r *LocalbuildReconciler) reconcileGitRepo(ctx context.Context, resource *v } else { repo.Spec.Source.Path = absPath } - f, ok := resource.Spec.PackageConfigs.EmbeddedArgoApplications.PackageCustomization[embeddedName] + f, ok := resource.Spec.PackageConfigs.CorePackageCustomization[embeddedName] if ok { repo.Spec.Customization = v1alpha1.PackageCustomization{ Name: embeddedName, @@ -545,11 +545,11 @@ func isSupportedArgoCDTypes(gvk *schema.GroupVersionKind) bool { func GetEmbeddedRawInstallResources(name string, templateData any, config v1alpha1.PackageCustomization, scheme *runtime.Scheme) ([][]byte, error) { switch name { - case "argocd": + case v1alpha1.ArgoCDPackageName: return RawArgocdInstallResources(templateData, config, scheme) - case "gitea": + case v1alpha1.GiteaPackageName: return RawGiteaInstallResources(templateData, config, scheme) - case "nginx": + case v1alpha1.IngressNginxPackageName: return RawNginxInstallResources(templateData, config, scheme) default: return nil, fmt.Errorf("unsupported embedded app name %s", name) diff --git a/pkg/controllers/localbuild/gitea.go b/pkg/controllers/localbuild/gitea.go index 1ecc6008..9c699244 100644 --- a/pkg/controllers/localbuild/gitea.go +++ b/pkg/controllers/localbuild/gitea.go @@ -82,7 +82,12 @@ func (r *LocalbuildReconciler) ReconcileGitea(ctx context.Context, req ctrl.Requ gitea.unmanagedResources = []client.Object{&giteCreds} - if result, err := gitea.Install(ctx, req, resource, r.Client, r.Scheme, r.Config); err != nil { + v, ok := resource.Spec.PackageConfigs.CorePackageCustomization[v1alpha1.GiteaPackageName] + if ok { + gitea.customization = v + } + + if result, err := gitea.Install(ctx, resource, r.Client, r.Scheme, r.Config); err != nil { return result, err } diff --git a/pkg/controllers/localbuild/installer.go b/pkg/controllers/localbuild/installer.go index 95cbd06b..b5ca402b 100644 --- a/pkg/controllers/localbuild/installer.go +++ b/pkg/controllers/localbuild/installer.go @@ -53,7 +53,7 @@ func (e *EmbeddedInstallation) newNamespace(namespace string) *corev1.Namespace } } -func (e *EmbeddedInstallation) Install(ctx context.Context, req ctrl.Request, resource *v1alpha1.Localbuild, cli client.Client, sc *runtime.Scheme, cfg util.CorePackageTemplateConfig) (ctrl.Result, error) { +func (e *EmbeddedInstallation) Install(ctx context.Context, resource *v1alpha1.Localbuild, cli client.Client, sc *runtime.Scheme, cfg util.CorePackageTemplateConfig) (ctrl.Result, error) { logger := log.FromContext(ctx) nsClient := client.NewNamespacedClient(cli, e.namespace) diff --git a/pkg/controllers/localbuild/nginx.go b/pkg/controllers/localbuild/nginx.go index a8c6d9c3..724ecbc8 100644 --- a/pkg/controllers/localbuild/nginx.go +++ b/pkg/controllers/localbuild/nginx.go @@ -37,7 +37,12 @@ func (r *LocalbuildReconciler) ReconcileNginx(ctx context.Context, req ctrl.Requ }, } - if result, err := nginx.Install(ctx, req, resource, r.Client, r.Scheme, r.Config); err != nil { + v, ok := resource.Spec.PackageConfigs.CorePackageCustomization[v1alpha1.IngressNginxPackageName] + if ok { + nginx.customization = v + } + + if result, err := nginx.Install(ctx, resource, r.Client, r.Scheme, r.Config); err != nil { return result, err } diff --git a/pkg/controllers/resources/idpbuilder.cnoe.io_localbuilds.yaml b/pkg/controllers/resources/idpbuilder.cnoe.io_localbuilds.yaml index b215d3b1..d544f4c2 100644 --- a/pkg/controllers/resources/idpbuilder.cnoe.io_localbuilds.yaml +++ b/pkg/controllers/resources/idpbuilder.cnoe.io_localbuilds.yaml @@ -64,23 +64,22 @@ spec: description: Enabled controls whether to install the embedded argo applications and the associated GitServer type: boolean - packageCustomization: - additionalProperties: - description: PackageCustomization defines how packages are - customized - properties: - filePath: - description: FilePath is the absolute file path to a - YAML file that contains Kubernetes manifests. - type: string - name: - description: Name is the name of the package to be customized. - e.g. argocd - type: string - required: - - name - type: object - type: object + type: object + packageCustomization: + additionalProperties: + description: PackageCustomization defines how packages are customized + properties: + filePath: + description: FilePath is the absolute file path to a YAML + file that contains Kubernetes manifests. + type: string + name: + description: Name is the name of the package to be customized. + e.g. argocd + type: string + required: + - name + type: object type: object type: object type: object