diff --git a/CHANGELOG.md b/CHANGELOG.md index 0643b94a5..2786af588 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ and this project's packages adheres to [Semantic Versioning](http://semver.org/s ## [Unreleased] +### Changed + +- Add deletion prevention label also to templated cluster's `App` and `ConfigMap` if using the `kubectl gs template --prevent-deletion` parameter + ## [4.6.0] - 2024-11-28 ### Changed diff --git a/cmd/template/app/runner.go b/cmd/template/app/runner.go index b69e5be9e..a27c06448 100644 --- a/cmd/template/app/runner.go +++ b/cmd/template/app/runner.go @@ -142,7 +142,7 @@ func (r *runner) run(ctx context.Context, cmd *cobra.Command, args []string) err if userConfigMap.Labels == nil { userConfigMap.Labels = map[string]string{} } - userConfigMap.Labels[label.PreventDeletion] = "true" + userConfigMap.Labels[label.PreventDeletion] = "true" //nolint:goconst } userConfigConfigMapYaml, err = yaml.Marshal(userConfigMap) diff --git a/cmd/template/cluster/flags/flag.go b/cmd/template/cluster/flags/flag.go index 8df688203..fb3594c3b 100644 --- a/cmd/template/cluster/flags/flag.go +++ b/cmd/template/cluster/flags/flag.go @@ -197,7 +197,7 @@ type Flag struct { func (f *Flag) Init(cmd *cobra.Command) { cmd.Flags().StringVar(&f.Provider, flagProvider, "", "Installation infrastructure provider.") cmd.Flags().StringVar(&f.ManagementCluster, flagManagementCluster, "", "Name of the management cluster. Only required in combination with certain parameters.") - cmd.Flags().BoolVar(&f.PreventDeletion, flagPreventDeletion, false, "Prevent cluster from getting deleted") + cmd.Flags().BoolVar(&f.PreventDeletion, flagPreventDeletion, false, "Prevent cluster from getting deleted (see https://docs.giantswarm.io/tutorials/fleet-management/deletion-prevention/)") // AWS only. cmd.Flags().StringVar(&f.AWS.AWSClusterRoleIdentityName, flagAWSClusterRoleIdentityName, "", "Name of the AWSClusterRoleIdentity that will be used for cluster creation.") diff --git a/cmd/template/cluster/provider/capa.go b/cmd/template/cluster/provider/capa.go index c04bacdb8..61889ff81 100644 --- a/cmd/template/cluster/provider/capa.go +++ b/cmd/template/cluster/provider/capa.go @@ -18,6 +18,7 @@ import ( "sigs.k8s.io/yaml" gsannotation "github.com/giantswarm/k8smetadata/pkg/annotation" + "github.com/giantswarm/k8smetadata/pkg/label" k8smetadata "github.com/giantswarm/k8smetadata/pkg/label" "github.com/giantswarm/kubectl-gs/v5/cmd/template/cluster/common" @@ -217,6 +218,9 @@ func templateClusterCAPA(ctx context.Context, k8sClient k8sclient.Interface, out userConfigMap.Labels = map[string]string{} userConfigMap.Labels[k8smetadata.Cluster] = config.Name + if config.PreventDeletion { + userConfigMap.Labels[label.PreventDeletion] = "true" //nolint:goconst + } configMapYAML, err = yaml.Marshal(userConfigMap) if err != nil { @@ -233,6 +237,10 @@ func templateClusterCAPA(ctx context.Context, k8sClient k8sclient.Interface, out Name: ClusterAWSRepoName, Namespace: common.OrganizationNamespace(config.Organization), UserConfigConfigMapName: configMapName, + ExtraLabels: map[string]string{}, + } + if config.PreventDeletion { + clusterAppConfig.ExtraLabels[label.PreventDeletion] = "true" } var err error diff --git a/cmd/template/cluster/provider/capg.go b/cmd/template/cluster/provider/capg.go index 31263c4db..175d4ba9e 100644 --- a/cmd/template/cluster/provider/capg.go +++ b/cmd/template/cluster/provider/capg.go @@ -7,6 +7,7 @@ import ( "text/template" "github.com/giantswarm/k8sclient/v8/pkg/k8sclient" + "github.com/giantswarm/k8smetadata/pkg/label" k8smetadata "github.com/giantswarm/k8smetadata/pkg/label" "github.com/giantswarm/microerror" "sigs.k8s.io/yaml" @@ -56,6 +57,9 @@ func templateClusterGCP(ctx context.Context, k8sClient k8sclient.Interface, outp userConfigMap.Labels = map[string]string{} userConfigMap.Labels[k8smetadata.Cluster] = config.Name + if config.PreventDeletion { + userConfigMap.Labels[label.PreventDeletion] = "true" //nolint:goconst + } configMapYAML, err = yaml.Marshal(userConfigMap) if err != nil { @@ -82,6 +86,10 @@ func templateClusterGCP(ctx context.Context, k8sClient k8sclient.Interface, outp Namespace: common.OrganizationNamespace(config.Organization), Version: appVersion, UserConfigConfigMapName: configMapName, + ExtraLabels: map[string]string{}, + } + if config.PreventDeletion { + clusterAppConfig.ExtraLabels[label.PreventDeletion] = "true" } var err error diff --git a/cmd/template/cluster/provider/capv.go b/cmd/template/cluster/provider/capv.go index 4822a1031..40c1c82cc 100644 --- a/cmd/template/cluster/provider/capv.go +++ b/cmd/template/cluster/provider/capv.go @@ -11,6 +11,7 @@ import ( "github.com/giantswarm/microerror" "sigs.k8s.io/yaml" + "github.com/giantswarm/k8smetadata/pkg/label" k8smetadata "github.com/giantswarm/k8smetadata/pkg/label" applicationv1alpha1 "github.com/giantswarm/apiextensions-application/api/v1alpha1" @@ -81,6 +82,9 @@ func templateClusterVSphere(output io.Writer, config common.ClusterConfig, appVe userConfigMap.Labels = map[string]string{} userConfigMap.Labels[k8smetadata.Cluster] = config.Name + if config.PreventDeletion { + userConfigMap.Labels[label.PreventDeletion] = "true" //nolint:goconst + } configMapYAML, err = yaml.Marshal(userConfigMap) if err != nil { @@ -109,6 +113,10 @@ func templateClusterVSphere(output io.Writer, config common.ClusterConfig, appVe UserConfigConfigMapName: configMapName, UserConfigSecretName: config.VSphere.CredentialsSecretName, ExtraConfigs: extraConfigs, + ExtraLabels: map[string]string{}, + } + if config.PreventDeletion { + clusterAppConfig.ExtraLabels[label.PreventDeletion] = "true" } var err error diff --git a/cmd/template/cluster/provider/capvcd.go b/cmd/template/cluster/provider/capvcd.go index e95459354..ef4a7f151 100644 --- a/cmd/template/cluster/provider/capvcd.go +++ b/cmd/template/cluster/provider/capvcd.go @@ -9,6 +9,7 @@ import ( "github.com/giantswarm/microerror" "sigs.k8s.io/yaml" + "github.com/giantswarm/k8smetadata/pkg/label" k8smetadata "github.com/giantswarm/k8smetadata/pkg/label" applicationv1alpha1 "github.com/giantswarm/apiextensions-application/api/v1alpha1" @@ -65,6 +66,9 @@ func templateClusterCloudDirector(output io.Writer, config common.ClusterConfig, userConfigMap.Labels = map[string]string{} userConfigMap.Labels[k8smetadata.Cluster] = config.Name + if config.PreventDeletion { + userConfigMap.Labels[label.PreventDeletion] = "true" //nolint:goconst + } configMapYAML, err = yaml.Marshal(userConfigMap) if err != nil { @@ -92,6 +96,10 @@ func templateClusterCloudDirector(output io.Writer, config common.ClusterConfig, Version: appVersion, UserConfigConfigMapName: configMapName, ExtraConfigs: extraConfigs, + ExtraLabels: map[string]string{}, + } + if config.PreventDeletion { + clusterAppConfig.ExtraLabels[label.PreventDeletion] = "true" } var err error diff --git a/cmd/template/cluster/provider/capz.go b/cmd/template/cluster/provider/capz.go index 1343ddbb6..649d372fa 100644 --- a/cmd/template/cluster/provider/capz.go +++ b/cmd/template/cluster/provider/capz.go @@ -9,6 +9,7 @@ import ( "github.com/giantswarm/microerror" "sigs.k8s.io/yaml" + "github.com/giantswarm/k8smetadata/pkg/label" k8smetadata "github.com/giantswarm/k8smetadata/pkg/label" "github.com/giantswarm/kubectl-gs/v5/cmd/template/cluster/common" @@ -54,6 +55,9 @@ func templateClusterCAPZ(ctx context.Context, k8sClient k8sclient.Interface, out userConfigMap.Labels = map[string]string{} userConfigMap.Labels[k8smetadata.Cluster] = config.Name + if config.PreventDeletion { + userConfigMap.Labels[label.PreventDeletion] = "true" //nolint:goconst + } configMapYAML, err = yaml.Marshal(userConfigMap) if err != nil { @@ -70,6 +74,10 @@ func templateClusterCAPZ(ctx context.Context, k8sClient k8sclient.Interface, out Name: ClusterAzureRepoName, Namespace: common.OrganizationNamespace(config.Organization), UserConfigConfigMapName: configMapName, + ExtraLabels: map[string]string{}, + } + if config.PreventDeletion { + clusterAppConfig.ExtraLabels[label.PreventDeletion] = "true" } var err error diff --git a/cmd/template/cluster/provider/eks.go b/cmd/template/cluster/provider/eks.go index 8b50029e8..6de8716da 100644 --- a/cmd/template/cluster/provider/eks.go +++ b/cmd/template/cluster/provider/eks.go @@ -10,6 +10,7 @@ import ( "github.com/giantswarm/microerror" "sigs.k8s.io/yaml" + "github.com/giantswarm/k8smetadata/pkg/label" k8smetadata "github.com/giantswarm/k8smetadata/pkg/label" "github.com/giantswarm/kubectl-gs/v5/cmd/template/cluster/common" @@ -61,6 +62,9 @@ func templateClusterEKS(ctx context.Context, k8sClient k8sclient.Interface, outp userConfigMap.Labels = map[string]string{} userConfigMap.Labels[k8smetadata.Cluster] = config.Name + if config.PreventDeletion { + userConfigMap.Labels[label.PreventDeletion] = "true" //nolint:goconst + } configMapYAML, err = yaml.Marshal(userConfigMap) if err != nil { @@ -87,6 +91,10 @@ func templateClusterEKS(ctx context.Context, k8sClient k8sclient.Interface, outp Namespace: common.OrganizationNamespace(config.Organization), Version: appVersion, UserConfigConfigMapName: configMapName, + ExtraLabels: map[string]string{}, + } + if config.PreventDeletion { + clusterAppConfig.ExtraLabels[label.PreventDeletion] = "true" } var err error