Skip to content

Commit

Permalink
Add functionality for resolveConflicts: PRESERVE
Browse files Browse the repository at this point in the history
  • Loading branch information
edmondceausu committed Feb 4, 2025
1 parent f3ba287 commit ef40f66
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ spec:
enum:
- overwrite
- none
- preserve
type: string
name:
description: Name is the name of the addon
Expand Down
4 changes: 4 additions & 0 deletions controlplane/eks/api/v1beta1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,10 @@ var (
// AddonResolutionNone indicates that if there are parameter conflicts then
// resolution will not be done and an error will be reported.
AddonResolutionNone = AddonResolution("none")

// AddonResolutionPreserve indicates that if there are parameter conflicts then
// resolution will result in preserving the existing value
AddonResolutionPreserve = AddonResolution("preserve")
)

// AddonStatus defines the status for an addon.
Expand Down
4 changes: 4 additions & 0 deletions controlplane/eks/api/v1beta2/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,10 @@ var (
// AddonResolutionNone indicates that if there are parameter conflicts then
// resolution will not be done and an error will be reported.
AddonResolutionNone = AddonResolution("none")

// AddonResolutionPreserve indicates that if there are parameter conflicts then
// resolution will result in preserving the existing value
AddonResolutionPreserve = AddonResolution("preserve")
)

// AddonStatus defines the status for an addon.
Expand Down
13 changes: 11 additions & 2 deletions docs/book/src/topics/eks/addons.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,15 @@ spec:
conflictResolution: "overwrite"
```
_Note_: For `conflictResolution` `overwrite` is the **default** behaviour. That means, if not otherwise specified, it's
set to `overwrite`.
Valid values are:
```
none
overwrite
preserve
```

_Note_: For `conflictResolution` `none` is the **default** behaviour. That means, if not otherwise specified, it's
set to `none`. Review [API Documentation](https://docs.aws.amazon.com/eks/latest/APIReference/API_CreateAddon.html#AmazonEKS-CreateAddon-request-resolveConflicts) for detailed behavior.

Additionally, there is a cluster [flavor](https://cluster-api.sigs.k8s.io/clusterctl/commands/generate-cluster.html#flavors)
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**:
Expand All @@ -46,6 +53,8 @@ To update the version of an addon you need to edit the `AWSManagedControlPlane`
...
```

_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.

## Deleting Addons

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.
Expand Down
24 changes: 19 additions & 5 deletions pkg/cloud/services/eks/addons.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,12 +194,16 @@ func (s *Service) translateAPIToAddon(addons []ekscontrolplanev1.Addon) []*eksad

for i := range addons {
addon := addons[i]
conflict, err := convertConflictResolution(*addon.ConflictResolution)
if err != nil {
s.scope.Error(err, err.Error())
}
convertedAddon := &eksaddons.EKSAddon{
Name: &addon.Name,
Version: &addon.Version,
Configuration: &addon.Configuration,
Tags: ngTags(s.scope.Cluster.Name, s.scope.AdditionalTags()),
ResolveConflict: convertConflictResolution(*addon.ConflictResolution),
ResolveConflict: conflict,
ServiceAccountRoleARN: addon.ServiceAccountRoleArn,
}

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

func convertConflictResolution(conflict ekscontrolplanev1.AddonResolution) *string {
if conflict == ekscontrolplanev1.AddonResolutionNone {
return aws.String(eks.ResolveConflictsNone)
func convertConflictResolution(conflict ekscontrolplanev1.AddonResolution) (*string, error) {
switch conflict {
case ekscontrolplanev1.AddonResolutionNone:
return aws.String(eks.ResolveConflictsNone), nil

case ekscontrolplanev1.AddonResolutionOverwrite:
return aws.String(eks.ResolveConflictsOverwrite), nil

case ekscontrolplanev1.AddonResolutionPreserve:
return aws.String(eks.ResolveConflictsPreserve), nil

default:
return aws.String(eks.ResolveConflictsNone), fmt.Errorf("failed to determine adddonResolution; defaulting to None")

}

Check failure on line 230 in pkg/cloud/services/eks/addons.go

View workflow job for this annotation

GitHub Actions / lint

unnecessary trailing newline (whitespace)
return aws.String(eks.ResolveConflictsOverwrite)
}

0 comments on commit ef40f66

Please sign in to comment.