Skip to content

Commit ef40f66

Browse files
committed
Add functionality for resolveConflicts: PRESERVE
1 parent f3ba287 commit ef40f66

File tree

5 files changed

+39
-7
lines changed

5 files changed

+39
-7
lines changed

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

+1
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ spec:
9191
enum:
9292
- overwrite
9393
- none
94+
- preserve
9495
type: string
9596
name:
9697
description: Name is the name of the addon

controlplane/eks/api/v1beta1/types.go

+4
Original file line numberDiff line numberDiff line change
@@ -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.

controlplane/eks/api/v1beta2/types.go

+4
Original file line numberDiff line numberDiff line change
@@ -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

+11-2
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,15 @@ spec:
2323
conflictResolution: "overwrite"
2424
```
2525
26-
_Note_: For `conflictResolution` `overwrite` is the **default** behaviour. That means, if not otherwise specified, it's
27-
set to `overwrite`.
26+
Valid values are:
27+
```
28+
none
29+
overwrite
30+
preserve
31+
```
32+
33+
_Note_: For `conflictResolution` `none` is the **default** behaviour. That means, if not otherwise specified, it's
34+
set to `none`. 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

+19-5
Original file line numberDiff line numberDiff line change
@@ -194,12 +194,16 @@ func (s *Service) translateAPIToAddon(addons []ekscontrolplanev1.Addon) []*eksad
194194

195195
for i := range addons {
196196
addon := addons[i]
197+
conflict, err := convertConflictResolution(*addon.ConflictResolution)
198+
if err != nil {
199+
s.scope.Error(err, err.Error())
200+
}
197201
convertedAddon := &eksaddons.EKSAddon{
198202
Name: &addon.Name,
199203
Version: &addon.Version,
200204
Configuration: &addon.Configuration,
201205
Tags: ngTags(s.scope.Cluster.Name, s.scope.AdditionalTags()),
202-
ResolveConflict: convertConflictResolution(*addon.ConflictResolution),
206+
ResolveConflict: conflict,
203207
ServiceAccountRoleARN: addon.ServiceAccountRoleArn,
204208
}
205209

@@ -209,9 +213,19 @@ func (s *Service) translateAPIToAddon(addons []ekscontrolplanev1.Addon) []*eksad
209213
return converted
210214
}
211215

212-
func convertConflictResolution(conflict ekscontrolplanev1.AddonResolution) *string {
213-
if conflict == ekscontrolplanev1.AddonResolutionNone {
214-
return aws.String(eks.ResolveConflictsNone)
216+
func convertConflictResolution(conflict ekscontrolplanev1.AddonResolution) (*string, error) {
217+
switch conflict {
218+
case ekscontrolplanev1.AddonResolutionNone:
219+
return aws.String(eks.ResolveConflictsNone), nil
220+
221+
case ekscontrolplanev1.AddonResolutionOverwrite:
222+
return aws.String(eks.ResolveConflictsOverwrite), nil
223+
224+
case ekscontrolplanev1.AddonResolutionPreserve:
225+
return aws.String(eks.ResolveConflictsPreserve), nil
226+
227+
default:
228+
return aws.String(eks.ResolveConflictsNone), fmt.Errorf("failed to determine adddonResolution; defaulting to None")
229+
215230
}
216-
return aws.String(eks.ResolveConflictsOverwrite)
217231
}

0 commit comments

Comments
 (0)