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

🌱 Implement topology validations for topology kubernetes version upgrades #10063

Merged

Conversation

chrischdi
Copy link
Member

@chrischdi chrischdi commented Jan 26, 2024

What this PR does / why we need it:

Which issue(s) this PR fixes (optional, in fixes #<issue number>(, fixes #<issue_number>, ...) format, will close the issue(s) when PR gets merged):
Fixes #10049
Fixes #9098

/area clusterclass

@k8s-ci-robot k8s-ci-robot added area/clusterclass Issues or PRs related to clusterclass cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Jan 26, 2024
@k8s-ci-robot k8s-ci-robot added the size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. label Jan 26, 2024
api/v1beta1/common_types.go Outdated Show resolved Hide resolved
controllers/remote/cluster_cache_tracker.go Show resolved Hide resolved
webhooks/alias.go Show resolved Hide resolved
internal/webhooks/cluster.go Show resolved Hide resolved
internal/webhooks/cluster.go Outdated Show resolved Hide resolved
internal/webhooks/cluster.go Outdated Show resolved Hide resolved
internal/webhooks/cluster.go Show resolved Hide resolved
internal/webhooks/cluster.go Outdated Show resolved Hide resolved
internal/webhooks/cluster.go Outdated Show resolved Hide resolved
internal/webhooks/cluster.go Outdated Show resolved Hide resolved
@chrischdi chrischdi force-pushed the pr-capi-version-validations branch 2 times, most recently from 6bbb017 to 81d7119 Compare February 7, 2024 17:37
@k8s-ci-robot k8s-ci-robot added size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. labels Feb 7, 2024
@chrischdi chrischdi force-pushed the pr-capi-version-validations branch 2 times, most recently from bdf09a2 to 41d7f68 Compare February 7, 2024 18:34
@k8s-ci-robot k8s-ci-robot added size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. and removed size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Feb 7, 2024
@chrischdi
Copy link
Member Author

Example error:

                <*errors.StatusError | 0x1400038ac80>: 
                Cluster.cluster.x-k8s.io "cluster1" is invalid: spec.topology.version: Invalid value: "v1.20.2": blocking version update due to MachineDeployment version check: upgrading MachineDeployments: [cluster1-workers1]
                {
                    ErrStatus: {
                        TypeMeta: {Kind: "", APIVersion: ""},
                        ListMeta: {
                            SelfLink: "",
                            ResourceVersion: "",
                            Continue: "",
                            RemainingItemCount: nil,
                        },
                        Status: "Failure",
                        Message: "Cluster.cluster.x-k8s.io \"cluster1\" is invalid: spec.topology.version: Invalid value: \"v1.20.2\": blocking version update due to MachineDeployment version check: upgrading MachineDeployments: [cluster1-workers1]",
                        Reason: "Invalid",
                        Details: {
                            Name: "cluster1",
                            Group: "cluster.x-k8s.io",
                            Kind: "Cluster",
                            UID: "",
                            Causes: [
                                {
                                    Type: "FieldValueInvalid",
                                    Message: "Invalid value: \"v1.20.2\": blocking version update due to MachineDeployment version check: upgrading MachineDeployments: [cluster1-workers1]",
                                    Field: "spec.topology.version",
                                },
                            ],
                            RetryAfterSeconds: 0,
                        },
                        Code: 422,
                    },
                }

@chrischdi chrischdi changed the title 🌱 [WIP] Implement topology validations for topology kubernetes version upgrades 🌱 Implement topology validations for topology kubernetes version upgrades Feb 8, 2024
@@ -29,92 +29,6 @@ import (
"sigs.k8s.io/cluster-api/internal/test/builder"
)

func TestIsUpgrading(t *testing.T) {
Copy link
Member Author

Choose a reason for hiding this comment

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

This tests got moved to internal/topology/check/upgrade_test.go

@@ -163,22 +137,6 @@ type MachinePoolState struct {
// IsUpgrading determines if the MachinePool is upgrading.
// A machine pool is considered upgrading if at least one of the Machines of this
// MachinePool has a different version.
func (mp *MachinePoolState) IsUpgrading(ctx context.Context, c client.Client) (bool, error) {
// If the MachinePool has no version there is no definitive way to check if it is upgrading. Therefore, return false.
Copy link
Member Author

Choose a reason for hiding this comment

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

This code got moved to internal/topology/check/upgrade.go

@@ -101,40 +99,16 @@ type MachineDeploymentState struct {
// IsUpgrading determines if the MachineDeployment is upgrading.
// A machine deployment is considered upgrading if at least one of the Machines of this
// MachineDeployment has a different version.
func (md *MachineDeploymentState) IsUpgrading(ctx context.Context, c client.Client) (bool, error) {
// If the MachineDeployment has no version there is no definitive way to check if it is upgrading. Therefore, return false.
Copy link
Member Author

Choose a reason for hiding this comment

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

This code got moved to internal/topology/check/upgrade.go

}
}

func TestIsMachinePoolUpgrading(t *testing.T) {
Copy link
Member Author

Choose a reason for hiding this comment

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

Note: this test did not exist before and we now cover the IsMachinePoolUpgrading function 🎉

@sbueringer
Copy link
Member

Let me know when you're done and I'll take another look (no rush though :))

@chrischdi
Copy link
Member Author

@sbueringer should be ready for review now :-)

Copy link
Member

@sbueringer sbueringer left a comment

Choose a reason for hiding this comment

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

Very nice work!! Just nits remaining

internal/test/envtest/environment.go Outdated Show resolved Hide resolved
internal/webhooks/cluster.go Outdated Show resolved Hide resolved
internal/webhooks/cluster.go Outdated Show resolved Hide resolved
internal/webhooks/cluster.go Outdated Show resolved Hide resolved
internal/webhooks/cluster.go Outdated Show resolved Hide resolved
internal/webhooks/cluster.go Outdated Show resolved Hide resolved
internal/webhooks/cluster.go Outdated Show resolved Hide resolved
internal/webhooks/cluster_test.go Show resolved Hide resolved
internal/webhooks/cluster_test.go Outdated Show resolved Hide resolved
internal/webhooks/cluster_test.go Outdated Show resolved Hide resolved
@sbueringer
Copy link
Member

Thank you!

/lgtm

/assign @fabriziopandini

@k8s-ci-robot
Copy link
Contributor

LGTM label has been added.

Git tree hash: 8402f5d3213f70f32c40f7b250886e4abeff03a6

…tter>

Sideeffects:
* webhooks: add ClusterCacheTrackerReader to the cluster webhook for machine pool validations
* Introduce annotation unsafe.topology.cluster.x-k8s.io/disable-version-validation
@k8s-ci-robot k8s-ci-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Feb 15, 2024
@chrischdi
Copy link
Member Author

Had to rebase due to merge conflict

@sbueringer
Copy link
Member

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Feb 15, 2024
@k8s-ci-robot
Copy link
Contributor

LGTM label has been added.

Git tree hash: 19db04416730ab0633954e11635a9a434ce8b194

api/v1beta1/common_types.go Show resolved Hide resolved
internal/webhooks/cluster.go Show resolved Hide resolved
internal/webhooks/cluster.go Outdated Show resolved Hide resolved
internal/webhooks/cluster.go Outdated Show resolved Hide resolved
internal/webhooks/cluster.go Outdated Show resolved Hide resolved
internal/webhooks/cluster.go Outdated Show resolved Hide resolved
internal/webhooks/cluster_test.go Show resolved Hide resolved
main.go Outdated Show resolved Hide resolved
@k8s-ci-robot k8s-ci-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Feb 20, 2024
@fabriziopandini
Copy link
Member

/lgtm
/approve

/hold
for squash

@k8s-ci-robot k8s-ci-robot added do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. lgtm "Looks good to me", indicates that a PR is ready to be merged. labels Feb 20, 2024
@k8s-ci-robot
Copy link
Contributor

LGTM label has been added.

Git tree hash: a971171d6a4ddc20acbeac2655ed2104ea0f6c45

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: fabriziopandini

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

The pull request process is described 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 approved Indicates a PR has been approved by an approver from all required OWNERS files. label Feb 20, 2024
@chrischdi
Copy link
Member Author

Squash should not be required

/hold cancel

@fabriziopandini
Copy link
Member

let test the squash bot
/hold cancel

@k8s-ci-robot k8s-ci-robot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Feb 20, 2024
@k8s-ci-robot k8s-ci-robot merged commit 0045baf into kubernetes-sigs:main Feb 20, 2024
22 checks passed
@k8s-ci-robot k8s-ci-robot added this to the v1.7 milestone Feb 20, 2024
@chrischdi chrischdi deleted the pr-capi-version-validations branch February 20, 2024 15:01
@chrischdi
Copy link
Member Author

chrischdi commented Mar 26, 2024

/cherry-pick release-1.6

Due to targeting the experimental ClusterClass feature

@k8s-infra-cherrypick-robot

@chrischdi: new pull request created: #10318

In response to this:

/cherry-pick release-1.6

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/test-infra repository.

@sbueringer sbueringer mentioned this pull request Apr 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. area/clusterclass Issues or PRs related to clusterclass cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.
Projects
None yet
5 participants