Skip to content

Commit e38f537

Browse files
authored
Ignore Node Version and EKS Version check if AMI Type is bottlerocket (#179)
Issue #, if available: - aws-controllers-k8s/community#2644 Description of changes: Since the bottlerocket versions don't align with EKS Versions, we should ignore the check of comparing nodeversion and eks version. Otherwise, it will result in error similar to `version and release version do not match: 1.32 and 1.47` By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
1 parent c5f0dd6 commit e38f537

File tree

2 files changed

+83
-15
lines changed

2 files changed

+83
-15
lines changed

pkg/resource/nodegroup/hook.go

Lines changed: 33 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818
"fmt"
1919
"reflect"
2020
"strconv"
21+
"strings"
2122
"time"
2223

2324
ackcompare "github.com/aws-controllers-k8s/runtime/pkg/compare"
@@ -330,22 +331,24 @@ func (rm *resourceManager) customUpdate(
330331
if desired.ko.Spec.Version != nil && desired.ko.Spec.ReleaseVersion != nil &&
331332
*desired.ko.Spec.Version != "" && *desired.ko.Spec.ReleaseVersion != "" {
332333

333-
// First parse the user provided release version and desired release
334-
desiredReleaseVersionTrimmed, err := util.GetEKSVersionFromReleaseVersion(*desired.ko.Spec.ReleaseVersion)
335-
if err != nil {
336-
return nil, ackerr.NewTerminalError(err)
337-
}
334+
if !isAMITypeBottlerocket(desired.ko.Spec.AMIType) {
335+
// First parse the user provided release version and desired release
336+
desiredReleaseVersionTrimmed, err := util.GetEKSVersionFromReleaseVersion(*desired.ko.Spec.ReleaseVersion)
337+
if err != nil {
338+
return nil, ackerr.NewTerminalError(err)
339+
}
338340

339-
// Set a terminal condition if the release version and version do not match.
340-
// e.g if the user provides a release version of 1.16.8-20211201 and a version of 1.17
341-
// They will either need to provide one of the following:
342-
// 2. A version
343-
// 1. A release version
344-
// 3. A version and release version that matches (e.g 1.16 and 1.16.8-20211201)
345-
if desiredReleaseVersionTrimmed != *desired.ko.Spec.Version {
346-
return nil, ackerr.NewTerminalError(
347-
fmt.Errorf("version and release version do not match: %s and %s", *desired.ko.Spec.Version, desiredReleaseVersionTrimmed),
348-
)
341+
// Set a terminal condition if the release version and version do not match.
342+
// e.g if the user provides a release version of 1.16.8-20211201 and a version of 1.17
343+
// They will either need to provide one of the following:
344+
// 2. A version
345+
// 1. A release version
346+
// 3. A version and release version that matches (e.g 1.16 and 1.16.8-20211201)
347+
if desiredReleaseVersionTrimmed != *desired.ko.Spec.Version {
348+
return nil, ackerr.NewTerminalError(
349+
fmt.Errorf("version and release version do not match: %s and %s", *desired.ko.Spec.Version, desiredReleaseVersionTrimmed),
350+
)
351+
}
349352
}
350353
}
351354

@@ -359,6 +362,21 @@ func (rm *resourceManager) customUpdate(
359362
return updatedRes, nil
360363
}
361364

365+
// Bottlerocket AMI types do not follow the same versioning scheme as other AMI types.
366+
// For more information, see https://github.com/awslabs/amazon-eks-ami/releases
367+
// and https://github.com/bottlerocket-os/bottlerocket/releases
368+
func isAMITypeBottlerocket(amiType *string) bool {
369+
if amiType == nil {
370+
return false
371+
}
372+
373+
if strings.HasPrefix(*amiType, "BOTTLEROCKET_") {
374+
return true
375+
}
376+
377+
return false
378+
}
379+
362380
// newUpdateLabelsPayload determines which of the labels should be added or
363381
// updated, and which labels should be removed, based on the desired vs the
364382
// latest

pkg/resource/nodegroup/hook_test.go

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -550,3 +550,53 @@ func Test_newUpdateNodegroupPayload(t *testing.T) {
550550
})
551551
}
552552
}
553+
554+
func Test_AMITypeBottlerocket(t *testing.T) {
555+
tests := []struct {
556+
name string
557+
amiType *string
558+
want bool
559+
}{
560+
{
561+
name: "nil ami type",
562+
amiType: nil,
563+
want: false,
564+
},
565+
{
566+
name: "BOTTLEROCKET_ARM_64 AMI",
567+
amiType: aws.String("BOTTLEROCKET_ARM_64"),
568+
want: true,
569+
},
570+
{
571+
name: "BOTTLEROCKET_ARM_64_NVIDIA AMI",
572+
amiType: aws.String("BOTTLEROCKET_ARM_64_NVIDIA"),
573+
want: true,
574+
},
575+
{
576+
name: "BOTTLEROCKET_x86_64 AMI",
577+
amiType: aws.String("BOTTLEROCKET_x86_64"),
578+
want: true,
579+
},
580+
{
581+
name: "BOTTLEROCKET_x86_64_FIPS AMI",
582+
amiType: aws.String("BOTTLEROCKET_x86_64_FIPS"),
583+
want: true,
584+
},
585+
{
586+
name: "BOTTLEROCKET_x86_64_NVIDIA AMI",
587+
amiType: aws.String("BOTTLEROCKET_x86_64_NVIDIA"),
588+
want: true,
589+
},
590+
{
591+
name: "RANDOM AMI",
592+
amiType: aws.String("RANDOM"),
593+
want: false,
594+
},
595+
}
596+
597+
for _, tt := range tests {
598+
t.Run(tt.name, func(t *testing.T) {
599+
assert.Equal(t, tt.want, isAMITypeBottlerocket(tt.amiType))
600+
})
601+
}
602+
}

0 commit comments

Comments
 (0)