Skip to content

Commit 4f05ed0

Browse files
committed
move to addon type
1 parent 4fee3cb commit 4f05ed0

File tree

13 files changed

+48
-46
lines changed

13 files changed

+48
-46
lines changed

config/crd/bases/controlplane.cluster.x-k8s.io_awsmanagedcontrolplanes.yaml

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,11 @@ spec:
9696
description: Name is the name of the addon
9797
minLength: 2
9898
type: string
99+
preserveOnDelete:
100+
description: |-
101+
PreserveOnDelete indicates that the addon resources should be
102+
preserved in the cluster on delete.
103+
type: boolean
99104
serviceAccountRoleARN:
100105
description: ServiceAccountRoleArn is the ARN of an IAM role
101106
to bind to the addons service account
@@ -2270,6 +2275,11 @@ spec:
22702275
description: Name is the name of the addon
22712276
minLength: 2
22722277
type: string
2278+
preserveOnDelete:
2279+
description: |-
2280+
PreserveOnDelete indicates that the addon resources should be
2281+
preserved in the cluster on delete.
2282+
type: boolean
22732283
serviceAccountRoleARN:
22742284
description: ServiceAccountRoleArn is the ARN of an IAM role
22752285
to bind to the addons service account
@@ -3116,12 +3126,6 @@ spec:
31163126
description: Partition is the AWS security partition being used. Defaults
31173127
to "aws"
31183128
type: string
3119-
preserveAddons:
3120-
default: false
3121-
description: |-
3122-
PreserveAddons is used to set configuration options for preserving EKS addons
3123-
If you set this value to true and remove an addon from the spec, it will not be deleted from the cluster.
3124-
type: boolean
31253129
region:
31263130
description: The AWS Region the cluster lives in.
31273131
type: string

controlplane/eks/api/v1beta1/conversion.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,6 @@ func (r *AWSManagedControlPlane) ConvertTo(dstRaw conversion.Hub) error {
121121
dst.Spec.RolePermissionsBoundary = restored.Spec.RolePermissionsBoundary
122122
dst.Status.Version = restored.Status.Version
123123
dst.Spec.BootstrapSelfManagedAddons = restored.Spec.BootstrapSelfManagedAddons
124-
dst.Spec.PreserveAddons = restored.Spec.PreserveAddons
125124
return nil
126125
}
127126

controlplane/eks/api/v1beta1/types.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,10 @@ type Addon struct {
141141
// ServiceAccountRoleArn is the ARN of an IAM role to bind to the addons service account
142142
// +optional
143143
ServiceAccountRoleArn *string `json:"serviceAccountRoleARN,omitempty"`
144+
// PreserveOnDelete indicates that the addon resources should be
145+
// preserved in the cluster on delete.
146+
// +optional
147+
PreserveOnDelete bool `json:"preserveOnDelete,omitempty"`
144148
}
145149

146150
// AddonResolution defines the method for resolving parameter conflicts.

controlplane/eks/api/v1beta1/zz_generated.conversion.go

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

controlplane/eks/api/v1beta2/awsmanagedcontrolplane_types.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -202,11 +202,6 @@ type AWSManagedControlPlaneSpec struct { //nolint: maligned
202202
// +kubebuilder:default=true
203203
BootstrapSelfManagedAddons bool `json:"bootstrapSelfManagedAddons,omitempty"`
204204

205-
// PreserveAddons is used to set configuration options for preserving EKS addons
206-
// If you set this value to true and remove an addon from the spec, it will not be deleted from the cluster.
207-
// +kubebuilder:default=false
208-
PreserveAddons bool `json:"preserveAddons,omitempty"`
209-
210205
// RestrictPrivateSubnets indicates that the EKS control plane should only use private subnets.
211206
// +kubebuilder:default=false
212207
RestrictPrivateSubnets bool `json:"restrictPrivateSubnets,omitempty"`

controlplane/eks/api/v1beta2/awsmanagedcontrolplane_webhook_test.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -85,52 +85,52 @@ func TestDefaultingWebhook(t *testing.T) {
8585
resourceName: "cluster1",
8686
resourceNS: "default",
8787
expectHash: false,
88-
expectSpec: AWSManagedControlPlaneSpec{EKSClusterName: "default_cluster1", IdentityRef: defaultIdentityRef, Bastion: defaultTestBastion, NetworkSpec: defaultNetworkSpec, TokenMethod: &EKSTokenMethodIAMAuthenticator, BootstrapSelfManagedAddons: true, PreserveAddons: false},
88+
expectSpec: AWSManagedControlPlaneSpec{EKSClusterName: "default_cluster1", IdentityRef: defaultIdentityRef, Bastion: defaultTestBastion, NetworkSpec: defaultNetworkSpec, TokenMethod: &EKSTokenMethodIAMAuthenticator, BootstrapSelfManagedAddons: true},
8989
},
9090
{
9191
name: "less than 100 chars, dot in name",
9292
resourceName: "team1.cluster1",
9393
resourceNS: "default",
9494
expectHash: false,
95-
expectSpec: AWSManagedControlPlaneSpec{EKSClusterName: "default_team1_cluster1", IdentityRef: defaultIdentityRef, Bastion: defaultTestBastion, NetworkSpec: defaultNetworkSpec, TokenMethod: &EKSTokenMethodIAMAuthenticator, BootstrapSelfManagedAddons: true, PreserveAddons: false},
95+
expectSpec: AWSManagedControlPlaneSpec{EKSClusterName: "default_team1_cluster1", IdentityRef: defaultIdentityRef, Bastion: defaultTestBastion, NetworkSpec: defaultNetworkSpec, TokenMethod: &EKSTokenMethodIAMAuthenticator, BootstrapSelfManagedAddons: true},
9696
},
9797
{
9898
name: "more than 100 chars",
9999
resourceName: "abcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcde",
100100
resourceNS: "default",
101101
expectHash: true,
102-
expectSpec: AWSManagedControlPlaneSpec{EKSClusterName: "capi_", IdentityRef: defaultIdentityRef, Bastion: defaultTestBastion, NetworkSpec: defaultNetworkSpec, TokenMethod: &EKSTokenMethodIAMAuthenticator, BootstrapSelfManagedAddons: true, PreserveAddons: false},
102+
expectSpec: AWSManagedControlPlaneSpec{EKSClusterName: "capi_", IdentityRef: defaultIdentityRef, Bastion: defaultTestBastion, NetworkSpec: defaultNetworkSpec, TokenMethod: &EKSTokenMethodIAMAuthenticator, BootstrapSelfManagedAddons: true},
103103
},
104104
{
105105
name: "with patch",
106106
resourceName: "cluster1",
107107
resourceNS: "default",
108108
expectHash: false,
109109
spec: AWSManagedControlPlaneSpec{Version: &vV1_17_1},
110-
expectSpec: AWSManagedControlPlaneSpec{EKSClusterName: "default_cluster1", Version: &vV1_17_1, IdentityRef: defaultIdentityRef, Bastion: defaultTestBastion, NetworkSpec: defaultNetworkSpec, TokenMethod: &EKSTokenMethodIAMAuthenticator, BootstrapSelfManagedAddons: true, PreserveAddons: false},
110+
expectSpec: AWSManagedControlPlaneSpec{EKSClusterName: "default_cluster1", Version: &vV1_17_1, IdentityRef: defaultIdentityRef, Bastion: defaultTestBastion, NetworkSpec: defaultNetworkSpec, TokenMethod: &EKSTokenMethodIAMAuthenticator, BootstrapSelfManagedAddons: true},
111111
},
112112
{
113113
name: "with allowed ip on bastion",
114114
resourceName: "cluster1",
115115
resourceNS: "default",
116116
expectHash: false,
117117
spec: AWSManagedControlPlaneSpec{Bastion: infrav1.Bastion{AllowedCIDRBlocks: []string{"100.100.100.100/0"}}},
118-
expectSpec: AWSManagedControlPlaneSpec{EKSClusterName: "default_cluster1", IdentityRef: defaultIdentityRef, Bastion: infrav1.Bastion{AllowedCIDRBlocks: []string{"100.100.100.100/0"}}, NetworkSpec: defaultNetworkSpec, TokenMethod: &EKSTokenMethodIAMAuthenticator, BootstrapSelfManagedAddons: true, PreserveAddons: false},
118+
expectSpec: AWSManagedControlPlaneSpec{EKSClusterName: "default_cluster1", IdentityRef: defaultIdentityRef, Bastion: infrav1.Bastion{AllowedCIDRBlocks: []string{"100.100.100.100/0"}}, NetworkSpec: defaultNetworkSpec, TokenMethod: &EKSTokenMethodIAMAuthenticator, BootstrapSelfManagedAddons: true},
119119
},
120120
{
121121
name: "with CNI on network",
122122
resourceName: "cluster1",
123123
resourceNS: "default",
124124
expectHash: false,
125125
spec: AWSManagedControlPlaneSpec{NetworkSpec: infrav1.NetworkSpec{CNI: &infrav1.CNISpec{}}},
126-
expectSpec: AWSManagedControlPlaneSpec{EKSClusterName: "default_cluster1", IdentityRef: defaultIdentityRef, Bastion: defaultTestBastion, NetworkSpec: infrav1.NetworkSpec{CNI: &infrav1.CNISpec{}, VPC: defaultVPCSpec}, TokenMethod: &EKSTokenMethodIAMAuthenticator, BootstrapSelfManagedAddons: true, PreserveAddons: false},
126+
expectSpec: AWSManagedControlPlaneSpec{EKSClusterName: "default_cluster1", IdentityRef: defaultIdentityRef, Bastion: defaultTestBastion, NetworkSpec: infrav1.NetworkSpec{CNI: &infrav1.CNISpec{}, VPC: defaultVPCSpec}, TokenMethod: &EKSTokenMethodIAMAuthenticator, BootstrapSelfManagedAddons: true},
127127
},
128128
{
129129
name: "secondary CIDR",
130130
resourceName: "cluster1",
131131
resourceNS: "default",
132132
expectHash: false,
133-
expectSpec: AWSManagedControlPlaneSpec{EKSClusterName: "default_cluster1", IdentityRef: defaultIdentityRef, Bastion: defaultTestBastion, NetworkSpec: defaultNetworkSpec, SecondaryCidrBlock: nil, TokenMethod: &EKSTokenMethodIAMAuthenticator, BootstrapSelfManagedAddons: true, PreserveAddons: false},
133+
expectSpec: AWSManagedControlPlaneSpec{EKSClusterName: "default_cluster1", IdentityRef: defaultIdentityRef, Bastion: defaultTestBastion, NetworkSpec: defaultNetworkSpec, SecondaryCidrBlock: nil, TokenMethod: &EKSTokenMethodIAMAuthenticator, BootstrapSelfManagedAddons: true},
134134
},
135135
}
136136

controlplane/eks/api/v1beta2/types.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,10 @@ type Addon struct {
141141
// ServiceAccountRoleArn is the ARN of an IAM role to bind to the addons service account
142142
// +optional
143143
ServiceAccountRoleArn *string `json:"serviceAccountRoleARN,omitempty"`
144+
// PreserveOnDelete indicates that the addon resources should be
145+
// preserved in the cluster on delete.
146+
// +optional
147+
PreserveOnDelete bool `json:"preserveOnDelete,omitempty"`
144148
}
145149

146150
// AddonResolution defines the method for resolving parameter conflicts.

pkg/cloud/scope/managedcontrolplane.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -430,11 +430,6 @@ func (s *ManagedControlPlaneScope) BootstrapSelfManagedAddons() *bool {
430430
return &s.ControlPlane.Spec.BootstrapSelfManagedAddons
431431
}
432432

433-
// PreserveAddons returns whether the AWS EKS addons should be preserved in the case of removal from the manifest.
434-
func (s *ManagedControlPlaneScope) PreserveAddons() *bool {
435-
return &s.ControlPlane.Spec.PreserveAddons
436-
}
437-
438433
// VpcCni returns a list of environment variables to apply to the `aws-node` DaemonSet.
439434
func (s *ManagedControlPlaneScope) VpcCni() ekscontrolplanev1.VpcCni {
440435
return s.ControlPlane.Spec.VpcCni

pkg/cloud/services/eks/addons.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ func (s *Service) reconcileAddons(ctx context.Context) error {
6262

6363
// Compute operations to move installed to desired
6464
s.scope.Debug("creating eks addons plan", "cluster", eksClusterName, "numdesired", len(desiredAddons), "numinstalled", len(installed))
65-
addonsPlan := eksaddons.NewPlan(eksClusterName, desiredAddons, installed, s.EKSClient, s.scope.MaxWaitActiveUpdateDelete, *s.scope.PreserveAddons())
65+
addonsPlan := eksaddons.NewPlan(eksClusterName, desiredAddons, installed, s.EKSClient, s.scope.MaxWaitActiveUpdateDelete)
6666
procedures, err := addonsPlan.Create(ctx)
6767
if err != nil {
6868
s.scope.Error(err, "failed creating eks addons plane")

pkg/eks/addons/plan.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,13 @@ import (
2828
)
2929

3030
// NewPlan creates a new Plan to manage EKS addons.
31-
func NewPlan(clusterName string, desiredAddons, installedAddons []*EKSAddon, client eks.Client, maxWait time.Duration, preserveOnDelete bool) planner.Plan {
31+
func NewPlan(clusterName string, desiredAddons, installedAddons []*EKSAddon, client eks.Client, maxWait time.Duration) planner.Plan {
3232
return &plan{
3333
installedAddons: installedAddons,
3434
desiredAddons: desiredAddons,
3535
eksClient: client,
3636
clusterName: clusterName,
3737
maxWaitActiveUpdateDelete: maxWait,
38-
preserveOnDelete: preserveOnDelete,
3938
}
4039
}
4140

@@ -46,7 +45,6 @@ type plan struct {
4645
eksClient eks.Client
4746
clusterName string
4847
maxWaitActiveUpdateDelete time.Duration
49-
preserveOnDelete bool
5048
}
5149

5250
// Create will create the plan (i.e. list of procedures) for managing EKS addons.
@@ -88,7 +86,7 @@ func (a *plan) Create(_ context.Context) ([]planner.Procedure, error) {
8886
desired := a.getDesired(*installed.Name)
8987
if desired == nil {
9088
if *installed.Status != string(ekstypes.AddonStatusDeleting) {
91-
procedures = append(procedures, &DeleteAddonProcedure{plan: a, name: *installed.Name})
89+
procedures = append(procedures, &DeleteAddonProcedure{plan: a, name: *installed.Name, preserve: installed.Preserve})
9290
}
9391
procedures = append(procedures, &WaitAddonDeleteProcedure{plan: a, name: *installed.Name})
9492
}

0 commit comments

Comments
 (0)