From 7a4d7e73d413cc2ca2ca4af0d85d9130e5f4740b Mon Sep 17 00:00:00 2001 From: Marian Steinbach Date: Tue, 13 Aug 2024 14:50:51 +0200 Subject: [PATCH 1/4] Remove flag --default-apps-release --- CHANGELOG.md | 1 + cmd/gitops/add/workload-cluster/flag.go | 8 ++---- cmd/gitops/add/workload-cluster/runner.go | 15 +++++----- .../testdata/expected/create/2-demowc.golden | 1 - .../expected/dry-run/case-2-flawless.golden | 1 - .../creator/testdata/input/demowc.yaml | 1 - .../flux-kustomization/kustomization_test.go | 4 +-- internal/gitops/structure/common/types.go | 1 - .../structure/workload-cluster/cluster.go | 3 +- .../workload-cluster/cluster_test.go | 28 ++++++++----------- .../templates/workload-cluster.yaml.tmpl | 3 -- .../testdata/expected/1-demowc.golden | 1 - .../testdata/expected/2-demowc.golden | 1 - 13 files changed, 24 insertions(+), 44 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9a3c13d9e..ad28c56b5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ and this project's packages adheres to [Semantic Versioning](http://semver.org/s - Use more portable, Bash specific shebang for GitOps pre-commit script template - Schedule cluster upgrades for CAPI clusters. +- `kubectl gs gitops add workload-cluster`: Remove flag `--default-apps-release`. ## [3.1.0] - 2024-07-23 diff --git a/cmd/gitops/add/workload-cluster/flag.go b/cmd/gitops/add/workload-cluster/flag.go index 0456a55a5..115771358 100644 --- a/cmd/gitops/add/workload-cluster/flag.go +++ b/cmd/gitops/add/workload-cluster/flag.go @@ -16,7 +16,6 @@ const ( //CAPx only flagClusterRelease = "cluster-release" flagClusterUserConfig = "cluster-user-config" - flagDefaultAppsRelease = "default-apps-release" flagDefaultAppsUserConfig = "default-apps-user-config" ) @@ -30,7 +29,6 @@ type flag struct { ClusterRelease string ClusterUserConfig string - DefaultAppsRelease string DefaultAppsUserConfig string } @@ -44,7 +42,6 @@ func (f *flag) Init(cmd *cobra.Command) { cmd.Flags().StringVar(&f.ClusterRelease, flagClusterRelease, "", "Cluster app version.") cmd.Flags().StringVar(&f.ClusterUserConfig, flagClusterUserConfig, "", "Cluster app user configuration to patch the base with.") - cmd.Flags().StringVar(&f.DefaultAppsRelease, flagDefaultAppsRelease, "", "Default apps app version.") cmd.Flags().StringVar(&f.DefaultAppsUserConfig, flagDefaultAppsUserConfig, "", "Default apps app user configuration to patch the base with.") } @@ -65,12 +62,11 @@ func (f *flag) Validate() error { return microerror.Maskf(invalidFlagsError, "--%s must not be empty", flagRepositoryName) } - if f.Base != "" && (f.ClusterRelease == "" || f.DefaultAppsRelease == "") { + if f.Base != "" && f.ClusterRelease == "" { return microerror.Maskf( invalidFlagsError, - "both --%s and --%s must not be empty when referencing base", + "--%s must not be empty when referencing base", flagClusterRelease, - flagDefaultAppsRelease, ) } diff --git a/cmd/gitops/add/workload-cluster/runner.go b/cmd/gitops/add/workload-cluster/runner.go index 9701536b0..02b93788b 100644 --- a/cmd/gitops/add/workload-cluster/runner.go +++ b/cmd/gitops/add/workload-cluster/runner.go @@ -44,14 +44,13 @@ func (r *runner) run(ctx context.Context, cmd *cobra.Command, args []string) err var err error config := common.StructureConfig{ - ClusterBase: r.flag.Base, - ClusterRelease: r.flag.ClusterRelease, - DefaultAppsRelease: r.flag.DefaultAppsRelease, - ManagementCluster: r.flag.ManagementCluster, - WorkloadCluster: r.flag.Name, - Organization: r.flag.Organization, - SkipMAPI: r.flag.SkipMAPI, - RepositoryName: r.flag.RepositoryName, + ClusterBase: r.flag.Base, + ClusterRelease: r.flag.ClusterRelease, + ManagementCluster: r.flag.ManagementCluster, + WorkloadCluster: r.flag.Name, + Organization: r.flag.Organization, + SkipMAPI: r.flag.SkipMAPI, + RepositoryName: r.flag.RepositoryName, } if r.flag.ClusterUserConfig != "" { diff --git a/internal/gitops/filesystem/creator/testdata/expected/create/2-demowc.golden b/internal/gitops/filesystem/creator/testdata/expected/create/2-demowc.golden index 029d71787..b3f6801f7 100644 --- a/internal/gitops/filesystem/creator/testdata/expected/create/2-demowc.golden +++ b/internal/gitops/filesystem/creator/testdata/expected/create/2-demowc.golden @@ -11,7 +11,6 @@ spec: cluster_name: "demowc" organization: "demoorg" cluster_release: "0.13.0" - default_apps_release: "0.6.0" prune: false serviceAccountName: automation sourceRef: diff --git a/internal/gitops/filesystem/creator/testdata/expected/dry-run/case-2-flawless.golden b/internal/gitops/filesystem/creator/testdata/expected/dry-run/case-2-flawless.golden index 4bd49b9e8..ce83bf2b5 100644 --- a/internal/gitops/filesystem/creator/testdata/expected/dry-run/case-2-flawless.golden +++ b/internal/gitops/filesystem/creator/testdata/expected/dry-run/case-2-flawless.golden @@ -15,7 +15,6 @@ spec: cluster_name: "demowc" organization: "demoorg" cluster_release: "0.13.0" - default_apps_release: "0.6.0" prune: false serviceAccountName: automation sourceRef: diff --git a/internal/gitops/filesystem/creator/testdata/input/demowc.yaml b/internal/gitops/filesystem/creator/testdata/input/demowc.yaml index 029d71787..b3f6801f7 100644 --- a/internal/gitops/filesystem/creator/testdata/input/demowc.yaml +++ b/internal/gitops/filesystem/creator/testdata/input/demowc.yaml @@ -11,7 +11,6 @@ spec: cluster_name: "demowc" organization: "demoorg" cluster_release: "0.13.0" - default_apps_release: "0.6.0" prune: false serviceAccountName: automation sourceRef: diff --git a/internal/gitops/filesystem/modifier/flux-kustomization/kustomization_test.go b/internal/gitops/filesystem/modifier/flux-kustomization/kustomization_test.go index 728ca3352..4c886ca2f 100644 --- a/internal/gitops/filesystem/modifier/flux-kustomization/kustomization_test.go +++ b/internal/gitops/filesystem/modifier/flux-kustomization/kustomization_test.go @@ -156,7 +156,6 @@ spec: postBuild: substitute: cluster_release: 1.0.0 - default_apps_release: 1.0.0 prune: true serviceAccountName: automation sourceRef: @@ -181,8 +180,7 @@ spec: `), modifier: KustomizationModifier{ PostBuildEnvs: map[string]string{ - "cluster_release": "1.0.0", - "default_apps_release": "1.0.0", + "cluster_release": "1.0.0", }, }, }, diff --git a/internal/gitops/structure/common/types.go b/internal/gitops/structure/common/types.go index ace9ab4c8..fe1d32ee9 100644 --- a/internal/gitops/structure/common/types.go +++ b/internal/gitops/structure/common/types.go @@ -29,7 +29,6 @@ type StructureConfig struct { ClusterBase string ClusterRelease string ClusterUserConfig string - DefaultAppsRelease string DefaultAppsUserConfig string EncryptionKeyPair encryption.KeyPair diff --git a/internal/gitops/structure/workload-cluster/cluster.go b/internal/gitops/structure/workload-cluster/cluster.go index 8ed0e0a66..55ac0677d 100644 --- a/internal/gitops/structure/workload-cluster/cluster.go +++ b/internal/gitops/structure/workload-cluster/cluster.go @@ -133,8 +133,7 @@ func NewWorkloadCluster(config common.StructureConfig) (*creator.CreatorConfig, if config.ClusterBase != "" { fsModifiers[wcFile] = fluxkusmod.KustomizationModifier{ PostBuildEnvs: map[string]string{ - "cluster_release": config.ClusterRelease, - "default_apps_release": config.DefaultAppsRelease, + "cluster_release": config.ClusterRelease, }, } } diff --git a/internal/gitops/structure/workload-cluster/cluster_test.go b/internal/gitops/structure/workload-cluster/cluster_test.go index 57ce28a2a..2568f1b07 100644 --- a/internal/gitops/structure/workload-cluster/cluster_test.go +++ b/internal/gitops/structure/workload-cluster/cluster_test.go @@ -65,14 +65,13 @@ func Test_NewWorkloadCluster(t *testing.T) { { name: "flawless with definition", config: common.StructureConfig{ - ClusterBase: "bases/cluster/capo", - ClusterRelease: "0.13.0", - DefaultAppsRelease: "0.6.0", - ManagementCluster: "demomc", - WorkloadCluster: "demowc", - Organization: "demoorg", - SkipMAPI: true, - RepositoryName: "gitops-demo", + ClusterBase: "bases/cluster/capo", + ClusterRelease: "0.13.0", + ManagementCluster: "demomc", + WorkloadCluster: "demowc", + Organization: "demoorg", + SkipMAPI: true, + RepositoryName: "gitops-demo", }, expectedObjects: []FsObjectExpected{ { @@ -117,12 +116,11 @@ func Test_NewWorkloadCluster(t *testing.T) { ClusterUserConfig: string([]byte(`testKey: testValue topKey: nestedKey: nestedValue`)), - DefaultAppsRelease: "0.6.0", - ManagementCluster: "demomc", - WorkloadCluster: "demowc", - Organization: "demoorg", - SkipMAPI: true, - RepositoryName: "gitops-demo", + ManagementCluster: "demomc", + WorkloadCluster: "demowc", + Organization: "demoorg", + SkipMAPI: true, + RepositoryName: "gitops-demo", }, expectedObjects: []FsObjectExpected{ { @@ -175,7 +173,6 @@ topKey: ClusterUserConfig: string([]byte(`testKey: testValue topKey: nestedKey: nestedValue`)), - DefaultAppsRelease: "0.6.0", DefaultAppsUserConfig: string([]byte(`testKey: testValue otherTopKey: nestedOtherKey: nestedOtherValue`)), @@ -244,7 +241,6 @@ otherTopKey: ClusterUserConfig: string([]byte(`testKey: testValue topKey: nestedKey: nestedValue`)), - DefaultAppsRelease: "0.6.0", DefaultAppsUserConfig: string([]byte(`testKey: testValue otherTopKey: nestedOtherKey: nestedOtherValue`)), diff --git a/internal/gitops/structure/workload-cluster/templates/workload-cluster.yaml.tmpl b/internal/gitops/structure/workload-cluster/templates/workload-cluster.yaml.tmpl index 7aedfd40e..52f424615 100644 --- a/internal/gitops/structure/workload-cluster/templates/workload-cluster.yaml.tmpl +++ b/internal/gitops/structure/workload-cluster/templates/workload-cluster.yaml.tmpl @@ -16,9 +16,6 @@ spec: {{- if .ClusterRelease }} cluster_release: {{ .ClusterRelease }} {{- end }} - {{- if .DefaultAppsRelease }} - default_apps_release: {{ .DefaultAppsRelease }} - {{- end }} organization: {{ .Organization }} prune: false serviceAccountName: automation diff --git a/internal/gitops/structure/workload-cluster/testdata/expected/1-demowc.golden b/internal/gitops/structure/workload-cluster/testdata/expected/1-demowc.golden index f5329df30..1be4f0978 100644 --- a/internal/gitops/structure/workload-cluster/testdata/expected/1-demowc.golden +++ b/internal/gitops/structure/workload-cluster/testdata/expected/1-demowc.golden @@ -10,7 +10,6 @@ spec: substitute: cluster_name: demowc cluster_release: 0.13.0 - default_apps_release: 0.6.0 organization: demoorg prune: false serviceAccountName: automation diff --git a/internal/gitops/structure/workload-cluster/testdata/expected/2-demowc.golden b/internal/gitops/structure/workload-cluster/testdata/expected/2-demowc.golden index 736b9e943..ba679bd65 100644 --- a/internal/gitops/structure/workload-cluster/testdata/expected/2-demowc.golden +++ b/internal/gitops/structure/workload-cluster/testdata/expected/2-demowc.golden @@ -10,7 +10,6 @@ spec: substitute: cluster_name: demowc cluster_release: 0.13.0 - default_apps_release: 0.6.0 organization: demoorg prune: false serviceAccountName: automation From 5429de9d0a49b73b9bfbaee533094cae2e77460d Mon Sep 17 00:00:00 2001 From: Marian Steinbach Date: Tue, 13 Aug 2024 15:25:50 +0200 Subject: [PATCH 2/4] Remove unused code and adapt tests --- cmd/gitops/add/base/runner.go | 111 ------------------ cmd/gitops/add/workload-cluster/command.go | 15 +-- cmd/gitops/add/workload-cluster/flag.go | 13 +- cmd/gitops/add/workload-cluster/runner.go | 11 -- internal/gitops/structure/base/base_test.go | 14 +-- .../base/templates/default_apps.yaml.tmpl | 1 - .../templates/default_apps_config.yaml.tmpl | 1 - .../base/templates/kustomization.yaml.tmpl | 5 - .../structure/base/templates/template.go | 8 -- .../expected/0-capa-kustomization.golden | 5 - internal/gitops/structure/common/types.go | 10 +- .../workload-cluster/cluster_test.go | 22 ---- .../default_apps_userconfig.yaml.tmpl | 10 -- .../templates/kustomization.yaml.tmpl | 8 +- .../patch_default_apps_userconfig.yaml.tmpl | 12 -- .../workload-cluster/templates/template.go | 8 -- .../testdata/expected/2-kustomization.golden | 2 - .../testdata/expected/3-kustomization.golden | 2 - 18 files changed, 16 insertions(+), 242 deletions(-) delete mode 100644 internal/gitops/structure/base/templates/default_apps.yaml.tmpl delete mode 100644 internal/gitops/structure/base/templates/default_apps_config.yaml.tmpl delete mode 100644 internal/gitops/structure/workload-cluster/templates/default_apps_userconfig.yaml.tmpl delete mode 100644 internal/gitops/structure/workload-cluster/templates/patch_default_apps_userconfig.yaml.tmpl diff --git a/cmd/gitops/add/base/runner.go b/cmd/gitops/add/base/runner.go index 73e9667b5..bea78a5e3 100644 --- a/cmd/gitops/add/base/runner.go +++ b/cmd/gitops/add/base/runner.go @@ -5,8 +5,6 @@ import ( "io" "strconv" - k8smetadata "github.com/giantswarm/k8smetadata/pkg/label" - templateapp "github.com/giantswarm/kubectl-gs/v4/pkg/template/app" clustercommon "github.com/giantswarm/kubectl-gs/v4/cmd/template/cluster/common" @@ -129,30 +127,6 @@ func generateClusterAppCrTemplate(appName string) (string, error) { return string(template), nil } -func generateDefaultAppsAppCrTemplate(appName string) (string, error) { - template, err := templateapp.NewAppCR(templateapp.Config{ - Name: appName, - AppName: "${cluster_name}-default-apps", - Cluster: "${cluster_name}", - Catalog: "cluster", - DefaultingEnabled: false, - InCluster: true, - Namespace: "org-${organization}", - Version: "${default_apps_release}", - UserConfigConfigMapName: "${cluster_name}-default-apps-config", - UseClusterValuesConfig: true, - ExtraLabels: map[string]string{ - k8smetadata.ManagedBy: "cluster", - }, - }) - - if err != nil { - return "", err - } - - return string(template), nil -} - func generateCapAClusterBaseTemplates(structureConfig common.StructureConfig) (common.ClusterBaseTemplates, error) { clusterBaseTemplates := common.ClusterBaseTemplates{} @@ -177,25 +151,8 @@ func generateCapAClusterBaseTemplates(structureConfig common.StructureConfig) (c return clusterBaseTemplates, err } - defaultAppsAppCr, err := generateDefaultAppsAppCrTemplate("default-apps-aws") - - if err != nil { - return clusterBaseTemplates, err - } - - defaultAppsValues, err := capa.GenerateDefaultAppsValues(capa.DefaultAppsConfig{ - ClusterName: "${cluster_name}", - Organization: "${organization}", - }) - - if err != nil { - return clusterBaseTemplates, err - } - clusterBaseTemplates.ClusterAppCr = clusterAppCr clusterBaseTemplates.ClusterValues = clusterValues - clusterBaseTemplates.DefaultAppsAppCr = defaultAppsAppCr - clusterBaseTemplates.DefaultAppsValues = defaultAppsValues return clusterBaseTemplates, nil } @@ -224,25 +181,8 @@ func generateCapGClusterBaseTemplates(structureConfig common.StructureConfig) (c return clusterBaseTemplates, err } - defaultAppsAppCr, err := generateDefaultAppsAppCrTemplate("default-apps-gcp") - - if err != nil { - return clusterBaseTemplates, err - } - - defaultAppsValues, err := capg.GenerateDefaultAppsValues(capg.DefaultAppsConfig{ - ClusterName: "${cluster_name}", - Organization: "${organization}", - }) - - if err != nil { - return clusterBaseTemplates, err - } - clusterBaseTemplates.ClusterAppCr = clusterAppCr clusterBaseTemplates.ClusterValues = clusterValues - clusterBaseTemplates.DefaultAppsAppCr = defaultAppsAppCr - clusterBaseTemplates.DefaultAppsValues = defaultAppsValues return clusterBaseTemplates, nil } @@ -266,25 +206,8 @@ func generateCapOClusterBaseTemplates(structureConfig common.StructureConfig) (c return clusterBaseTemplates, err } - defaultAppsAppCr, err := generateDefaultAppsAppCrTemplate("default-apps-openstack") - - if err != nil { - return clusterBaseTemplates, err - } - - defaultAppsValues, err := openstack.GenerateDefaultAppsValues(openstack.DefaultAppsConfig{ - ClusterName: "${cluster_name}", - Organization: "${organization}", - }) - - if err != nil { - return clusterBaseTemplates, err - } - clusterBaseTemplates.ClusterAppCr = clusterAppCr clusterBaseTemplates.ClusterValues = clusterValues - clusterBaseTemplates.DefaultAppsAppCr = defaultAppsAppCr - clusterBaseTemplates.DefaultAppsValues = defaultAppsValues return clusterBaseTemplates, nil } @@ -308,25 +231,8 @@ func generateCapVClusterBaseTemplates(structureConfig common.StructureConfig) (c return clusterBaseTemplates, err } - defaultAppsAppCr, err := generateDefaultAppsAppCrTemplate("default-apps-vsphere") - - if err != nil { - return clusterBaseTemplates, err - } - - defaultAppsValues, err := capv.GenerateDefaultAppsValues(capv.DefaultAppsConfig{ - ClusterName: "${cluster_name}", - Organization: "${organization}", - }) - - if err != nil { - return clusterBaseTemplates, err - } - clusterBaseTemplates.ClusterAppCr = clusterAppCr clusterBaseTemplates.ClusterValues = clusterValues - clusterBaseTemplates.DefaultAppsAppCr = defaultAppsAppCr - clusterBaseTemplates.DefaultAppsValues = defaultAppsValues return clusterBaseTemplates, nil } @@ -354,25 +260,8 @@ func generateCapZClusterBaseTemplates(structureConfig common.StructureConfig) (c return clusterBaseTemplates, err } - defaultAppsAppCr, err := generateDefaultAppsAppCrTemplate("default-apps-azure") - - if err != nil { - return clusterBaseTemplates, err - } - - defaultAppsValues, err := capz.GenerateDefaultAppsValues(capz.DefaultAppsConfig{ - ClusterName: "${cluster_name}", - Organization: "${organization}", - }) - - if err != nil { - return clusterBaseTemplates, err - } - clusterBaseTemplates.ClusterAppCr = clusterAppCr clusterBaseTemplates.ClusterValues = clusterValues - clusterBaseTemplates.DefaultAppsAppCr = defaultAppsAppCr - clusterBaseTemplates.DefaultAppsValues = defaultAppsValues return clusterBaseTemplates, nil } diff --git a/cmd/gitops/add/workload-cluster/command.go b/cmd/gitops/add/workload-cluster/command.go index eb7e62d9f..86949e455 100644 --- a/cmd/gitops/add/workload-cluster/command.go +++ b/cmd/gitops/add/workload-cluster/command.go @@ -14,15 +14,13 @@ const ( name = "workload-cluster" alias = "wc" - shortDescription = "Adds a new Workload Cluster to your GitOps directory structure" - longDescription = `Adds a new Workload Cluster to your GitOps directory structure. + shortDescription = "Adds a new workload cluster to your GitOps directory structure" + longDescription = `Adds a new workload cluster to your GitOps directory structure. workload-cluster \ -[--base ] \ [--cluster-release ] \ [--cluster-user-config ] \ -[--default-apps-release ] \ -[--default-apps-user-config ] \ --name \ --management-cluster \ --organization \ @@ -48,8 +46,7 @@ https://github.com/giantswarm/gitops-template/blob/main/docs/add_wc.md` --organization myorg \ --repository-name gitops-demo \ --base bases/clusters/openstack \ - --cluster-release 0.13.0 \ - --default-apps-release 0.6.0 + --cluster-release 0.13.0 # Add dummy Workload Cluster structure with definition from base and extra configuration kubectl gs gitops add wc \ @@ -59,9 +56,7 @@ https://github.com/giantswarm/gitops-template/blob/main/docs/add_wc.md` --repository-name gitops-demo \ --base bases/clusters/openstack \ --cluster-release 0.13.0 \ - --default-apps-release 0.6.0 \ - --cluster-user-config /tmp/cluster_user_config.yaml \ - --default-apps-user-config /tmp/default_apps_user_config.yaml` + --cluster-user-config /tmp/cluster_user_config.yaml` ) type Config struct { diff --git a/cmd/gitops/add/workload-cluster/flag.go b/cmd/gitops/add/workload-cluster/flag.go index 115771358..db084f91a 100644 --- a/cmd/gitops/add/workload-cluster/flag.go +++ b/cmd/gitops/add/workload-cluster/flag.go @@ -13,10 +13,9 @@ const ( flagSkipMAPI = "skip-mapi" flagRepositoryName = "repository-name" - //CAPx only - flagClusterRelease = "cluster-release" - flagClusterUserConfig = "cluster-user-config" - flagDefaultAppsUserConfig = "default-apps-user-config" + // CAPI only + flagClusterRelease = "cluster-release" + flagClusterUserConfig = "cluster-user-config" ) type flag struct { @@ -27,9 +26,8 @@ type flag struct { SkipMAPI bool RepositoryName string - ClusterRelease string - ClusterUserConfig string - DefaultAppsUserConfig string + ClusterRelease string + ClusterUserConfig string } func (f *flag) Init(cmd *cobra.Command) { @@ -42,7 +40,6 @@ func (f *flag) Init(cmd *cobra.Command) { cmd.Flags().StringVar(&f.ClusterRelease, flagClusterRelease, "", "Cluster app version.") cmd.Flags().StringVar(&f.ClusterUserConfig, flagClusterUserConfig, "", "Cluster app user configuration to patch the base with.") - cmd.Flags().StringVar(&f.DefaultAppsUserConfig, flagDefaultAppsUserConfig, "", "Default apps app user configuration to patch the base with.") } func (f *flag) Validate() error { diff --git a/cmd/gitops/add/workload-cluster/runner.go b/cmd/gitops/add/workload-cluster/runner.go index 02b93788b..c0a9d2742 100644 --- a/cmd/gitops/add/workload-cluster/runner.go +++ b/cmd/gitops/add/workload-cluster/runner.go @@ -64,17 +64,6 @@ func (r *runner) run(ctx context.Context, cmd *cobra.Command, args []string) err config.ClusterUserConfig = strings.TrimSpace(config.ClusterUserConfig) } - if r.flag.DefaultAppsUserConfig != "" { - config.DefaultAppsUserConfig, err = commonkey.ReadConfigMapYamlFromFile( - afero.NewOsFs(), - r.flag.DefaultAppsUserConfig, - ) - if err != nil { - return microerror.Mask(err) - } - - config.DefaultAppsUserConfig = strings.TrimSpace(config.DefaultAppsUserConfig) - } creatorConfig, err := structure.NewWorkloadCluster(config) if err != nil { diff --git a/internal/gitops/structure/base/base_test.go b/internal/gitops/structure/base/base_test.go index 234b472de..77768e787 100644 --- a/internal/gitops/structure/base/base_test.go +++ b/internal/gitops/structure/base/base_test.go @@ -27,10 +27,8 @@ func Test_NewManagementCluster(t *testing.T) { config: common.StructureConfig{ Provider: "capa", ClusterBaseTemplates: common.ClusterBaseTemplates{ - ClusterAppCr: "foo:bar", - ClusterValues: "foo:bar", - DefaultAppsAppCr: "foo:bar", - DefaultAppsValues: "foo:bar", + ClusterAppCr: "foo:bar", + ClusterValues: "foo:bar", }, }, expectedObjects: []FsObjectExpected{ @@ -58,14 +56,6 @@ func Test_NewManagementCluster(t *testing.T) { RelativePath: "bases/clusters/capa/template/cluster_config.yaml", GoldenFile: "testdata/expected/foo-bar.golden", }, - { - RelativePath: "bases/clusters/capa/template/default_apps.yaml", - GoldenFile: "testdata/expected/foo-bar.golden", - }, - { - RelativePath: "bases/clusters/capa/template/default_apps_config.yaml", - GoldenFile: "testdata/expected/foo-bar.golden", - }, }, }, } diff --git a/internal/gitops/structure/base/templates/default_apps.yaml.tmpl b/internal/gitops/structure/base/templates/default_apps.yaml.tmpl deleted file mode 100644 index 92d6fed76..000000000 --- a/internal/gitops/structure/base/templates/default_apps.yaml.tmpl +++ /dev/null @@ -1 +0,0 @@ -{{ .ClusterBaseTemplates.DefaultAppsAppCr }} \ No newline at end of file diff --git a/internal/gitops/structure/base/templates/default_apps_config.yaml.tmpl b/internal/gitops/structure/base/templates/default_apps_config.yaml.tmpl deleted file mode 100644 index ecf223d58..000000000 --- a/internal/gitops/structure/base/templates/default_apps_config.yaml.tmpl +++ /dev/null @@ -1 +0,0 @@ -{{ .ClusterBaseTemplates.DefaultAppsValues }} \ No newline at end of file diff --git a/internal/gitops/structure/base/templates/kustomization.yaml.tmpl b/internal/gitops/structure/base/templates/kustomization.yaml.tmpl index b44944add..241f235fd 100644 --- a/internal/gitops/structure/base/templates/kustomization.yaml.tmpl +++ b/internal/gitops/structure/base/templates/kustomization.yaml.tmpl @@ -5,13 +5,8 @@ configMapGenerator: - values=cluster_config.yaml name: ${cluster_name}-config namespace: org-${organization} - - files: - - values=default_apps_config.yaml - name: ${cluster_name}-default-apps-config - namespace: org-${organization} generatorOptions: disableNameSuffixHash: true kind: Kustomization resources: - cluster.yaml - - default_apps.yaml diff --git a/internal/gitops/structure/base/templates/template.go b/internal/gitops/structure/base/templates/template.go index 3d2cc7086..172275e21 100644 --- a/internal/gitops/structure/base/templates/template.go +++ b/internal/gitops/structure/base/templates/template.go @@ -15,18 +15,10 @@ var cluster string //go:embed cluster_config.yaml.tmpl var clusterConfig string -//go:embed default_apps.yaml.tmpl -var defaultApps string - -//go:embed default_apps_config.yaml.tmpl -var defaultAppsConfig string - func GetClusterBaseTemplates() []common.Template { return []common.Template{ {Name: "kustomization.yaml", Data: kustomization}, {Name: "cluster.yaml", Data: cluster}, {Name: "cluster_config.yaml", Data: clusterConfig}, - {Name: "default_apps.yaml", Data: defaultApps}, - {Name: "default_apps_config.yaml", Data: defaultAppsConfig}, } } diff --git a/internal/gitops/structure/base/testdata/expected/0-capa-kustomization.golden b/internal/gitops/structure/base/testdata/expected/0-capa-kustomization.golden index b44944add..241f235fd 100644 --- a/internal/gitops/structure/base/testdata/expected/0-capa-kustomization.golden +++ b/internal/gitops/structure/base/testdata/expected/0-capa-kustomization.golden @@ -5,13 +5,8 @@ configMapGenerator: - values=cluster_config.yaml name: ${cluster_name}-config namespace: org-${organization} - - files: - - values=default_apps_config.yaml - name: ${cluster_name}-default-apps-config - namespace: org-${organization} generatorOptions: disableNameSuffixHash: true kind: Kustomization resources: - cluster.yaml - - default_apps.yaml diff --git a/internal/gitops/structure/common/types.go b/internal/gitops/structure/common/types.go index fe1d32ee9..ef49c239f 100644 --- a/internal/gitops/structure/common/types.go +++ b/internal/gitops/structure/common/types.go @@ -26,10 +26,9 @@ type StructureConfig struct { Provider string ClusterBaseTemplates ClusterBaseTemplates - ClusterBase string - ClusterRelease string - ClusterUserConfig string - DefaultAppsUserConfig string + ClusterBase string + ClusterRelease string + ClusterUserConfig string EncryptionKeyPair encryption.KeyPair EncryptionTarget string @@ -49,9 +48,6 @@ type StructureConfig struct { type ClusterBaseTemplates struct { ClusterAppCr string ClusterValues string - - DefaultAppsAppCr string - DefaultAppsValues string } type Template struct { diff --git a/internal/gitops/structure/workload-cluster/cluster_test.go b/internal/gitops/structure/workload-cluster/cluster_test.go index 2568f1b07..b7006ae0e 100644 --- a/internal/gitops/structure/workload-cluster/cluster_test.go +++ b/internal/gitops/structure/workload-cluster/cluster_test.go @@ -173,9 +173,6 @@ topKey: ClusterUserConfig: string([]byte(`testKey: testValue topKey: nestedKey: nestedValue`)), - DefaultAppsUserConfig: string([]byte(`testKey: testValue -otherTopKey: - nestedOtherKey: nestedOtherValue`)), ManagementCluster: "demomc", WorkloadCluster: "demowc", Organization: "demoorg", @@ -219,18 +216,10 @@ otherTopKey: RelativePath: "management-clusters/demomc/organizations/demoorg/workload-clusters/demowc/cluster/cluster_userconfig.yaml", GoldenFile: "testdata/expected/0-cluster_userconfig.golden", }, - { - RelativePath: "management-clusters/demomc/organizations/demoorg/workload-clusters/demowc/cluster/default_apps_userconfig.yaml", - GoldenFile: "testdata/expected/0-default_apps_userconfig.golden", - }, { RelativePath: "management-clusters/demomc/organizations/demoorg/workload-clusters/demowc/cluster/patch_cluster_userconfig.yaml", GoldenFile: "testdata/expected/0-patch_cluster_userconfig.golden", }, - { - RelativePath: "management-clusters/demomc/organizations/demoorg/workload-clusters/demowc/cluster/patch_default_apps_userconfig.yaml", - GoldenFile: "testdata/expected/0-patch_default_apps_userconfig.golden", - }, }, }, { @@ -241,9 +230,6 @@ otherTopKey: ClusterUserConfig: string([]byte(`testKey: testValue topKey: nestedKey: nestedValue`)), - DefaultAppsUserConfig: string([]byte(`testKey: testValue -otherTopKey: - nestedOtherKey: nestedOtherValue`)), ManagementCluster: "demomc", WorkloadCluster: "demowc", Organization: "demoorg", @@ -289,18 +275,10 @@ otherTopKey: RelativePath: "management-clusters/demomc/organizations/demoorg/workload-clusters/demowc/mapi/cluster/cluster_userconfig.yaml", GoldenFile: "testdata/expected/0-cluster_userconfig.golden", }, - { - RelativePath: "management-clusters/demomc/organizations/demoorg/workload-clusters/demowc/mapi/cluster/default_apps_userconfig.yaml", - GoldenFile: "testdata/expected/0-default_apps_userconfig.golden", - }, { RelativePath: "management-clusters/demomc/organizations/demoorg/workload-clusters/demowc/mapi/cluster/patch_cluster_userconfig.yaml", GoldenFile: "testdata/expected/0-patch_cluster_userconfig.golden", }, - { - RelativePath: "management-clusters/demomc/organizations/demoorg/workload-clusters/demowc/mapi/cluster/patch_default_apps_userconfig.yaml", - GoldenFile: "testdata/expected/0-patch_default_apps_userconfig.golden", - }, }, }, } diff --git a/internal/gitops/structure/workload-cluster/templates/default_apps_userconfig.yaml.tmpl b/internal/gitops/structure/workload-cluster/templates/default_apps_userconfig.yaml.tmpl deleted file mode 100644 index 8ab7a7526..000000000 --- a/internal/gitops/structure/workload-cluster/templates/default_apps_userconfig.yaml.tmpl +++ /dev/null @@ -1,10 +0,0 @@ -{{- if and .ClusterBase .DefaultAppsUserConfig -}} -apiVersion: v1 -data: - values: | -{{ .DefaultAppsUserConfig | indent 4 }} -kind: ConfigMap -metadata: - name: {{ .WorkloadCluster }}-default-apps-userconfig - namespace: org-{{ .Organization }} -{{- end }} diff --git a/internal/gitops/structure/workload-cluster/templates/kustomization.yaml.tmpl b/internal/gitops/structure/workload-cluster/templates/kustomization.yaml.tmpl index 02d7f0716..924585ee0 100644 --- a/internal/gitops/structure/workload-cluster/templates/kustomization.yaml.tmpl +++ b/internal/gitops/structure/workload-cluster/templates/kustomization.yaml.tmpl @@ -3,14 +3,11 @@ apiVersion: kustomize.config.k8s.io/v1beta1 commonLabels: giantswarm.io/managed-by: flux kind: Kustomization -{{- if or .ClusterUserConfig .DefaultAppsUserConfig }} +{{- if .ClusterUserConfig }} patchesStrategicMerge: {{- if .ClusterUserConfig }} - patch_cluster_userconfig.yaml {{- end }} -{{- if .DefaultAppsUserConfig }} - - patch_default_apps_userconfig.yaml -{{- end }} {{- end }} resources: {{- if .SkipMAPI }} @@ -21,7 +18,4 @@ resources: {{- if .ClusterUserConfig }} - cluster_userconfig.yaml {{- end }} -{{- if .DefaultAppsUserConfig }} - - default_apps_userconfig.yaml -{{- end }} {{- end }} diff --git a/internal/gitops/structure/workload-cluster/templates/patch_default_apps_userconfig.yaml.tmpl b/internal/gitops/structure/workload-cluster/templates/patch_default_apps_userconfig.yaml.tmpl deleted file mode 100644 index 5803717d9..000000000 --- a/internal/gitops/structure/workload-cluster/templates/patch_default_apps_userconfig.yaml.tmpl +++ /dev/null @@ -1,12 +0,0 @@ -{{- if and .ClusterBase .DefaultAppsUserConfig -}} -apiVersion: application.giantswarm.io/v1alpha1 -kind: App -metadata: - name: ${cluster_name}-default-apps - namespace: org-${organization} -spec: - userConfig: - configMap: - name: {{ .WorkloadCluster }}-default-apps-userconfig - namespace: org-{{ .Organization }} -{{- end }} diff --git a/internal/gitops/structure/workload-cluster/templates/template.go b/internal/gitops/structure/workload-cluster/templates/template.go index 485d30d1b..2edc94b6e 100644 --- a/internal/gitops/structure/workload-cluster/templates/template.go +++ b/internal/gitops/structure/workload-cluster/templates/template.go @@ -12,9 +12,6 @@ var appsKustomization string //go:embed cluster_userconfig.yaml.tmpl var clusterUserConfig string -//go:embed default_apps_userconfig.yaml.tmpl -var defaultAppsUserConfig string - //go:embed kustomization.yaml.tmpl var kustomization string @@ -24,9 +21,6 @@ var patchClusterConfig string //go:embed patch_cluster_userconfig.yaml.tmpl var patchClusterUserconfig string -//go:embed patch_default_apps_userconfig.yaml.tmpl -var patchDefaultAppsUserconfig string - //go:embed private-key.yaml.tmpl var privateKey string @@ -44,9 +38,7 @@ func GetClusterDirectoryTemplates() []common.Template { return []common.Template{ common.Template{Name: "kustomization.yaml", Data: kustomization}, common.Template{Name: "cluster_userconfig.yaml", Data: clusterUserConfig}, - common.Template{Name: "default_apps_userconfig.yaml", Data: defaultAppsUserConfig}, common.Template{Name: "patch_cluster_userconfig.yaml", Data: patchClusterUserconfig}, - common.Template{Name: "patch_default_apps_userconfig.yaml", Data: patchDefaultAppsUserconfig}, } } diff --git a/internal/gitops/structure/workload-cluster/testdata/expected/2-kustomization.golden b/internal/gitops/structure/workload-cluster/testdata/expected/2-kustomization.golden index 3d42b95d3..cee4f452c 100644 --- a/internal/gitops/structure/workload-cluster/testdata/expected/2-kustomization.golden +++ b/internal/gitops/structure/workload-cluster/testdata/expected/2-kustomization.golden @@ -4,8 +4,6 @@ commonLabels: kind: Kustomization patchesStrategicMerge: - patch_cluster_userconfig.yaml - - patch_default_apps_userconfig.yaml resources: - ../../../../../../../bases/cluster/capo - cluster_userconfig.yaml - - default_apps_userconfig.yaml diff --git a/internal/gitops/structure/workload-cluster/testdata/expected/3-kustomization.golden b/internal/gitops/structure/workload-cluster/testdata/expected/3-kustomization.golden index ed8f390cf..f8ad4ca8b 100644 --- a/internal/gitops/structure/workload-cluster/testdata/expected/3-kustomization.golden +++ b/internal/gitops/structure/workload-cluster/testdata/expected/3-kustomization.golden @@ -4,8 +4,6 @@ commonLabels: kind: Kustomization patchesStrategicMerge: - patch_cluster_userconfig.yaml - - patch_default_apps_userconfig.yaml resources: - ../../../../../../../../bases/cluster/capo - cluster_userconfig.yaml - - default_apps_userconfig.yaml From 6c93e42dc932d684b530e31898427bca73df2aac Mon Sep 17 00:00:00 2001 From: Marian Steinbach Date: Wed, 14 Aug 2024 15:12:48 +0200 Subject: [PATCH 3/4] Replace cluster release with release --- CHANGELOG.md | 4 ++-- cmd/gitops/add/base/runner.go | 3 ++- cmd/gitops/add/workload-cluster/command.go | 6 +++--- cmd/gitops/add/workload-cluster/flag.go | 15 +++++++-------- cmd/gitops/add/workload-cluster/runner.go | 2 +- .../testdata/expected/create/2-demowc.golden | 2 +- .../expected/dry-run/case-2-flawless.golden | 2 +- .../filesystem/creator/testdata/input/demowc.yaml | 2 +- .../flux-kustomization/kustomization_test.go | 4 ++-- internal/gitops/structure/common/types.go | 2 +- .../gitops/structure/workload-cluster/cluster.go | 2 +- .../structure/workload-cluster/cluster_test.go | 14 +++++++------- .../templates/workload-cluster.yaml.tmpl | 4 ++-- .../testdata/expected/1-demowc.golden | 2 +- .../testdata/expected/2-demowc.golden | 2 +- 15 files changed, 33 insertions(+), 33 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ad28c56b5..ab366da3c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,7 +11,7 @@ and this project's packages adheres to [Semantic Versioning](http://semver.org/s - Use more portable, Bash specific shebang for GitOps pre-commit script template - Schedule cluster upgrades for CAPI clusters. -- `kubectl gs gitops add workload-cluster`: Remove flag `--default-apps-release`. +- The way to specify a release in `kubectl gs gitops add workload-cluster` has changed. The flags `--default-apps-release` and `--cluster-release` have been replaced by `--release`. ## [3.1.0] - 2024-07-23 @@ -22,7 +22,7 @@ and this project's packages adheres to [Semantic Versioning](http://semver.org/s ### Changed -- **BREAKING** When templating cluster manifests for CAPZ clusters with `kubectl gs template cluster` command, now we set the workload cluster release version via the `--release` flag, instead setting cluster-azure version via `--cluster-version`. +- **BREAKING** When templating cluster manifests for CAPZ clusters with `kubectl gs template cluster` command, now we set the workload cluster release version via the `--release` flag, instead setting cluster-azure version via `--cluster-version`. ## [3.0.0] - 2024-06-27 diff --git a/cmd/gitops/add/base/runner.go b/cmd/gitops/add/base/runner.go index bea78a5e3..e8bdca8ed 100644 --- a/cmd/gitops/add/base/runner.go +++ b/cmd/gitops/add/base/runner.go @@ -116,7 +116,7 @@ func generateClusterAppCrTemplate(appName string) (string, error) { Catalog: "cluster", InCluster: true, Namespace: "org-${organization}", - Version: "${cluster_release}", + Version: "", UserConfigConfigMapName: "${cluster_name}-config", }) @@ -144,6 +144,7 @@ func generateCapAClusterBaseTemplates(structureConfig common.StructureConfig) (c Name: "nodepool0", }, }, + ReleaseVersion: "${release}", }) clusterValues, err := capa.GenerateClusterValues(clusterConfig) diff --git a/cmd/gitops/add/workload-cluster/command.go b/cmd/gitops/add/workload-cluster/command.go index 86949e455..bcd9f432c 100644 --- a/cmd/gitops/add/workload-cluster/command.go +++ b/cmd/gitops/add/workload-cluster/command.go @@ -19,7 +19,7 @@ const ( workload-cluster \ [--base ] \ -[--cluster-release ] \ +[--release ] \ [--cluster-user-config ] \ --name \ --management-cluster \ @@ -46,7 +46,7 @@ https://github.com/giantswarm/gitops-template/blob/main/docs/add_wc.md` --organization myorg \ --repository-name gitops-demo \ --base bases/clusters/openstack \ - --cluster-release 0.13.0 + --release 0.13.0 # Add dummy Workload Cluster structure with definition from base and extra configuration kubectl gs gitops add wc \ @@ -55,7 +55,7 @@ https://github.com/giantswarm/gitops-template/blob/main/docs/add_wc.md` --organization myorg \ --repository-name gitops-demo \ --base bases/clusters/openstack \ - --cluster-release 0.13.0 \ + --release 0.13.0 \ --cluster-user-config /tmp/cluster_user_config.yaml` ) diff --git a/cmd/gitops/add/workload-cluster/flag.go b/cmd/gitops/add/workload-cluster/flag.go index db084f91a..a59d10f0f 100644 --- a/cmd/gitops/add/workload-cluster/flag.go +++ b/cmd/gitops/add/workload-cluster/flag.go @@ -14,7 +14,7 @@ const ( flagRepositoryName = "repository-name" // CAPI only - flagClusterRelease = "cluster-release" + flagRelease = "release" flagClusterUserConfig = "cluster-user-config" ) @@ -26,19 +26,18 @@ type flag struct { SkipMAPI bool RepositoryName string - ClusterRelease string + Release string ClusterUserConfig string } func (f *flag) Init(cmd *cobra.Command) { cmd.Flags().StringVar(&f.Base, flagBase, "", "Path to the base directory. It must be relative to the repository root.") - cmd.Flags().StringVar(&f.ManagementCluster, flagManagementCluster, "", "Codename of the Management Cluster the Workload Cluster belongs to.") + cmd.Flags().StringVar(&f.ManagementCluster, flagManagementCluster, "", "Codename of the management cluster the workload cluster belongs to.") cmd.Flags().StringVar(&f.Name, flagName, "", "Name of the Workload Cluster.") - cmd.Flags().StringVar(&f.Organization, flagOrganization, "", "Name of the Organization the Workload Cluster belongs to.") + cmd.Flags().StringVar(&f.Organization, flagOrganization, "", "Name of the Organization the workload cluster belongs to.") cmd.Flags().BoolVar(&f.SkipMAPI, flagSkipMAPI, false, "Skip `mapi` directory when adding the app.") cmd.Flags().StringVar(&f.RepositoryName, flagRepositoryName, "", "Name of the GitOps repository.") - - cmd.Flags().StringVar(&f.ClusterRelease, flagClusterRelease, "", "Cluster app version.") + cmd.Flags().StringVar(&f.Release, flagRelease, "", "Workload cluster release version.") cmd.Flags().StringVar(&f.ClusterUserConfig, flagClusterUserConfig, "", "Cluster app user configuration to patch the base with.") } @@ -59,11 +58,11 @@ func (f *flag) Validate() error { return microerror.Maskf(invalidFlagsError, "--%s must not be empty", flagRepositoryName) } - if f.Base != "" && f.ClusterRelease == "" { + if f.Base != "" && f.Release == "" { return microerror.Maskf( invalidFlagsError, "--%s must not be empty when referencing base", - flagClusterRelease, + flagRelease, ) } diff --git a/cmd/gitops/add/workload-cluster/runner.go b/cmd/gitops/add/workload-cluster/runner.go index c0a9d2742..6491d8f79 100644 --- a/cmd/gitops/add/workload-cluster/runner.go +++ b/cmd/gitops/add/workload-cluster/runner.go @@ -45,7 +45,7 @@ func (r *runner) run(ctx context.Context, cmd *cobra.Command, args []string) err config := common.StructureConfig{ ClusterBase: r.flag.Base, - ClusterRelease: r.flag.ClusterRelease, + Release: r.flag.Release, ManagementCluster: r.flag.ManagementCluster, WorkloadCluster: r.flag.Name, Organization: r.flag.Organization, diff --git a/internal/gitops/filesystem/creator/testdata/expected/create/2-demowc.golden b/internal/gitops/filesystem/creator/testdata/expected/create/2-demowc.golden index b3f6801f7..afa974dfc 100644 --- a/internal/gitops/filesystem/creator/testdata/expected/create/2-demowc.golden +++ b/internal/gitops/filesystem/creator/testdata/expected/create/2-demowc.golden @@ -10,7 +10,7 @@ spec: substitute: cluster_name: "demowc" organization: "demoorg" - cluster_release: "0.13.0" + release: "0.13.0" prune: false serviceAccountName: automation sourceRef: diff --git a/internal/gitops/filesystem/creator/testdata/expected/dry-run/case-2-flawless.golden b/internal/gitops/filesystem/creator/testdata/expected/dry-run/case-2-flawless.golden index ce83bf2b5..6bd24d285 100644 --- a/internal/gitops/filesystem/creator/testdata/expected/dry-run/case-2-flawless.golden +++ b/internal/gitops/filesystem/creator/testdata/expected/dry-run/case-2-flawless.golden @@ -14,7 +14,7 @@ spec: substitute: cluster_name: "demowc" organization: "demoorg" - cluster_release: "0.13.0" + release: "0.13.0" prune: false serviceAccountName: automation sourceRef: diff --git a/internal/gitops/filesystem/creator/testdata/input/demowc.yaml b/internal/gitops/filesystem/creator/testdata/input/demowc.yaml index b3f6801f7..afa974dfc 100644 --- a/internal/gitops/filesystem/creator/testdata/input/demowc.yaml +++ b/internal/gitops/filesystem/creator/testdata/input/demowc.yaml @@ -10,7 +10,7 @@ spec: substitute: cluster_name: "demowc" organization: "demoorg" - cluster_release: "0.13.0" + release: "0.13.0" prune: false serviceAccountName: automation sourceRef: diff --git a/internal/gitops/filesystem/modifier/flux-kustomization/kustomization_test.go b/internal/gitops/filesystem/modifier/flux-kustomization/kustomization_test.go index 4c886ca2f..b20c11543 100644 --- a/internal/gitops/filesystem/modifier/flux-kustomization/kustomization_test.go +++ b/internal/gitops/filesystem/modifier/flux-kustomization/kustomization_test.go @@ -155,7 +155,7 @@ spec: path: ./management-clusters/demomc postBuild: substitute: - cluster_release: 1.0.0 + release: 1.0.0 prune: true serviceAccountName: automation sourceRef: @@ -180,7 +180,7 @@ spec: `), modifier: KustomizationModifier{ PostBuildEnvs: map[string]string{ - "cluster_release": "1.0.0", + "release": "1.0.0", }, }, }, diff --git a/internal/gitops/structure/common/types.go b/internal/gitops/structure/common/types.go index ef49c239f..931ed8302 100644 --- a/internal/gitops/structure/common/types.go +++ b/internal/gitops/structure/common/types.go @@ -27,7 +27,7 @@ type StructureConfig struct { ClusterBaseTemplates ClusterBaseTemplates ClusterBase string - ClusterRelease string + Release string ClusterUserConfig string EncryptionKeyPair encryption.KeyPair diff --git a/internal/gitops/structure/workload-cluster/cluster.go b/internal/gitops/structure/workload-cluster/cluster.go index 55ac0677d..a90f08294 100644 --- a/internal/gitops/structure/workload-cluster/cluster.go +++ b/internal/gitops/structure/workload-cluster/cluster.go @@ -133,7 +133,7 @@ func NewWorkloadCluster(config common.StructureConfig) (*creator.CreatorConfig, if config.ClusterBase != "" { fsModifiers[wcFile] = fluxkusmod.KustomizationModifier{ PostBuildEnvs: map[string]string{ - "cluster_release": config.ClusterRelease, + "release": config.Release, }, } } diff --git a/internal/gitops/structure/workload-cluster/cluster_test.go b/internal/gitops/structure/workload-cluster/cluster_test.go index b7006ae0e..bd3bd596c 100644 --- a/internal/gitops/structure/workload-cluster/cluster_test.go +++ b/internal/gitops/structure/workload-cluster/cluster_test.go @@ -66,7 +66,7 @@ func Test_NewWorkloadCluster(t *testing.T) { name: "flawless with definition", config: common.StructureConfig{ ClusterBase: "bases/cluster/capo", - ClusterRelease: "0.13.0", + Release: "0.13.0", ManagementCluster: "demomc", WorkloadCluster: "demowc", Organization: "demoorg", @@ -111,8 +111,8 @@ func Test_NewWorkloadCluster(t *testing.T) { { name: "flawless with definition and configuration", config: common.StructureConfig{ - ClusterBase: "bases/cluster/capo", - ClusterRelease: "0.13.0", + ClusterBase: "bases/cluster/capo", + Release: "0.13.0", ClusterUserConfig: string([]byte(`testKey: testValue topKey: nestedKey: nestedValue`)), @@ -168,8 +168,8 @@ topKey: { name: "flawless with definition and full configuration", config: common.StructureConfig{ - ClusterBase: "bases/cluster/capo", - ClusterRelease: "0.13.0", + ClusterBase: "bases/cluster/capo", + Release: "0.13.0", ClusterUserConfig: string([]byte(`testKey: testValue topKey: nestedKey: nestedValue`)), @@ -225,8 +225,8 @@ topKey: { name: "flawless MAPI with definition and full configuration", config: common.StructureConfig{ - ClusterBase: "bases/cluster/capo", - ClusterRelease: "0.13.0", + ClusterBase: "bases/cluster/capo", + Release: "0.13.0", ClusterUserConfig: string([]byte(`testKey: testValue topKey: nestedKey: nestedValue`)), diff --git a/internal/gitops/structure/workload-cluster/templates/workload-cluster.yaml.tmpl b/internal/gitops/structure/workload-cluster/templates/workload-cluster.yaml.tmpl index 52f424615..5979beaaa 100644 --- a/internal/gitops/structure/workload-cluster/templates/workload-cluster.yaml.tmpl +++ b/internal/gitops/structure/workload-cluster/templates/workload-cluster.yaml.tmpl @@ -13,8 +13,8 @@ spec: postBuild: substitute: cluster_name: {{ .WorkloadCluster }} - {{- if .ClusterRelease }} - cluster_release: {{ .ClusterRelease }} + {{- if .Release }} + release: {{ .Release }} {{- end }} organization: {{ .Organization }} prune: false diff --git a/internal/gitops/structure/workload-cluster/testdata/expected/1-demowc.golden b/internal/gitops/structure/workload-cluster/testdata/expected/1-demowc.golden index 1be4f0978..e77eaf5b3 100644 --- a/internal/gitops/structure/workload-cluster/testdata/expected/1-demowc.golden +++ b/internal/gitops/structure/workload-cluster/testdata/expected/1-demowc.golden @@ -9,7 +9,7 @@ spec: postBuild: substitute: cluster_name: demowc - cluster_release: 0.13.0 + release: 0.13.0 organization: demoorg prune: false serviceAccountName: automation diff --git a/internal/gitops/structure/workload-cluster/testdata/expected/2-demowc.golden b/internal/gitops/structure/workload-cluster/testdata/expected/2-demowc.golden index ba679bd65..9405796cf 100644 --- a/internal/gitops/structure/workload-cluster/testdata/expected/2-demowc.golden +++ b/internal/gitops/structure/workload-cluster/testdata/expected/2-demowc.golden @@ -9,7 +9,7 @@ spec: postBuild: substitute: cluster_name: demowc - cluster_release: 0.13.0 + release: 0.13.0 organization: demoorg prune: false serviceAccountName: automation From cdb01981763c9d3d5c6bedf07acd59c66ec58570 Mon Sep 17 00:00:00 2001 From: Marian Steinbach Date: Wed, 14 Aug 2024 15:26:29 +0200 Subject: [PATCH 4/4] Improve examples --- cmd/gitops/add/workload-cluster/command.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/cmd/gitops/add/workload-cluster/command.go b/cmd/gitops/add/workload-cluster/command.go index bcd9f432c..b522026f0 100644 --- a/cmd/gitops/add/workload-cluster/command.go +++ b/cmd/gitops/add/workload-cluster/command.go @@ -32,30 +32,30 @@ https://github.com/giantswarm/gitops-template/blob/main/docs/repo_structure.md. Steps it implements: https://github.com/giantswarm/gitops-template/blob/main/docs/add_wc.md` - examples = ` # Add dummy Workload Cluster structure, without cluster definition + examples = ` # Add dummy workload cluster structure, without cluster definition kubectl gs gitops add wc \ --name dummy \ --management-cluster mymc \ --organization myorg \ --repository-name gitops-demo - # Add dummy Workload Cluster structure with definition from base + # Add dummy workload cluster structure with definition from base kubectl gs gitops add wc \ --name dummy \ --management-cluster mymc \ --organization myorg \ --repository-name gitops-demo \ --base bases/clusters/openstack \ - --release 0.13.0 + --release 29.0.0 - # Add dummy Workload Cluster structure with definition from base and extra configuration + # Add dummy workload cluster structure with definition from base and extra configuration kubectl gs gitops add wc \ --name dummy \ --management-cluster mymc \ --organization myorg \ --repository-name gitops-demo \ --base bases/clusters/openstack \ - --release 0.13.0 \ + --release 29.0.0 \ --cluster-user-config /tmp/cluster_user_config.yaml` )