Skip to content

Commit

Permalink
--prevent-deletion implementation (#1334)
Browse files Browse the repository at this point in the history
* init commit

* Added prevent-deletion flag value to cluster template config

* update for capz & capa-eks

* CHANGELOG

* tests update

* revert test_4

* Update flag.go

Co-authored-by: Marian Steinbach <marian@giantswarm.io>

---------

Co-authored-by: vvondruska <vondruska.vaclav@gmail.com>
Co-authored-by: Marian Steinbach <marian@giantswarm.io>
  • Loading branch information
3 people committed Jun 19, 2024
1 parent 8a1e413 commit 995b6e0
Show file tree
Hide file tree
Showing 19 changed files with 52 additions and 19 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project's packages adheres to [Semantic Versioning](http://semver.org/s

## [Unreleased]

### Added

- Added `--prevent-deletion` flag to cluster template command for capa, capa-eks, capz clusters

## [2.56.0] - 2024-06-10

### Added
Expand Down
3 changes: 3 additions & 0 deletions cmd/template/cluster/flag.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const (
flagEnableLongNames = "enable-long-names"
flagProvider = "provider"
flagManagementCluster = "management-cluster"
flagPreventDeletion = "prevent-deletion"

// AWS only.
flagAWSExternalSNAT = "external-snat"
Expand Down Expand Up @@ -143,6 +144,7 @@ type flag struct {
EnableLongNames bool
Provider string
ManagementCluster string
PreventDeletion bool

// Common.
ControlPlaneAZ []string
Expand Down Expand Up @@ -177,6 +179,7 @@ func (f *flag) Init(cmd *cobra.Command) {
cmd.Flags().BoolVar(&f.EnableLongNames, flagEnableLongNames, true, "Allow long names.")
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")

// AWS only.
cmd.Flags().StringVar(&f.AWS.AWSClusterRoleIdentityName, flagAWSClusterRoleIdentityName, "", "Name of the AWSClusterRoleIdentity that will be used for cluster creation.")
Expand Down
7 changes: 4 additions & 3 deletions cmd/template/cluster/provider/capa.go
Original file line number Diff line number Diff line change
Expand Up @@ -281,9 +281,10 @@ func BuildCapaClusterConfig(config ClusterConfig) capa.ClusterConfig {
InstanceType: config.ControlPlaneInstanceType,
},
Metadata: &capa.Metadata{
Name: config.Name,
Description: config.Description,
Organization: config.Organization,
Name: config.Name,
Description: config.Description,
Organization: config.Organization,
PreventDeletion: config.PreventDeletion,
},
NodePools: &map[string]capa.MachinePool{
config.AWS.MachinePool.Name: {
Expand Down
7 changes: 4 additions & 3 deletions cmd/template/cluster/provider/capz.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,10 @@ func BuildCapzClusterConfig(config ClusterConfig) capz.ClusterConfig {
return capz.ClusterConfig{
Global: &capz.Global{
Metadata: &capz.Metadata{
Name: config.Name,
Description: config.Description,
Organization: config.Organization,
Name: config.Name,
Description: config.Description,
Organization: config.Organization,
PreventDeletion: config.PreventDeletion,
},
ProviderSpecific: &capz.ProviderSpecific{
Location: config.Region,
Expand Down
1 change: 1 addition & 0 deletions cmd/template/cluster/provider/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ type ClusterConfig struct {
PodsCIDR string
OIDC OIDC
ServicePriority string
PreventDeletion bool

Region string
BastionInstanceType string
Expand Down
7 changes: 4 additions & 3 deletions cmd/template/cluster/provider/eks.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,10 @@ func BuildEKSClusterConfig(config ClusterConfig) eks.ClusterConfig {
return eks.ClusterConfig{
Global: &eks.Global{
Metadata: &eks.Metadata{
Name: config.Name,
Description: config.Description,
Organization: config.Organization,
Name: config.Name,
Description: config.Description,
Organization: config.Organization,
PreventDeletion: config.PreventDeletion,
},
},
}
Expand Down
6 changes: 5 additions & 1 deletion cmd/template/cluster/provider/templates/capa/functions.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,11 @@ func GenerateClusterValues(flagInputs ClusterConfig) (string, error) {
}
}

finalConfigString, err := yaml.Marshal(flagInputs)
if metadata, ok := flagConfigData["global"].(map[string]interface{})["metadata"].(map[string]interface{}); ok {
metadata["preventDeletion"] = flagInputs.Global.Metadata.PreventDeletion
}

finalConfigString, err := yaml.Marshal(flagConfigData)
if err != nil {
return "", microerror.Mask(err)
}
Expand Down
7 changes: 4 additions & 3 deletions cmd/template/cluster/provider/templates/capa/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@ type ClusterConfig struct {
}

type Metadata struct {
Description string `json:"description,omitempty"`
Name string `json:"name,omitempty"`
Organization string `json:"organization,omitempty"`
Description string `json:"description,omitempty"`
Name string `json:"name,omitempty"`
Organization string `json:"organization,omitempty"`
PreventDeletion bool `json:"preventDeletion,omitempty"`
}

type DefaultAppsConfig struct {
Expand Down
4 changes: 4 additions & 0 deletions cmd/template/cluster/provider/templates/capz/functions.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ func GenerateClusterValues(flagInputs ClusterConfig) (string, error) {
}
}

if metadata, ok := flagConfigData["global"].(map[string]interface{})["metadata"].(map[string]interface{}); ok {
metadata["preventDeletion"] = flagInputs.Global.Metadata.PreventDeletion
}

finalConfigString, err := yaml.Marshal(flagInputs)
if err != nil {
return "", microerror.Mask(err)
Expand Down
7 changes: 4 additions & 3 deletions cmd/template/cluster/provider/templates/capz/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ type Global struct {
}

type Metadata struct {
Name string `json:"name,omitempty"`
Description string `json:"description,omitempty"`
Organization string `json:"organization,omitempty"`
Name string `json:"name,omitempty"`
Description string `json:"description,omitempty"`
Organization string `json:"organization,omitempty"`
PreventDeletion bool `json:"preventDeletion,omitempty"`
}

type DefaultAppsConfig struct {
Expand Down
4 changes: 4 additions & 0 deletions cmd/template/cluster/provider/templates/eks/functions.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ func GenerateClusterValues(flagInputs ClusterConfig) (string, error) {
}
}

if metadata, ok := flagConfigData["global"].(map[string]interface{})["metadata"].(map[string]interface{}); ok {
metadata["preventDeletion"] = flagInputs.Global.Metadata.PreventDeletion
}

finalConfigString, err := yaml.Marshal(flagInputs)
if err != nil {
return "", microerror.Mask(err)
Expand Down
7 changes: 4 additions & 3 deletions cmd/template/cluster/provider/templates/eks/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ type ClusterConfig struct {
}

type Metadata struct {
Name string `json:"name,omitempty"`
Description string `json:"description,omitempty"`
Organization string `json:"organization,omitempty"`
Name string `json:"name,omitempty"`
Description string `json:"description,omitempty"`
Organization string `json:"organization,omitempty"`
PreventDeletion bool `json:"preventDeletion,omitempty"`
}
1 change: 1 addition & 0 deletions cmd/template/cluster/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ func (r *runner) getClusterConfig() (provider.ClusterConfig, error) {
Namespace: metav1.NamespaceDefault,
Region: r.flag.Region,
ServicePriority: r.flag.ServicePriority,
PreventDeletion: r.flag.PreventDeletion,

App: r.flag.App,
AWS: r.flag.AWS,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ data:
description: just a test cluster
name: test1
organization: test
preventDeletion: false
nodePools:
worker1:
availabilityZones:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ data:
description: just a test cluster
name: test1
organization: test
preventDeletion: false
nodePools:
worker1:
availabilityZones:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ data:
description: just a test cluster
name: test1
organization: test
preventDeletion: false
nodePools:
worker1:
availabilityZones:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ data:
description: just a test cluster
name: test6
organization: test
preventDeletion: false
nodePools:
worker1:
availabilityZones:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ data:
description: just a test cluster
name: test7
organization: test
preventDeletion: false
nodePools:
worker1:
availabilityZones:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ data:
description: just a test cluster
name: test8
organization: test
preventDeletion: false
nodePools:
worker1:
availabilityZones:
Expand Down

0 comments on commit 995b6e0

Please sign in to comment.