Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ensure core package customizations are processed #307

Merged
merged 1 commit into from
Jun 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions api/v1alpha1/localbuild_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -30,15 +34,15 @@ 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 {
Argo ArgoPackageConfigSpec `json:"argoPackageConfigs,omitempty"`
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 {
Expand Down
16 changes: 8 additions & 8 deletions api/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions pkg/build/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/cmd/create/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
7 changes: 6 additions & 1 deletion pkg/controllers/localbuild/argo.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
18 changes: 9 additions & 9 deletions pkg/controllers/localbuild/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -221,7 +221,7 @@ func (r *LocalbuildReconciler) reconcileEmbeddedApp(ctx context.Context, appName
app := &argov1alpha1.Application{
ObjectMeta: metav1.ObjectMeta{
Name: appName,
Namespace: "argocd",
Namespace: argocdNamespace,
},
}

Expand Down Expand Up @@ -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,
Expand All @@ -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)
Expand Down
7 changes: 6 additions & 1 deletion pkg/controllers/localbuild/gitea.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/controllers/localbuild/installer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
7 changes: 6 additions & 1 deletion pkg/controllers/localbuild/nginx.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
33 changes: 16 additions & 17 deletions pkg/controllers/resources/idpbuilder.cnoe.io_localbuilds.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is the plan to not support helm or kustomize?

file that contains Kubernetes manifests.
type: string
name:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we make this an enum?

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
Expand Down
Loading