Skip to content

Commit 12b6056

Browse files
committed
Support EKS upgrade policy
1 parent 4728557 commit 12b6056

File tree

11 files changed

+198
-0
lines changed

11 files changed

+198
-0
lines changed

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3196,6 +3196,17 @@ spec:
31963196
- iam-authenticator
31973197
- aws-cli
31983198
type: string
3199+
upgradePolicy:
3200+
description: |-
3201+
The support policy to use for the cluster.
3202+
Extended support indicates that the cluster will not be automatically upgraded
3203+
when it leaves the standard support period, and will enter extended support.
3204+
Clusters in extended support have higher costs.
3205+
The default value is extended. Use standard to disable extended support.
3206+
enum:
3207+
- extended
3208+
- standard
3209+
type: string
31993210
version:
32003211
description: |-
32013212
Version defines the desired Kubernetes version. If no version number

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1022,6 +1022,17 @@ spec:
10221022
- iam-authenticator
10231023
- aws-cli
10241024
type: string
1025+
upgradePolicy:
1026+
description: |-
1027+
The support policy to use for the cluster.
1028+
Extended support indicates that the cluster will not be automatically upgraded
1029+
when it leaves the standard support period, and will enter extended support.
1030+
Clusters in extended support have higher costs.
1031+
The default value is extended. Use standard to disable extended support.
1032+
enum:
1033+
- extended
1034+
- standard
1035+
type: string
10251036
version:
10261037
description: |-
10271038
Version defines the desired Kubernetes version. If no version number

controlplane/eks/api/v1beta1/conversion.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ func (r *AWSManagedControlPlane) ConvertTo(dstRaw conversion.Hub) error {
121121
dst.Spec.RolePermissionsBoundary = restored.Spec.RolePermissionsBoundary
122122
dst.Status.Version = restored.Status.Version
123123
dst.Spec.BootstrapSelfManagedAddons = restored.Spec.BootstrapSelfManagedAddons
124+
dst.Spec.UpgradePolicy = restored.Spec.UpgradePolicy
124125
return nil
125126
}
126127

controlplane/eks/api/v1beta1/zz_generated.conversion.go

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

controlplane/eks/api/v1beta2/awsmanagedcontrolplane_types.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,15 @@ type AWSManagedControlPlaneSpec struct { //nolint: maligned
208208

209209
// KubeProxy defines managed attributes of the kube-proxy daemonset
210210
KubeProxy KubeProxy `json:"kubeProxy,omitempty"`
211+
212+
// The support policy to use for the cluster.
213+
// Extended support indicates that the cluster will not be automatically upgraded
214+
// when it leaves the standard support period, and will enter extended support.
215+
// Clusters in extended support have higher costs.
216+
// The default value is extended. Use standard to disable extended support.
217+
// +kubebuilder:validation:Enum=extended;standard
218+
// +optional
219+
UpgradePolicy *UpgradePolicy `json:"upgradePolicy,omitempty"`
211220
}
212221

213222
// KubeProxy specifies how the kube-proxy daemonset is managed.

controlplane/eks/api/v1beta2/types.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,24 @@ type AddonIssue struct {
220220
ResourceIDs []string `json:"resourceIds,omitempty"`
221221
}
222222

223+
// UpgradePolicy defines the support policy to use for the cluster.
224+
type UpgradePolicy string
225+
226+
var (
227+
// UpgradePolicyExtended indicates that the cluster will not be automatically upgraded
228+
// when it leaves the standard support period, and will enter extended support.
229+
// Clusters in extended support have higher costs.
230+
UpgradePolicyExtended = UpgradePolicy("extended")
231+
232+
// UpgradePolicyStandard indicates that the cluster will be automatically upgraded
233+
// when it leaves the standard support period.
234+
UpgradePolicyStandard = UpgradePolicy("standard")
235+
)
236+
237+
func (e UpgradePolicy) String() string {
238+
return string(e)
239+
}
240+
223241
const (
224242
// SecurityGroupCluster is the security group for communication between EKS
225243
// control plane and managed node groups.

controlplane/eks/api/v1beta2/zz_generated.deepcopy.go

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/book/src/topics/eks/creating-a-cluster.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ clusterctl generate cluster capi-eks-quickstart --flavor eks-managedmachinepool
1414

1515
NOTE: When creating an EKS cluster only the **MAJOR.MINOR** of the `-kubernetes-version` is taken into consideration.
1616

17+
By default, EKS cluster uses:
18+
- EXTENDED support. See more info about [cluster upgrade policy](https://docs.aws.amazon.com/eks/latest/userguide/view-upgrade-policy.html)
19+
1720
## Kubeconfig
1821

1922
When creating an EKS cluster 2 kubeconfigs are generated and stored as secrets in the management cluster. This is different to when you create a non-managed cluster using the AWS provider.

pkg/cloud/converters/eks.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,3 +278,11 @@ func AddonConflictResolutionFromSDK(conflict ekstypes.ResolveConflicts) *string
278278
}
279279
return aws.String(string(ekscontrolplanev1.AddonResolutionOverwrite))
280280
}
281+
282+
// SupportTypeToSDK converts CAPA upgrade support policy types to SDK types.
283+
func SupportTypeToSDK(input ekscontrolplanev1.UpgradePolicy) ekstypes.SupportType {
284+
if input == ekscontrolplanev1.UpgradePolicyStandard {
285+
return ekstypes.SupportTypeStandard
286+
}
287+
return ekstypes.SupportTypeExtended
288+
}

pkg/cloud/services/eks/cluster.go

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"context"
2121
"fmt"
2222
"net"
23+
"strings"
2324
"time"
2425

2526
"github.com/aws/aws-sdk-go-v2/aws"
@@ -35,6 +36,7 @@ import (
3536
infrav1 "sigs.k8s.io/cluster-api-provider-aws/v2/api/v1beta2"
3637
ekscontrolplanev1 "sigs.k8s.io/cluster-api-provider-aws/v2/controlplane/eks/api/v1beta2"
3738
"sigs.k8s.io/cluster-api-provider-aws/v2/pkg/cloud/awserrors"
39+
"sigs.k8s.io/cluster-api-provider-aws/v2/pkg/cloud/converters"
3840
"sigs.k8s.io/cluster-api-provider-aws/v2/pkg/cloud/services/wait"
3941
"sigs.k8s.io/cluster-api-provider-aws/v2/pkg/internal/cidr"
4042
"sigs.k8s.io/cluster-api-provider-aws/v2/pkg/internal/cmp"
@@ -460,6 +462,14 @@ func (s *Service) createCluster(ctx context.Context, eksClusterName string) (*ek
460462
eksVersion = &v
461463
}
462464

465+
var upgradePolicy *ekstypes.UpgradePolicyRequest
466+
467+
if s.scope.ControlPlane.Spec.UpgradePolicy != nil {
468+
upgradePolicy = &ekstypes.UpgradePolicyRequest{
469+
SupportType: converters.SupportTypeToSDK(*s.scope.ControlPlane.Spec.UpgradePolicy),
470+
}
471+
}
472+
463473
bootstrapAddon := s.scope.BootstrapSelfManagedAddons()
464474
input := &eks.CreateClusterInput{
465475
Name: aws.String(eksClusterName),
@@ -471,6 +481,7 @@ func (s *Service) createCluster(ctx context.Context, eksClusterName string) (*ek
471481
Tags: tags,
472482
KubernetesNetworkConfig: netConfig,
473483
BootstrapSelfManagedAddons: bootstrapAddon,
484+
UpgradePolicy: upgradePolicy,
474485
}
475486

476487
var out *eks.CreateClusterOutput
@@ -526,6 +537,12 @@ func (s *Service) reconcileClusterConfig(ctx context.Context, cluster *ekstypes.
526537
input.ResourcesVpcConfig = updateVpcConfig
527538
}
528539

540+
updateUpgradePolicy := s.reconcileUpgradePolicy(cluster.UpgradePolicy)
541+
if updateUpgradePolicy != nil {
542+
needsUpdate = true
543+
input.UpgradePolicy = updateUpgradePolicy
544+
}
545+
529546
if needsUpdate {
530547
if err := wait.WaitForWithRetryable(wait.NewBackoff(), func() (bool, error) {
531548
if _, err := s.EKSClient.UpdateClusterConfig(ctx, input); err != nil {
@@ -719,6 +736,31 @@ func (s *Service) reconcileClusterVersion(ctx context.Context, cluster *ekstypes
719736
return nil
720737
}
721738

739+
func (s *Service) reconcileUpgradePolicy(upgradePolicy *ekstypes.UpgradePolicyResponse) *ekstypes.UpgradePolicyRequest {
740+
s.Info("reconciling upgrade policy")
741+
742+
if upgradePolicy == nil {
743+
s.Debug("cannot get cluster upgrade policy, no action")
744+
return nil
745+
}
746+
747+
clusterUpgradePolicy := upgradePolicy.SupportType
748+
749+
if s.scope.ControlPlane.Spec.UpgradePolicy == nil {
750+
s.Debug("upgrade policy not given, no action")
751+
return nil
752+
}
753+
754+
if strings.ToLower(string(clusterUpgradePolicy)) == s.scope.ControlPlane.Spec.UpgradePolicy.String() {
755+
s.Debug("upgrade policy unchanged, no action")
756+
return nil
757+
}
758+
759+
return &ekstypes.UpgradePolicyRequest{
760+
SupportType: converters.SupportTypeToSDK(*s.scope.ControlPlane.Spec.UpgradePolicy),
761+
}
762+
}
763+
722764
func (s *Service) describeEKSCluster(ctx context.Context, eksClusterName string) (*ekstypes.Cluster, error) {
723765
input := &eks.DescribeClusterInput{
724766
Name: aws.String(eksClusterName),

0 commit comments

Comments
 (0)