Skip to content

🐛 test/e2e/metrics_test.go: discover operator-controller namespace and improve logging#1547

Merged
joelanford merged 1 commit into
operator-framework:mainfrom
joelanford:fix-metrics-e2e
Jan 7, 2025
Merged

🐛 test/e2e/metrics_test.go: discover operator-controller namespace and improve logging#1547
joelanford merged 1 commit into
operator-framework:mainfrom
joelanford:fix-metrics-e2e

Conversation

@joelanford

Copy link
Copy Markdown
Member

Description

We should make our e2e's resilient to operator-controller being relocated or run in different namespaces. This PR removes the hardcoded 'olmv1-system' namespace assumption and instead discovers the namespace by finding the operator-controller pod via label selector and using its namespace.

This PR also:

  • Fails the test if a kube CLI client is not found (before it was skipping)
  • Improves logging to tell the user what namespace is discovered
  • Fixes an issue with the token creation error handling to ensure that failure logging is included in the e2e output.

Reviewer Checklist

  • API Go Documentation
  • Tests: Unit Tests (and E2E Tests, if appropriate)
  • Comprehensive Commit Messages
  • Links to related GitHub Issue(s)

…improve logging

Signed-off-by: Joe Lanford <joe.lanford@gmail.com>
@joelanford joelanford requested a review from a team as a code owner January 7, 2025 13:19
@netlify

netlify Bot commented Jan 7, 2025

Copy link
Copy Markdown

Deploy Preview for olmv1 ready!

Name Link
🔨 Latest commit ec9fadb
🔍 Latest deploy log https://app.netlify.com/sites/olmv1/deploys/677d29f27a26730008a45520
😎 Deploy Preview https://deploy-preview-1547--olmv1.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@codecov

codecov Bot commented Jan 7, 2025

Copy link
Copy Markdown

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 74.25%. Comparing base (83b01c3) to head (ec9fadb).
Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1547   +/-   ##
=======================================
  Coverage   74.25%   74.25%           
=======================================
  Files          42       42           
  Lines        3329     3329           
=======================================
  Hits         2472     2472           
  Misses        676      676           
  Partials      181      181           
Flag Coverage Δ
e2e 52.11% <ø> (ø)
unit 56.95% <ø> (-0.04%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Comment thread test/e2e/metrics_test.go
t.Log("Determining operator-controller namespace")
cmd := exec.Command(client, "get", "pods", "--all-namespaces", "--selector=control-plane=operator-controller-controller-manager", "--output=jsonpath={.items[0].metadata.namespace}")
output, err := cmd.CombinedOutput()
require.NoError(t, err, "Error creating determining operator-controller namespace: %s", string(output))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

What if there are multiple outputs (namespaces) found?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yeah, I thought about that briefly. Ultimately if there are multiple pods that match the label that exist in different namespaces, we'll pick the first one.

If that's the "correct" namespace (where the SA and metrics service/endpoint) exist, the test will pass.
If it's not the right namespace, the test will fail, likely because the token generation fails because the SA doesn't exist, but if the SA exists in the "incorrect" namespace, it could still fail if there's no service there.

TL;DR: the test will fail if we choose an "incorrect" namespace.

@tmshort tmshort Jan 7, 2025

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

wouldn’t the output be along the lines of "namespace1\nnamespace2" which would mess up any use of output? I don’t think you’re just picking “one”.
Admittedly, this will totally mess up your --serviceaccount parameter, but we should error out early.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

No, because the output specifically selects the namespace of the first item in the returned list

--output=jsonpath={.items[0].metadata.namespace}

@tmshort tmshort Jan 7, 2025

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Ah, yes, this was something you had also changed downstream... So you're going for the first one... hmm... But now I'm wondering how you did that downstream without this commit?
Edit: Ah... drop commit...

@tmshort tmshort left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

/lgtm

@joelanford joelanford added this pull request to the merge queue Jan 7, 2025
Merged via the queue into operator-framework:main with commit 6755e94 Jan 7, 2025
github-merge-queue Bot pushed a commit that referenced this pull request Jan 7, 2025
…improve logging (#1547)

Signed-off-by: Joe Lanford <joe.lanford@gmail.com>
camilamacedo86 pushed a commit to camilamacedo86/operator-controller that referenced this pull request Jan 8, 2025
…improve logging (operator-framework#1547)

Signed-off-by: Joe Lanford <joe.lanford@gmail.com>
camilamacedo86 pushed a commit to camilamacedo86/operator-controller that referenced this pull request Jan 8, 2025
…improve logging (operator-framework#1547)

Signed-off-by: Joe Lanford <joe.lanford@gmail.com>
@joelanford joelanford deleted the fix-metrics-e2e branch February 14, 2025 19:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

lgtm Indicates that a PR is ready to be merged.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants