fix: Look for secret in namespace of wandb CR#78
Conversation
WalkthroughThis pull request adds a validation in the Tiltfile to check that the Kubernetes context is among an allowed list. It also updates the license retrieval functionality across the codebase by modifying the signature of the Changes
Sequence Diagram(s)sequenceDiagram
participant T as Tiltfile Script
participant K as k8s_context()
participant S as Allowed Contexts
participant O as Output (Print/Fail)
T->>K: Retrieve current Kubernetes context
T->>S: Get list of allowed contexts
alt Context is allowed
T->>O: Print confirmation message
else Context not allowed
T->>O: Call fail() with error message
end
sequenceDiagram
participant C as Controller (Reconcile)
participant G as GetLicense()
participant GS as getLicenseFromSecret()
participant K as Kubernetes API
C->>G: Call GetLicense(ctx, client, wandb, crdSpec, userInputSpec)
alt License sourced via secret
G->>GS: Request license from secret using k8sClient
GS->>K: Query Kubernetes Secret
K-->>GS: Return secret value (or empty)
GS-->>G: Return retrieved license
else License provided via values
G->>G: Process license provided via spec values
end
G-->>C: Return license information
Possibly related PRs
Suggested reviewers
Poem
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (2)
🧰 Additional context used🧬 Code Definitions (1)pkg/wandb/spec/utils/license_test.go (4)
⏰ Context from checks skipped due to timeout of 90000ms (1)
🔇 Additional comments (10)
✨ Finishing Touches
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
pkg/wandb/spec/utils/license_test.go (1)
55-85: Added comprehensive test for license retrieval from secret.This test creates a Kubernetes secret with license data, then verifies that the GetLicense function correctly retrieves it. The test properly handles secret creation and validation.
However, I don't see cleanup for the created secret resource after the test. Consider adding a cleanup step:
+ BeforeEach(func() { + // Delete any existing test secrets + secret := &corev1.Secret{} + err := k8sClient.DeleteAllOf(context.Background(), secret, + client.InNamespace("default"), + client.MatchingFields{"metadata.name": "test-secret-name"}) + // Ignore not found errors + Expect(client.IgnoreNotFound(err)).NotTo(HaveOccurred()) + }) + + AfterEach(func() { + // Clean up created resources + secret := &corev1.Secret{} + err := k8sClient.DeleteAllOf(context.Background(), secret, + client.InNamespace("default"), + client.MatchingFields{"metadata.name": "test-secret-name"}) + Expect(client.IgnoreNotFound(err)).NotTo(HaveOccurred()) + })
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (5)
Tiltfile(1 hunks)controllers/weightsandbiases_controller.go(1 hunks)pkg/wandb/spec/utils/license.go(3 hunks)pkg/wandb/spec/utils/license_test.go(3 hunks)pkg/wandb/spec/utils/utils_suite_test.go(1 hunks)
🧰 Additional context used
🧬 Code Definitions (1)
pkg/wandb/spec/utils/utils_suite_test.go (5)
pkg/wandb/spec/state/secrets/manager.go (1) (1)
New(12-24)pkg/wandb/spec/state/versioning.go (1) (1)
New(20-34)pkg/wandb/spec/state/secrets/secrets_suite_test.go (4) (4)
testEnv(26-26)cfg(24-24)err(43-43)k8sClient(25-25)main.go (1) (1)
scheme(48-48)pkg/wandb/spec/channel/deployer/deployer_test.go (1) (1)
client(30-30)
⏰ Context from checks skipped due to timeout of 90000ms (2)
- GitHub Check: Test
- GitHub Check: build-and-scan
🔇 Additional comments (16)
Tiltfile (1)
22-25: Good validation for Kubernetes context safety.This adds a safeguard to prevent accidentally deploying to unintended environments by checking if the current context is in the allowed list. This is a valuable safety measure, especially in environments where developers might have multiple contexts configured.
controllers/weightsandbiases_controller.go (1)
143-143: Correctly updated function call to match new signature.The
GetLicensecall has been updated to include the context, K8s client, and the wandb resource itself. This aligns with the changes in the implementation and ensures the license is retrieved from the correct namespace.pkg/wandb/spec/utils/utils_suite_test.go (4)
3-16: Good addition of necessary imports for K8s testing.These imports support the new Kubernetes testing environment setup, which is essential for properly testing the modified license functionality.
18-20: Properly declared global variables for K8s testing.These variables establish the foundation for the Kubernetes test environment, client, and configuration - necessary components for testing Kubernetes-dependent functionality.
27-51: Well-structured test environment setup.The BeforeSuite function properly initializes the test environment with appropriate error checking at each step. This ensures tests have a valid Kubernetes environment to interact with.
53-57: Clean test environment teardown.The AfterSuite function ensures proper cleanup of test resources, which is important to prevent resource leaks during testing.
pkg/wandb/spec/utils/license.go (4)
14-15: Improved function signature with necessary context and client parameters.The function now accepts the required parameters (context, K8s client, wandb object) to correctly retrieve license information, and uses a context-aware logger. This is more aligned with Kubernetes controller patterns.
38-38: Fixed namespace retrieval to use wandb resource namespace.This is the core fix that addresses the PR objective - now getting the namespace directly from the wandb object rather than from spec values. This ensures the secret is always looked up in the correct namespace.
41-41: Updated secret retrieval with the passed client.Now using the provided Kubernetes client instead of creating a new one, which is more efficient and aligned with controller patterns.
51-51: Updated helper function signature to use consistent parameter naming.Changed parameter name from
kubeClienttok8sClientfor consistency with the calling function.pkg/wandb/spec/utils/license_test.go (6)
4-12: Added required imports for enhanced license functionality.The added imports are necessary to support the expanded functionality of the
GetLicensefunction, which now requires a Kubernetes context, client, and type definitions for working with Kubernetes resources.
16-16: Context description updated for clarity.Changing from "when the license is set" to "when the license is set via values" provides better specificity about the test scenario, clearly differentiating it from the new secret-based approach.
25-31: Updated test for license from values with new function signature.The test now correctly uses the expanded function signature, passing the required context, Kubernetes client, and WeightsAndBiases object with namespace information to match the updated implementation.
34-54: Good addition of test for missing license secret.This test case verifies the behavior when a license secret is referenced but doesn't exist in the cluster, ensuring the function gracefully returns an empty string rather than failing.
94-100: Updated test for no license with new function signature.The test for when no license is set has been correctly updated to use the new function signature with context, client, and WeightsAndBiases object.
1-104:Details
❌ Incorrect review comment
Missing k8sClient setup in test file.
The tests use a global
k8sClientvariable, but I don't see where it's defined or initialized in this file. Ensure that the test setup properly initializes the Kubernetes client, possibly in aBeforeSuiteblock or by importing from a test suite helper.
🏁 Script executed:
#!/bin/bash # Search for k8sClient setup in test files echo "Searching for k8sClient setup in test files..." rg -A 5 "var\s+k8sClient" --type goLength of output: 1245
Review Update: k8sClient Initialization Confirmed
After verifying the codebase, it’s clear that the global
k8sClientis defined and initialized in the test suite filepkg/wandb/spec/utils/utils_suite_test.go(and similarly in other suite test files). There is no need to add any additional setup in this test file. Please ensure you're running the tests within the full suite context where thek8sClientis correctly established.Likely an incorrect or invalid review comment.
|
|
||
| By("bootstrapping test environment") | ||
| testEnv = &envtest.Environment{ | ||
| CRDDirectoryPaths: []string{filepath.Join("..", "..", "..", "..", "config", "crd", "bases")}, |
There was a problem hiding this comment.
This looks a little odd, but I don't think there is a better solution. Maybe there is a basedir?
### [1.19.3](v1.19.2...v1.19.3) (2025-03-26) ### Bug Fixes * Look for secret in namespace of wandb CR ([#78](#78)) ([e374c9a](e374c9a))
|
This PR is included in version 1.19.3 🎉 |
## 1.0.0 (2025-04-11) ### Features * Add active-state cm ([wandb#2](https://github.com/sqaisar/wandb-operator/issues/2)) ([5a6c4c3](5a6c4c3)) * Add caching for deployer release requests ([1185b40](1185b40)) * Add events recording ([388d37b](388d37b)) * Add helm support ([077765c](077765c)) * Add option to set reconcileFrequency ([484c014](484c014)) * Add support for helm repo releases ([dfef752](dfef752)) * Add support for release from a git repository ([8a6b073](8a6b073)) * Adding owner ref and wait and timeout to uninstall ([wandb#51](https://github.com/sqaisar/wandb-operator/issues/51)) ([f21fd6d](f21fd6d)) * Allow the operator to support installation without cluster level permissions ([wandb#16](https://github.com/sqaisar/wandb-operator/issues/16)) ([6f29a3e](6f29a3e)) * Make wandb operator available on OperatorHub ([wandb#32](https://github.com/sqaisar/wandb-operator/issues/32)) ([1a59dab](1a59dab)) * **operator:** Add airgapped support ([wandb#12](https://github.com/sqaisar/wandb-operator/issues/12)) ([bfd3796](bfd3796)) * Prevent Logging of Sensitive info in Plain Text ([wandb#31](https://github.com/sqaisar/wandb-operator/issues/31)) ([5530cb3](5530cb3)) * Prevent Logging of Sensitive info in Plain Text ([wandb#35](https://github.com/sqaisar/wandb-operator/issues/35)) ([9a752fd](9a752fd)) * Release Version Pinning Init ([wandb#28](https://github.com/sqaisar/wandb-operator/issues/28)) ([dfe8bda](dfe8bda)) * Replace base image with RHEL UBI ([wandb#44](https://github.com/sqaisar/wandb-operator/issues/44)) ([12497d2](12497d2)) * Support for deploymenting via jobs ([da801ea](da801ea)) * Updated license.go file to include the feature for licenseSecret as well ([wandb#54](https://github.com/sqaisar/wandb-operator/issues/54)) ([bb55caa](bb55caa)) * Use container based deployments only ([3e6b222](3e6b222)) * use secrets instead of configmaps ([049797f](049797f)) ### Bug Fixes * add applied config to download bundle ([bef77c2](bef77c2)) * Add console namespace and service name to config properties ([0b9efef](0b9efef)) * Add debugging for installing release ([893ebd9](893ebd9)) * add gh token for ci ([72d456f](72d456f)) * add license log ([wandb#11](https://github.com/sqaisar/wandb-operator/issues/11)) ([e129fab](e129fab)) * Add operator namespace env ([846731a](846731a)) * add operator properties to config ([b5f48f0](b5f48f0)) * add pnpm, node and git to docker image ([176b6f0](176b6f0)) * Add Tilt configs for local development ([wandb#53](https://github.com/sqaisar/wandb-operator/issues/53)) ([5ef82b5](5ef82b5)) * added changelog commits ([61b5f5d](61b5f5d)) * Assign metadata instead of merging it ([908c839](908c839)) * Basic Auth Fix ([wandb#56](https://github.com/sqaisar/wandb-operator/issues/56)) ([414b2cf](414b2cf)) * Bump controller tools version to latest ([wandb#13](https://github.com/sqaisar/wandb-operator/issues/13)) ([c52dbb6](c52dbb6)) * Bump deps ([wandb#36](https://github.com/sqaisar/wandb-operator/issues/36)) ([eefb59c](eefb59c)) * Bump deps ([wandb#70](https://github.com/sqaisar/wandb-operator/issues/70)) ([11ba9f8](11ba9f8)) * Channel spec not getting applied correctly ([6e763a8](6e763a8)) * Charts download ([57355ce](57355ce)) * Clean up docker image ([ef7c629](ef7c629)) * clean up env for image push ([7213ed2](7213ed2)) * Correct merge order ([cd49cef](cd49cef)) * correctly check if chart is installed based on status ([384d330](384d330)) * Create release rc files ([f7f4622](f7f4622)) * Debug logging errors ([wandb#26](https://github.com/sqaisar/wandb-operator/issues/26)) ([a641621](a641621)) * Debug logging the cache ([wandb#21](https://github.com/sqaisar/wandb-operator/issues/21)) ([26e8fd5](26e8fd5)) * Debugging logic ([wandb#22](https://github.com/sqaisar/wandb-operator/issues/22)) ([2c019b8](2c019b8)) * Default to dev mode ([d961f77](d961f77)) * docker build ([d160a9c](d160a9c)) * docker image push ([e08b3da](e08b3da)) * Git release pulls correctly ([d47aebd](d47aebd)) * init controller ([0f0a9e9](0f0a9e9)) * install go version ([6664b4b](6664b4b)) * Install kubectl in docker image ([e5df9de](e5df9de)) * Jobs work? ([9972d26](9972d26)) * kubectl not working in docker image ([ffc694e](ffc694e)) * Local_resource and kubectl apply could risk deploying to the wrong context ([wandb#66](https://github.com/sqaisar/wandb-operator/issues/66)) ([a90a270](a90a270)) * lock pnpm version ([c2608f7](c2608f7)) * Log the diff of specs ([wandb#23](https://github.com/sqaisar/wandb-operator/issues/23)) ([c0ea0d8](c0ea0d8)) * Look for secret in namespace of wandb CR ([wandb#78](https://github.com/sqaisar/wandb-operator/issues/78)) ([e374c9a](e374c9a)) * Mask sensitive values in log ([wandb#14](https://github.com/sqaisar/wandb-operator/issues/14)) ([514336d](514336d)) * merge func ([94aa0d0](94aa0d0)) * Output json format logs ([90af7b6](90af7b6)) * Pass namespace into chart ([e8e0b8f](e8e0b8f)) * pass spec namespace and name ([79d77f2](79d77f2)) * Preserve unknown fields ([565a25f](565a25f)) * properly get license ([6ff6533](6ff6533)) * Properly merge chart specs together ([37c41bc](37c41bc)) * Properly parse chart from deployer ([5eabdfe](5eabdfe)) * Properly set namespace for deployments ([53f51a9](53f51a9)) * Properly update complete status ([86a5196](86a5196)) * push images to dockerhub ([d4cdd27](d4cdd27)) * refactor spec ([87be86b](87be86b)) * Refactor specs ([7c6da34](7c6da34)) * Release needs ginkgo ([wandb#65](https://github.com/sqaisar/wandb-operator/issues/65)) ([c51df78](c51df78)) * remove console ([fba45ee](fba45ee)) * remove debugging logs ([d4da31f](d4da31f)) * remove submodule ([bdb408a](bdb408a)) * Remove ui building step ([08ee985](08ee985)) * Rename config -> values and release -> chart ([519cd1b](519cd1b)) * Rename config spec cfs ([672100a](672100a)) * rename configs ([8727281](8727281)) * rename docker variables ([274e20c](274e20c)) * rename versioning step name ([77bf4ed](77bf4ed)) * reorder backup ([ab66486](ab66486)) * revert to v2 for semver ([535a721](535a721)) * Save active spec metadata ([47bd862](47bd862)) * Secret reading metadata ([6dab7ed](6dab7ed)) * secrets stored with correct values ([f6d61e9](f6d61e9)) * Serve console with gin ([c9e04aa](c9e04aa)) * set namespace when running kubectl apply ([1d6f00c](1d6f00c)) * Setting cached release namespace incorrectly ([e585555](e585555)) * Simplify docker image ([1cf55e4](1cf55e4)) * Support Openshift permissions schema for the helm cache ([wandb#17](https://github.com/sqaisar/wandb-operator/issues/17)) ([b498f79](b498f79)) * TLS ([wandb#67](https://github.com/sqaisar/wandb-operator/issues/67)) ([0d3013c](0d3013c)) * Tmp directory permissions ([b0820f5](b0820f5)) * Update to fix some CVEs ([wandb#55](https://github.com/sqaisar/wandb-operator/issues/55)) ([9a34cbe](9a34cbe)) * upgrade semantic to v3 ([594c463](594c463)) * Use cdk8s image for apply container ([189bc08](189bc08)) * Use deployer release channels ([480b380](480b380)) * Using validate for job spec ([5c7ff66](5c7ff66)) * x-kubernetes-preserve-unknown-fields ([bedac52](bedac52))
Summary by CodeRabbit
New Features
Chores
Tests