Skip to content

Add 3 labels to all resources, add e2e test that validate the existence of the three labels #142

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

Draft
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

Shai1-Levi
Copy link

@Shai1-Levi Shai1-Levi commented Jan 13, 2025

Why we need this PR

To meet k8s custom labels standardization:
Add 3 custom labels to all resources, add e2e that test the existence of name label

Changes made

  1. Add recommended app.kubernetes.io/name label to everything

With these changes we prevent services selecting pods by other
operators, because they all have the control-plane: controller-manager
label by default.

Because deployment updates with modified labels fail, also rename the
deployment by modifying the namePrefix (causes bundle file renames as
well).

  1. Add test that validate retrieval of operator controller pod by the name label.

  2. Add the default container label, for easier getting desired logs.

Which issue(s) this PR fixes

Test plan

2. Add test that validate retrieval of operator controller pod by the label.
@openshift-ci openshift-ci bot requested review from razo7 and slintes January 13, 2025 16:29
Copy link
Contributor

openshift-ci bot commented Jan 13, 2025

Hi @Shai1-Levi. Thanks for your PR.

I'm waiting for a medik8s member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

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.

2. Add test that validate retrieval of operator controller pod by the label.
@slintes
Copy link
Member

slintes commented Jan 14, 2025

in the past at least, label additions broke updates... [1]
IIRC e2e has an update test, let's see what happens.

/test 4.17-openshift-e2e

[1] medik8s/node-healthcheck-operator@df1d2e8#diff-c006b1ef995eeeb57408cce42bd84db8dfc0cbe18df03222857665cebb1ac6fdR9-R18

@Shai1-Levi Shai1-Levi changed the title Add custom label to all resources, add e2e test with it [WIP] Add custom label to all resources, add e2e test with it Jan 14, 2025
@slintes
Copy link
Member

slintes commented Jan 14, 2025

update still fails 🤷🏼‍♂️

"Failed to run bundle upgrade: error waiting for CSV to install: csv failed: reason: \"InstallComponentFailed\", message: \"install strategy failed: Deployment.apps \\\"node-maintenance-operator-controller-manager\\\" is invalid: spec.selector: Invalid value: v1.LabelSelector{MatchLabels:map[string]string{\\\"app.kubernetes.io/name\\\":\\\"node-maintenance-operator\\\", \\\"control-plane\\\":\\\"controller-manager\\\", \\\"node-maintenance-operator\\\":\\\"\\\"}, MatchExpressions:[]v1.LabelSelectorRequirement(nil)}: field is immutable\"\n" make: *** [Makefile:208: bundle-run-update] Error 1

- add recommended app.kubernetes.io/name label to everything

  With these changes we prevent services selecting pods by other
  operators, because they all have the control-plane: controller-manager
  label by default.

  Because deployment updates with modified labels fail, also rename the
  deployment by modifying the namePrefix (causes bundle file renames as
  well).

- Add test that validate retrieval of operator controller pod by the label.
@Shai1-Levi
Copy link
Author

/test 4.17-openshift-e2e

Copy link
Contributor

openshift-ci bot commented Jan 15, 2025

@Shai1-Levi: Cannot trigger testing until a trusted user reviews the PR and leaves an /ok-to-test message.

In response to this:

/test 4.17-openshift-e2e

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.

@razo7
Copy link
Member

razo7 commented Jan 15, 2025

/ok-to-test

- add recommended app.kubernetes.io/name label to everything

  With these changes we prevent services selecting pods by other
  operators, because they all have the control-plane: controller-manager
  label by default.

  Because deployment updates with modified labels fail, also rename the
  deployment by modifying the namePrefix (causes bundle file renames as
  well).

- Add test that validate retrieval of operator controller pod by the label.
@slintes
Copy link
Member

slintes commented Jan 16, 2025

/test 4.17-openshift-e2e

@slintes
Copy link
Member

slintes commented Jan 16, 2025

operator update succeeded
test failure looks unrelated, looking at the test history this seems to be very flaky... :/

/ok-to-test
/lgtm
/approve

- Add recommended app.kubernetes.io/name label to everything

  With these changes we prevent services selecting pods by other
  operators, because they all have the control-plane: controller-manager
  label by default.

  Because deployment updates with modified labels fail, also rename the
  deployment by modifying the namePrefix (causes bundle file renames as
  well).

- Add test that validate retrieval of operator controller pod by the label.

- Add the default container label, for easier getting desired logs.
@openshift-ci openshift-ci bot removed the lgtm label Jan 16, 2025
@Shai1-Levi
Copy link
Author

Hey,
I added some labels to fix the e2e test and test-scorecard
@slintes I didn't saw your last comment before I pushed the code

/test 4.17-openshift-e2e

@openshift-ci openshift-ci bot removed the approved label Jan 17, 2025
- Add recommended app.kubernetes.io/name label to everything

  With these changes we prevent services selecting pods by other
  operators, because they all have the control-plane: controller-manager
  label by default.

  Because deployment updates with modified labels fail, also rename the
  deployment by modifying the namePrefix (causes bundle file renames as
  well).

- Add test that validate retrieval of operator controller pod by the label.

- Add the default container label, for easier getting desired logs.
@slintes
Copy link
Member

slintes commented Jan 17, 2025

/retest
/lgtm

@openshift-ci openshift-ci bot added the lgtm label Jan 17, 2025
@slintes
Copy link
Member

slintes commented Jan 17, 2025

/retest

@slintes
Copy link
Member

slintes commented Jan 18, 2025

setup failed...

/retest

@slintes
Copy link
Member

slintes commented Jan 18, 2025

@razo7 since when is the e2e test so flaky? :/

Error waiting for events: context deadline exceeded  [FAILED] Event SucceedMaintenance was missing for test-maintenance nm CR
  Unexpected error:
      <context.deadlineExceededError>: 
      context deadline exceeded
      {}
  occurred

@slintes
Copy link
Member

slintes commented Jan 18, 2025

/retest

@Shai1-Levi Shai1-Levi changed the title [WIP] Add custom label to all resources, add e2e test with it Add custom label to all resources, add e2e test with it Jan 19, 2025
@@ -419,6 +422,13 @@ func getOperatorPod() *corev1.Pod {
return &pods.Items[0]
}

func getOperatorLabel() bool {
pods, err := KubeClient.CoreV1().Pods(operatorNsName).List(context.Background(), metav1.ListOptions{LabelSelector: "app.kubernetes.io/name=node-maintenance-operator"})
Copy link
Member

Choose a reason for hiding this comment

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

IIUC the PR introduces 3 new labels while this function looks for the existence of only one of them. See also K8s recommended labels .

Copy link
Author

@Shai1-Levi Shai1-Levi Jan 19, 2025

Choose a reason for hiding this comment

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

Thanks, I will add the new labels into thse e2e test.
Regard k8s recommended labels I over this doc and I think that all the relevant labels was added. Thank you for introducing me with these k8s convention

@Shai1-Levi Shai1-Levi changed the title Add custom label to all resources, add e2e test with it Add 3 custom labels to all resources, add e2e that test the existence of name label Jan 19, 2025
…labels existence

- Add recommended app.kubernetes.io/name label to everything

  With these changes we prevent services selecting pods by other
  operators, because they all have the control-plane: controller-manager
  label by default.

  Because deployment updates with modified labels fail, also rename the
  deployment by modifying the namePrefix (causes bundle file renames as
  well).

- Add tests that validate retrieval of operator controller pod by label.

- Add the default container label, for easier getting desired logs.
@openshift-ci openshift-ci bot removed the lgtm label Jan 21, 2025
@Shai1-Levi Shai1-Levi changed the title Add 3 custom labels to all resources, add e2e that test the existence of name label Add 3 labels to all resources, add e2e test that validate the existence of the three labels Jan 21, 2025
Copy link
Member

@slintes slintes left a comment

Choose a reason for hiding this comment

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

/retest

ExpectWithOffset(2, len(pods.Items)).ToNot(BeZero(), "no operator pod found")
return true
}

func validateOperatorCustomLabelComponent() bool {
Copy link
Member

Choose a reason for hiding this comment

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

not that relevant for test code, but for production code this would be very inefficient. You could get the pod with one label, and then check if it has the other labels as well, instead of looking for the pod 3 times

@slintes
Copy link
Member

slintes commented Jan 22, 2025

/hold

since this is not urgent, let's first try to fix the e2e test, these retests are a waste of resources...

@openshift-ci openshift-ci bot removed the lgtm label Jan 22, 2025
Copy link
Contributor

openshift-ci bot commented Jan 22, 2025

New changes are detected. LGTM label has been removed.

@@ -179,6 +179,9 @@ var _ = Describe("Starting Maintenance", func() {
// it should be caused by the test deployment's termination graceperiod > drain timeout
Expect(getOperatorLogs()).To(ContainSubstring(nodemaintenance.FixedDurationReconcileLog))

//validate that operator controller pod have app.kubernetes.io/name label
Expect(validateOperatorCustomLabels()).To(BeTrue(), "operator custom label validation failed")
Copy link
Member

Choose a reason for hiding this comment

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

the return value and checking it isn't needed IMHO, everything is checked inside the function already?

podName := podOperator.ObjectMeta.Name

// Get the Pod
pod, err := KubeClient.CoreV1().Pods(operatorNsName).Get(context.TODO(), podName, metav1.GetOptions{})
Copy link
Member

Choose a reason for hiding this comment

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

you have the pod already, why getting it here again?

// Check if each label is present
for _, key := range requiredKeys {
_, exists := pod.Labels[key]
ExpectWithOffset(1, exists).Should(BeTrue(), fmt.Sprintf("Missing required label '%s' in pod '%s'", key, podName))
Copy link
Member

Choose a reason for hiding this comment

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

a) you don't check label values anymore
b) hint: ExpectWithOffset(1, pod.Labels).To(HaveKeyWithValue(key, value))

Copy link
Contributor

openshift-ci bot commented Jan 22, 2025

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: Shai1-Levi
Once this PR has been reviewed and has the lgtm label, please ask for approval from slintes. 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

@openshift-ci openshift-ci bot removed the approved label Jan 22, 2025
Copy link
Contributor

openshift-ci bot commented Jul 7, 2025

@Shai1-Levi: The following tests failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
ci/prow/4.16-openshift-e2e 807c5f9 link true /test 4.16-openshift-e2e
ci/prow/4.17-openshift-e2e 807c5f9 link true /test 4.17-openshift-e2e
ci/prow/4.18-openshift-e2e 807c5f9 link true /test 4.18-openshift-e2e
ci/prow/4.20-ci-bundle-my-bundle 1827784 link true /test 4.20-ci-bundle-my-bundle

Full PR test history. Your PR dashboard.

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. 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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants