Skip to content

Conversation

fiunchinho
Copy link
Contributor

@fiunchinho fiunchinho commented Jun 19, 2025

/kind feature

What this PR does / why we need it:

This is a draft PR to gather feedback about a potential approach to solve the k8s version skew problem, where AWSMachinePool workers are upgraded to newer k8s versions before the control plane nodes are upgraded.

Release note:

Check control plane version skew before creating new launch template version

@k8s-ci-robot
Copy link
Contributor

Skipping CI for Draft Pull Request.
If you want CI signal for your change, please convert it to an actual PR.
You can still manually trigger a test run with /test all

@k8s-ci-robot k8s-ci-robot added do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. needs-priority labels Jun 19, 2025
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign neolit123 for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Jun 19, 2025
@k8s-ci-robot k8s-ci-robot requested review from cnmcavoy and nrb June 19, 2025 12:53
@fiunchinho fiunchinho changed the title Check control plane version skew before creating new launch template … Check control plane version skew before creating new launch template version Jun 19, 2025
@k8s-ci-robot k8s-ci-robot added release-note Denotes a PR that will be considered when it comes time to generate release notes. and removed do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. labels Jun 19, 2025
@fiunchinho fiunchinho changed the title Check control plane version skew before creating new launch template version ✨ Check control plane version skew before creating new launch template version Jun 19, 2025
@fiunchinho fiunchinho force-pushed the control-plane-skew branch from d872e60 to ebb7acc Compare June 19, 2025 13:04
@fiunchinho fiunchinho changed the title ✨ Check control plane version skew before creating new launch template version WIP: ✨ Check control plane version skew before creating new launch template version Jun 19, 2025
@fiunchinho fiunchinho force-pushed the control-plane-skew branch 2 times, most recently from 09f90d8 to 8a507ce Compare June 19, 2025 23:19
@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Jun 19, 2025
@fiunchinho fiunchinho changed the title WIP: ✨ Check control plane version skew before creating new launch template version ✨ Check control plane version skew before creating new launch template version Jun 19, 2025
@fiunchinho
Copy link
Contributor Author

/test all

@fiunchinho fiunchinho force-pushed the control-plane-skew branch from 8a507ce to 5e4e6e8 Compare June 20, 2025 12:32
@fiunchinho
Copy link
Contributor Author

/retest

@fiunchinho fiunchinho marked this pull request as ready for review June 23, 2025 07:48
@k8s-ci-robot k8s-ci-robot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Jun 23, 2025
@k8s-ci-robot k8s-ci-robot requested a review from dlipovetsky June 23, 2025 07:48
Copy link
Member

@richardcase richardcase left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is a good approach to stop upgrading the MachinePools too early.

// isMachinePoolAllowedToUpgradeDueToControlPlaneVersionSkew checks if the control plane is being upgraded, in which case we shouldn't update the launch template.
func (r *AWSMachinePoolReconciler) isMachinePoolAllowedToUpgradeDueToControlPlaneVersionSkew(clusterScope cloud.ClusterScoper, machinePoolScope *scope.MachinePoolScope) (bool, error) {
if machinePoolScope.Cluster.Spec.ControlPlaneRef == nil {
return true, nil
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we'd want to proceed in this case with the upgrade.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed the logic to return an error in this case, PTAL.

@richardcase
Copy link
Member

/milestone v2.9

@k8s-ci-robot k8s-ci-robot added this to the v2.9 milestone Jun 24, 2025
@fiunchinho fiunchinho force-pushed the control-plane-skew branch from 5e4e6e8 to 5b92730 Compare July 30, 2025 15:47
@fiunchinho
Copy link
Contributor Author

/test ?

@k8s-ci-robot
Copy link
Contributor

@fiunchinho: The following commands are available to trigger required jobs:

/test pull-cluster-api-provider-aws-build
/test pull-cluster-api-provider-aws-build-docker
/test pull-cluster-api-provider-aws-e2e-blocking
/test pull-cluster-api-provider-aws-test
/test pull-cluster-api-provider-aws-verify

The following commands are available to trigger optional jobs:

/test pull-cluster-api-provider-aws-apidiff-main
/test pull-cluster-api-provider-aws-e2e
/test pull-cluster-api-provider-aws-e2e-clusterclass
/test pull-cluster-api-provider-aws-e2e-conformance
/test pull-cluster-api-provider-aws-e2e-conformance-with-ci-artifacts
/test pull-cluster-api-provider-aws-e2e-eks
/test pull-cluster-api-provider-aws-e2e-eks-gc
/test pull-cluster-api-provider-aws-e2e-eks-testing

Use /test all to run the following jobs that were automatically triggered:

pull-cluster-api-provider-aws-apidiff-main
pull-cluster-api-provider-aws-build
pull-cluster-api-provider-aws-build-docker
pull-cluster-api-provider-aws-e2e-blocking
pull-cluster-api-provider-aws-test
pull-cluster-api-provider-aws-verify

In response to this:

/test ?

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@fiunchinho
Copy link
Contributor Author

/test pull-cluster-api-provider-aws-e2e
/test pull-cluster-api-provider-aws-e2e-eks

@fiunchinho
Copy link
Contributor Author

/test pull-cluster-api-provider-aws-test

@fiunchinho fiunchinho force-pushed the control-plane-skew branch from 5b92730 to c4d8dc1 Compare July 30, 2025 16:25
@fiunchinho
Copy link
Contributor Author

/test pull-cluster-api-provider-aws-e2e
/test pull-cluster-api-provider-aws-e2e-eks

@fiunchinho
Copy link
Contributor Author

/retest


cpVersion, found, err := unstructured.NestedString(controlPlane.Object, "status", "version")
if !found || err != nil {
return false, errors.Wrapf(err, "failed to get version of ControlPlane %s", machinePoolScope.Cluster.Spec.ControlPlaneRef.Name)
Copy link
Contributor

@nrb nrb Aug 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With the || here, is it possible that we'll get a case where !found = true && err == nil? That may cause an issue when generating the wrapped error here.

asgSvc.EXPECT().CanStartASGInstanceRefresh(gomock.Any()).Times(0)
// Won't be called due to version skew
ec2Svc.EXPECT().CreateLaunchTemplateVersion(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Times(0)
// Won't be called due to version skew
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Appreciate these comments, thank you!

@AndiDog
Copy link
Contributor

AndiDog commented Sep 3, 2025

We found this doesn't work if the MachinePool object still hasn't been updated. The patched logic then thinks MachinePool.spec.template.spec.version to be the desired version, but it's outdated and this might again lead to unwanted worker rollouts with too new Kubernetes version.

This patch improves the situation if the objects are deployed around the same time (before reconciliation runs), so I think we could keep it as a first step in the right direction. For a full skew check, we'd need to synchronize the MachinePool and AWSMachinePool objects, for example using a common field or label.

@fiunchinho One more question on behavior: The patch avoids the instance refresh. But what if the ASG scales up or replaces instances – would they have the new Kubernetes version? Also, we currently get return errors.New("Cannot update the launch template, prerequisite not met") – probably fine, but maybe we should fill the condition with a good reason text (returned by canUpdateLaunchTemplate()?!).

@fiunchinho
Copy link
Contributor Author

@fiunchinho One more question on behavior: The patch avoids the instance refresh. But what if the ASG scales up or replaces instances – would they have the new Kubernetes version? Also, we currently get return errors.New("Cannot update the launch template, prerequisite not met") – probably fine, but maybe we should fill the condition with a good reason text (returned by canUpdateLaunchTemplate()?!).

It prevents creating a new launch template version, so new nodes (even when scaling up) won't get the new k8s version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. needs-priority release-note Denotes a PR that will be considered when it comes time to generate release notes. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants