Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ feat(addons): add updateAddonTagsWithLatestVersion to set addon tags to latest version #5210

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -924,6 +924,8 @@ func mockedEKSCluster(g *WithT, eksRec *mock_eksiface.MockEKSAPIMockRecorder, ia
ClusterName: aws.String("test-cluster"),
}).Return(&eks.ListAddonsOutput{}, nil)

eksRec.DescribeAddonVersions(&eks.DescribeAddonVersionsInput{}).Return(&eks.DescribeAddonVersionsOutput{}, nil)

awsNodeRec.ReconcileCNI(gomock.Any()).Return(nil)
kubeProxyRec.ReconcileKubeProxy(gomock.Any()).Return(nil)
iamAuthenticatorRec.ReconcileIAMAuthenticator(gomock.Any()).Return(nil)
Expand Down
44 changes: 44 additions & 0 deletions pkg/cloud/services/eks/addons.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ func (s *Service) reconcileAddons(ctx context.Context) error {
// Get the addons from the spec we want for the cluster
desiredAddons := s.translateAPIToAddon(s.scope.Addons())

// Update the tags with the latest version if available
if desiredAddons, err = s.updateAddonTagsWithLatestVersion(desiredAddons); err != nil {
return fmt.Errorf("updating addon tags with latest version: %w", err)
}

// If there are no addons desired or installed then do nothing
if len(installed) == 0 && len(desiredAddons) == 0 {
s.scope.Info("no addons installed and no addons to install, no action needed")
Expand Down Expand Up @@ -209,6 +214,45 @@ func (s *Service) translateAPIToAddon(addons []ekscontrolplanev1.Addon) []*eksad
return converted
}

func (s *Service) updateAddonTagsWithLatestVersion(addons []*eksaddons.EKSAddon) ([]*eksaddons.EKSAddon, error) {
s.Debug("Updating addon tags with the latest available version")

input := &eks.DescribeAddonVersionsInput{
KubernetesVersion: s.scope.ControlPlane.Spec.Version,
}

output, err := s.EKSClient.DescribeAddonVersions(input)
if err != nil {
return nil, fmt.Errorf("error describing addon versions: %w", err)
}
if len(output.Addons) == 0 {
s.Debug("No addons found for the specified Kubernetes version")
return addons, nil
}

latestVersions := make(map[string]string)
for _, addon := range output.Addons {
if len(addon.AddonVersions) > 0 {
latestVersions[*addon.AddonName] = *addon.AddonVersions[0].AddonVersion
for _, version := range addon.AddonVersions[1:] {
if *version.AddonVersion > latestVersions[*addon.AddonName] {
latestVersions[*addon.AddonName] = *version.AddonVersion
}
}
}
}

for _, addon := range addons {
if addon.Version != nil && *addon.Version == "latest" {
if latestVersion, ok := latestVersions[*addon.Name]; ok {
addon.Version = &latestVersion
}
}
}

return addons, nil
}

func convertConflictResolution(conflict ekscontrolplanev1.AddonResolution) *string {
if conflict == ekscontrolplanev1.AddonResolutionNone {
return aws.String(eks.ResolveConflictsNone)
Expand Down