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

✨ Moved MachineDeployment Cluster Label Name to webhook #2308

Merged
merged 1 commit into from
Feb 21, 2020

Conversation

hpandeycodeit
Copy link

What this PR does / why we need it:
Moved MachineDeployment Cluster Label Name to webhook as per #2302

Which issue(s) this PR fixes :
Fixes #2302

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Feb 11, 2020
@k8s-ci-robot k8s-ci-robot added size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. size/S Denotes a PR that changes 10-29 lines, ignoring generated files. and removed size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels Feb 11, 2020
@k8s-ci-robot k8s-ci-robot added size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. and removed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Feb 11, 2020
Comment on lines 47 to 48
g.Expect(md.Spec.Selector.MatchLabels).To(HaveKeyWithValue(clusterv1.ClusterLabelName, "test-md"))
g.Expect(md.Spec.Template.Labels).To(HaveKeyWithValue(clusterv1.ClusterLabelName, "test-md"))
Copy link
Contributor

Choose a reason for hiding this comment

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

@hpandeycodeit You probably need to remove clusterv1.ClusterLabelName and add ClusterLabelName instead.

Copy link
Author

Choose a reason for hiding this comment

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

thanks! changed it :)

@k8s-ci-robot k8s-ci-robot added size/S Denotes a PR that changes 10-29 lines, ignoring generated files. and removed size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels Feb 12, 2020
Copy link
Member

@vincepri vincepri left a comment

Choose a reason for hiding this comment

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

/approve

Linter is failing with

controllers/machinedeployment_controller.go:151: File is not `gofmt`-ed with `-s` (gofmt)

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: hpandeycodeit, vincepri

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 13, 2020
MatchLabels: map[string]string{
ClusterLabelName: "test-cluster",
},
},
Copy link
Member

Choose a reason for hiding this comment

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

Specifying the Selector here is causing the test failure: line 49 is checking for the MachineDeploymentLabelName key which is only set if there is not a Selector already defined.

It might be good to add a separate test that specifies md.Spec.Selector.MatchLabels and md.Spec.Template.Labels and verifies that the MachineDeployment labels are not added, while the ClusterLabelName ones are.

@vincepri
Copy link
Member

/milestone v0.3.0-rc.1

@k8s-ci-robot k8s-ci-robot added this to the v0.3.0-rc.1 milestone Feb 16, 2020
@vincepri
Copy link
Member

@hpandeycodeit Are still interested to get this change merged?

@hpandeycodeit
Copy link
Author

@hpandeycodeit Are still interested to get this change merged?

yes. will make the suggested changes today.

@vincepri
Copy link
Member

@hpandeycodeit LGTM pending squash

@vincepri
Copy link
Member

/milestone v0.3.0

@hpandeycodeit
Copy link
Author

/test pull-cluster-api-test

@chuckha
Copy link
Contributor

chuckha commented Feb 21, 2020

There were some assumptions in the tests that this change breaks. The tests have two choices. Either implement webhooks in the envtest set of tests or ensure that when we create machine deployments they always have the right label/selectors applied. Here is a diff required to get these tests to passing:

diff --git a/controllers/machinedeployment_controller_test.go b/controllers/machinedeployment_controller_test.go
index b947d3b7e..ccf1fc86a 100644
--- a/controllers/machinedeployment_controller_test.go
+++ b/controllers/machinedeployment_controller_test.go
@@ -62,19 +62,29 @@ var _ = Describe("MachineDeployment Reconciler", func() {
        })
 
        It("Should reconcile a MachineDeployment", func() {
-               labels := map[string]string{"foo": "bar"}
+               labels := map[string]string{
+                       "foo":                      "bar",
+                       clusterv1.ClusterLabelName: testCluster.Name,
+               }
                version := "1.10.3"
                deployment := &clusterv1.MachineDeployment{
                        ObjectMeta: metav1.ObjectMeta{
                                GenerateName: "md-",
                                Namespace:    namespace.Name,
+                               Labels: map[string]string{
+                                       clusterv1.ClusterLabelName: testCluster.Name,
+                               },
                        },
                        Spec: clusterv1.MachineDeploymentSpec{
                                ClusterName:          testCluster.Name,
                                MinReadySeconds:      pointer.Int32Ptr(0),
                                Replicas:             pointer.Int32Ptr(2),
                                RevisionHistoryLimit: pointer.Int32Ptr(0),
-                               Selector:             metav1.LabelSelector{},
+                               Selector: metav1.LabelSelector{
+                                       MatchLabels: map[string]string{
+                                               clusterv1.ClusterLabelName: testCluster.Name,
+                                       },
+                               },
                                Strategy: &clusterv1.MachineDeploymentStrategy{
                                        Type: clusterv1.RollingUpdateMachineDeploymentStrategyType,
                                        RollingUpdate: &clusterv1.MachineRollingUpdateDeployment{
@@ -306,7 +316,8 @@ var _ = Describe("MachineDeployment Reconciler", func() {
                oldLabels[clusterv1.MachineDeploymentLabelName] = deployment.Name
 
                newLabels := map[string]string{
-                       "new-key": "new-value",
+                       "new-key":                  "new-value",
+                       clusterv1.ClusterLabelName: testCluster.Name,
                }
 
                By("Updating MachineDeployment label")

@chuckha
Copy link
Contributor

chuckha commented Feb 21, 2020

if you apply that patch or any similar patch that gets the tests passing @hpandeycodeit, this lgtm.

@vincepri vincepri removed this from the v0.3.0 milestone Feb 21, 2020
@vincepri vincepri added this to the v0.3.0-rc.2 milestone Feb 21, 2020
@k8s-ci-robot k8s-ci-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Feb 21, 2020
@hpandeycodeit
Copy link
Author

if you apply that patch or any similar patch that gets the tests passing @hpandeycodeit, this lgtm.

Thanks @chuckha I have applied this patch!

@chuckha
Copy link
Contributor

chuckha commented Feb 21, 2020

/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 21, 2020
@chuckha
Copy link
Contributor

chuckha commented Feb 21, 2020

/hold

@k8s-ci-robot k8s-ci-robot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Feb 21, 2020
@chuckha
Copy link
Contributor

chuckha commented Feb 21, 2020

Sorry, just noticed this wasn't squashed, can you squash this down to 1 commit please?

fix the import issue

Minor change to the test

gofmted the file

Added separate test case for labels

Modified the MachineDeployment reconcile test, added labels, selectors
@k8s-ci-robot k8s-ci-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Feb 21, 2020
Copy link
Member

@vincepri vincepri left a comment

Choose a reason for hiding this comment

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

/lgtm

@chuckha to unhold

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

chuckha commented Feb 21, 2020

/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 21, 2020
@k8s-ci-robot k8s-ci-robot merged commit 1435eed into kubernetes-sigs:master Feb 21, 2020
@hpandeycodeit
Copy link
Author

Thank you @vincepri @detiber @chuckha!

@k8s-ci-robot
Copy link
Contributor

@hpandeycodeit: The following test failed, say /retest to rerun all failed tests:

Test name Commit Details Rerun command
pull-cluster-api-capd-e2e dab38c8 link /test pull-cluster-api-capd-e2e

Full PR test history. Your PR dashboard. Please help us cut down on flakes by linking to an open issue when you hit one in your PR.

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. I understand the commands that are listed here.

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. 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/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

MachineDeployment Cluster name label should be set in defaulting webhook rather than in reconciliation
6 participants