Skip to content

Commit 9ffe698

Browse files
committed
add update version force annotation
1 parent cd13360 commit 9ffe698

File tree

4 files changed

+90
-12
lines changed

4 files changed

+90
-12
lines changed

go.mod

+4-4
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ require (
1010
github.com/aws-controllers-k8s/kms-controller v1.0.9
1111
github.com/aws-controllers-k8s/runtime v0.43.0
1212
github.com/aws/aws-sdk-go v1.55.5
13-
github.com/aws/aws-sdk-go-v2 v1.33.0
14-
github.com/aws/aws-sdk-go-v2/service/eks v1.56.5
13+
github.com/aws/aws-sdk-go-v2 v1.36.3
14+
github.com/aws/aws-sdk-go-v2/service/eks v1.63.0
1515
github.com/aws/smithy-go v1.22.2
1616
github.com/go-logr/logr v1.4.2
1717
github.com/spf13/pflag v1.0.5
@@ -26,8 +26,8 @@ require (
2626
github.com/aws/aws-sdk-go-v2/config v1.28.6 // indirect
2727
github.com/aws/aws-sdk-go-v2/credentials v1.17.47 // indirect
2828
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.16.21 // indirect
29-
github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.28 // indirect
30-
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.28 // indirect
29+
github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.34 // indirect
30+
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.34 // indirect
3131
github.com/aws/aws-sdk-go-v2/internal/ini v1.8.1 // indirect
3232
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.12.1 // indirect
3333
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.12.6 // indirect

go.sum

+8-8
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,22 @@ github.com/aws-controllers-k8s/runtime v0.43.0 h1:mCtMHO0rew84VbqotquvBirnKysbao
88
github.com/aws-controllers-k8s/runtime v0.43.0/go.mod h1:Oy0JKvDxZMZ+SVupm4NZVqP00KLIIAMfk93KnOwlt5c=
99
github.com/aws/aws-sdk-go v1.55.5 h1:KKUZBfBoyqy5d3swXyiC7Q76ic40rYcbqH7qjh59kzU=
1010
github.com/aws/aws-sdk-go v1.55.5/go.mod h1:eRwEWoyTWFMVYVQzKMNHWP5/RV4xIUGMQfXQHfHkpNU=
11-
github.com/aws/aws-sdk-go-v2 v1.33.0 h1:Evgm4DI9imD81V0WwD+TN4DCwjUMdc94TrduMLbgZJs=
12-
github.com/aws/aws-sdk-go-v2 v1.33.0/go.mod h1:P5WJBrYqqbWVaOxgH0X/FYYD47/nooaPOZPlQdmiN2U=
11+
github.com/aws/aws-sdk-go-v2 v1.36.3 h1:mJoei2CxPutQVxaATCzDUjcZEjVRdpsiiXi2o38yqWM=
12+
github.com/aws/aws-sdk-go-v2 v1.36.3/go.mod h1:LLXuLpgzEbD766Z5ECcRmi8AzSwfZItDtmABVkRLGzg=
1313
github.com/aws/aws-sdk-go-v2/config v1.28.6 h1:D89IKtGrs/I3QXOLNTH93NJYtDhm8SYa9Q5CsPShmyo=
1414
github.com/aws/aws-sdk-go-v2/config v1.28.6/go.mod h1:GDzxJ5wyyFSCoLkS+UhGB0dArhb9mI+Co4dHtoTxbko=
1515
github.com/aws/aws-sdk-go-v2/credentials v1.17.47 h1:48bA+3/fCdi2yAwVt+3COvmatZ6jUDNkDTIsqDiMUdw=
1616
github.com/aws/aws-sdk-go-v2/credentials v1.17.47/go.mod h1:+KdckOejLW3Ks3b0E3b5rHsr2f9yuORBum0WPnE5o5w=
1717
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.16.21 h1:AmoU1pziydclFT/xRV+xXE/Vb8fttJCLRPv8oAkprc0=
1818
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.16.21/go.mod h1:AjUdLYe4Tgs6kpH4Bv7uMZo7pottoyHMn4eTcIcneaY=
19-
github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.28 h1:igORFSiH3bfq4lxKFkTSYDhJEUCYo6C8VKiWJjYwQuQ=
20-
github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.28/go.mod h1:3So8EA/aAYm36L7XIvCVwLa0s5N0P7o2b1oqnx/2R4g=
21-
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.28 h1:1mOW9zAUMhTSrMDssEHS/ajx8JcAj/IcftzcmNlmVLI=
22-
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.28/go.mod h1:kGlXVIWDfvt2Ox5zEaNglmq0hXPHgQFNMix33Tw22jA=
19+
github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.34 h1:ZK5jHhnrioRkUNOc+hOgQKlUL5JeC3S6JgLxtQ+Rm0Q=
20+
github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.34/go.mod h1:p4VfIceZokChbA9FzMbRGz5OV+lekcVtHlPKEO0gSZY=
21+
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.34 h1:SZwFm17ZUNNg5Np0ioo/gq8Mn6u9w19Mri8DnJ15Jf0=
22+
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.34/go.mod h1:dFZsC0BLo346mvKQLWmoJxT+Sjp+qcVR1tRVHQGOH9Q=
2323
github.com/aws/aws-sdk-go-v2/internal/ini v1.8.1 h1:VaRN3TlFdd6KxX1x3ILT5ynH6HvKgqdiXoTxAF4HQcQ=
2424
github.com/aws/aws-sdk-go-v2/internal/ini v1.8.1/go.mod h1:FbtygfRFze9usAadmnGJNc8KsP346kEe+y2/oyhGAGc=
25-
github.com/aws/aws-sdk-go-v2/service/eks v1.56.5 h1:AoVtICtIPSSgRJzNhT5A6IAP9kNbah2jJu1MAnBkHtM=
26-
github.com/aws/aws-sdk-go-v2/service/eks v1.56.5/go.mod h1:6gWwo7rT4qfYVHwJnj0nUM4DP+XuURcTO+89H8dCvrM=
25+
github.com/aws/aws-sdk-go-v2/service/eks v1.63.0 h1:LZ6pECjK8oNZbgtc5Gtmt7VzVjXyUgqPsatXcEZQyqM=
26+
github.com/aws/aws-sdk-go-v2/service/eks v1.63.0/go.mod h1:v1xXy6ea0PHtWkjFUvAUh6B/5wv7UF909Nru0dOIJDk=
2727
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.12.1 h1:iXtILhvDxB6kPvEXgsDhGaZCSC6LQET5ZHSdJozeI0Y=
2828
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.12.1/go.mod h1:9nu0fVANtYiAePIBh2/pFUSwtJ402hLnp854CNoDOeE=
2929
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.12.6 h1:50+XsN70RS7dwJ2CkVNXzj7U2L1HKP8nqTd3XWEXBN4=

pkg/resource/cluster/hook.go

+33
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import (
1717
"context"
1818
"errors"
1919
"fmt"
20+
"strconv"
2021
"time"
2122

2223
ackcompare "github.com/aws-controllers-k8s/runtime/pkg/compare"
@@ -29,6 +30,7 @@ import (
2930
svcsdktypes "github.com/aws/aws-sdk-go-v2/service/eks/types"
3031
"github.com/aws/smithy-go"
3132
corev1 "k8s.io/api/core/v1"
33+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
3234

3335
"github.com/aws-controllers-k8s/eks-controller/pkg/tags"
3436
"github.com/aws-controllers-k8s/eks-controller/pkg/util"
@@ -49,6 +51,36 @@ const (
4951
StatusPending = "PENDING"
5052
)
5153

54+
const (
55+
// AnnotationPrefix is the prefix for all annotations specifically for
56+
// the EKS service.
57+
AnnotationPrefix = "eks.services.k8s.aws/"
58+
// AnnotationForceUpgrade is an annotation whose value indicates whether
59+
// the cluster version upgrade should be forced even if there are cluster insight findings.
60+
AnnotationForceUpgrade = AnnotationPrefix + "force-upgrade"
61+
62+
DefaultForceUpgrade = false
63+
)
64+
65+
// GetForceUpgrade returns whether the cluster version upgrade should be forced
66+
// as determined by the annotation on the object, or the default value otherwise.
67+
func GetForceUpgrade(
68+
m *metav1.ObjectMeta,
69+
) bool {
70+
resAnnotations := m.GetAnnotations()
71+
forceUpgrade, ok := resAnnotations[AnnotationForceUpgrade]
72+
if !ok {
73+
return DefaultForceUpgrade
74+
}
75+
76+
forceUpgradeBool, err := strconv.ParseBool(forceUpgrade)
77+
if err != nil {
78+
return DefaultForceUpgrade
79+
}
80+
81+
return forceUpgradeBool
82+
}
83+
5284
var (
5385
// TerminalStatuses are the status strings that are terminal states for a
5486
// cluster.
@@ -438,6 +470,7 @@ func (rm *resourceManager) updateVersion(
438470
input := &svcsdk.UpdateClusterVersionInput{
439471
Name: desired.ko.Spec.Name,
440472
Version: &nextVersion,
473+
Force: GetForceUpgrade(&desired.ko.ObjectMeta),
441474
}
442475

443476
_, err = rm.sdkapi.UpdateClusterVersion(ctx, input)

test/e2e/tests/test_cluster.py

+45
Original file line numberDiff line numberDiff line change
@@ -449,3 +449,48 @@ def test_cluster_adopt_update(self, eks_client, adoption_cluster):
449449
assert aws_res
450450
assert aws_res["cluster"]["upgradePolicy"]["supportType"] == support_type
451451

452+
def test_force_upgrade_annotation(self, eks_client, simple_cluster_version_minus_2):
453+
(ref, cr) = simple_cluster_version_minus_2
454+
cluster_name = cr["spec"]["name"]
455+
456+
try:
457+
aws_res = eks_client.describe_cluster(name=cluster_name)
458+
assert aws_res is not None
459+
except eks_client.exceptions.ResourceNotFoundException:
460+
pytest.fail(f"Could not find cluster '{cluster_name}' in EKS")
461+
462+
wait_for_cluster_active(eks_client, cluster_name)
463+
464+
# Add force upgrade annotation and update version
465+
updates = {
466+
"metadata": {
467+
"annotations": {
468+
"eks.services.k8s.aws/force-upgrade": "true"
469+
}
470+
},
471+
"spec": {
472+
"version": "1.29"
473+
}
474+
}
475+
k8s.patch_custom_resource(ref, updates)
476+
time.sleep(MODIFY_WAIT_AFTER_SECONDS)
477+
478+
get_and_assert_status(ref, 'UPDATING', False)
479+
wait_for_cluster_active(eks_client, cluster_name)
480+
481+
# At this point, the cluster should be active at version 1.28 (first increment)
482+
aws_res = eks_client.describe_cluster(name=cluster_name)
483+
assert aws_res["cluster"]["version"] == "1.28"
484+
485+
time.sleep(CHECK_STATUS_WAIT_SECONDS*1.5)
486+
get_and_assert_status(ref, 'UPDATING', False)
487+
488+
wait_for_cluster_active(eks_client, cluster_name)
489+
time.sleep(CHECK_STATUS_WAIT_SECONDS*1.5)
490+
491+
# The cluster should now be at version 1.29
492+
aws_res = eks_client.describe_cluster(name=cluster_name)
493+
assert aws_res["cluster"]["version"] == "1.29"
494+
495+
time.sleep(CHECK_STATUS_WAIT_SECONDS*1.5)
496+
get_and_assert_status(ref, 'ACTIVE', True)

0 commit comments

Comments
 (0)