Skip to content

Commit 4df1908

Browse files
authored
✨ Addons: Add functionality for resolveConflicts: PRESERVE (#5330)
* Add functionality for resolveConflicts: PRESERVE fixes for test to pass removed v1beta1 support * make generate * updated documentation and code to reflect kubebuilder behavior * fixed rebase errors * make generate after rebase
1 parent 47820e4 commit 4df1908

File tree

5 files changed

+39
-13
lines changed

5 files changed

+39
-13
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2228,10 +2228,11 @@ spec:
22282228
default: overwrite
22292229
description: |-
22302230
ConflictResolution is used to declare what should happen if there
2231-
are parameter conflicts. Defaults to none
2231+
are parameter conflicts. Defaults to overwrite
22322232
enum:
22332233
- overwrite
22342234
- none
2235+
- preserve
22352236
type: string
22362237
name:
22372238
description: Name is the name of the addon

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,11 @@ spec:
7373
default: overwrite
7474
description: |-
7575
ConflictResolution is used to declare what should happen if there
76-
are parameter conflicts. Defaults to none
76+
are parameter conflicts. Defaults to overwrite
7777
enum:
7878
- overwrite
7979
- none
80+
- preserve
8081
type: string
8182
name:
8283
description: Name is the name of the addon

controlplane/eks/api/v1beta2/types.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,9 +134,9 @@ type Addon struct {
134134
// +optional
135135
Configuration string `json:"configuration,omitempty"`
136136
// ConflictResolution is used to declare what should happen if there
137-
// are parameter conflicts. Defaults to none
137+
// are parameter conflicts. Defaults to overwrite
138138
// +kubebuilder:default=overwrite
139-
// +kubebuilder:validation:Enum=overwrite;none
139+
// +kubebuilder:validation:Enum=overwrite;none;preserve
140140
ConflictResolution *AddonResolution `json:"conflictResolution,omitempty"`
141141
// ServiceAccountRoleArn is the ARN of an IAM role to bind to the addons service account
142142
// +optional
@@ -154,6 +154,10 @@ var (
154154
// AddonResolutionNone indicates that if there are parameter conflicts then
155155
// resolution will not be done and an error will be reported.
156156
AddonResolutionNone = AddonResolution("none")
157+
158+
// AddonResolutionPreserve indicates that if there are parameter conflicts then
159+
// resolution will result in preserving the existing value
160+
AddonResolutionPreserve = AddonResolution("preserve")
157161
)
158162

159163
// AddonStatus defines the status for an addon.

docs/book/src/topics/eks/addons.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,15 @@ spec:
2323
conflictResolution: "overwrite"
2424
```
2525
26+
Valid values are:
27+
```
28+
none
29+
overwrite
30+
preserve
31+
```
32+
2633
_Note_: For `conflictResolution` `overwrite` is the **default** behaviour. That means, if not otherwise specified, it's
27-
set to `overwrite`.
34+
set to `overwrite`. Review [API Documentation](https://docs.aws.amazon.com/eks/latest/APIReference/API_CreateAddon.html#AmazonEKS-CreateAddon-request-resolveConflicts) for detailed behavior.
2835

2936
Additionally, there is a cluster [flavor](https://cluster-api.sigs.k8s.io/clusterctl/commands/generate-cluster.html#flavors)
3037
called [eks-managedmachinepool-vpccni](https://github.com/kubernetes-sigs/cluster-api-provider-aws/blob/main/templates/cluster-template-eks-managedmachinepool-vpccni.yaml) that you can use with **clusterctl**:
@@ -46,6 +53,8 @@ To update the version of an addon you need to edit the `AWSManagedControlPlane`
4653
...
4754
```
4855

56+
_Note_: For `conflictResolution` `none`, updating may fail if a change was made to the addon that is unexpected by EKS. Review [API Documentation](https://docs.aws.amazon.com/eks/latest/APIReference/API_UpdateAddon.html#AmazonEKS-UpdateAddon-request-resolveConflicts) for detailed behavior on conflict resolution.
57+
4958
## Deleting Addons
5059

5160
To delete an addon from a cluster you need to edit the `AWSManagedControlPlane` instance and remove the entry for the addon you want to delete.

pkg/cloud/services/eks/addons.go

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -196,12 +196,16 @@ func (s *Service) translateAPIToAddon(addons []ekscontrolplanev1.Addon) []*eksad
196196

197197
for i := range addons {
198198
addon := addons[i]
199+
conflict, err := convertConflictResolution(*addon.ConflictResolution)
200+
if err != nil {
201+
s.scope.Error(err, err.Error())
202+
}
199203
convertedAddon := &eksaddons.EKSAddon{
200204
Name: &addon.Name,
201205
Version: &addon.Version,
202206
Configuration: convertConfiguration(addon.Configuration),
203207
Tags: ngTags(s.scope.Cluster.Name, s.scope.AdditionalTags()),
204-
ResolveConflict: convertConflictResolution(*addon.ConflictResolution),
208+
ResolveConflict: conflict,
205209
ServiceAccountRoleARN: addon.ServiceAccountRoleArn,
206210
}
207211

@@ -220,14 +224,21 @@ func (k *EKSClient) WaitUntilAddonDeleted(ctx context.Context, input *eks.Descri
220224
return waiter.Wait(ctx, input, maxWait)
221225
}
222226

223-
func convertConflictResolution(conflict ekscontrolplanev1.AddonResolution) *string {
224-
if conflict == ekscontrolplanev1.AddonResolutionNone {
225-
res := string(ekstypes.ResolveConflictsNone)
226-
return aws.String(res)
227-
}
227+
func convertConflictResolution(conflict ekscontrolplanev1.AddonResolution) (*string, error) {
228+
switch conflict {
229+
case ekscontrolplanev1.AddonResolutionNone:
230+
return aws.String(string(ekstypes.ResolveConflictsNone)), nil
228231

229-
res := string(ekstypes.ResolveConflictsOverwrite)
230-
return aws.String(res)
232+
case ekscontrolplanev1.AddonResolutionOverwrite:
233+
return aws.String(string(ekstypes.ResolveConflictsOverwrite)), nil
234+
235+
case ekscontrolplanev1.AddonResolutionPreserve:
236+
return aws.String(string(ekstypes.ResolveConflictsPreserve)), nil
237+
238+
// Defaulting to behavior "Overwrite" as documented
239+
default:
240+
return aws.String(string(ekstypes.ResolveConflictsOverwrite)), fmt.Errorf("failed to determine adddonResolution; defaulting to Overwrite")
241+
}
231242
}
232243

233244
func convertConfiguration(configuration string) *string {

0 commit comments

Comments
 (0)