-
-
Notifications
You must be signed in to change notification settings - Fork 301
Fix bug with CloudRunner and K8s with Namespaces #763
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
base: main
Are you sure you want to change the base?
Conversation
…r is kicked from self hosted k8s agents that are in a non default namespace)
📝 WalkthroughWalkthroughAdds support for custom Kubernetes container namespaces. A new Changes
Sequence DiagramsequenceDiagram
participant opts as CloudRunnerOptions
participant bp as BuildParameters
participant k8s as K8s Provider
participant kubectl as kubectl Task Runner
opts->>opts: containerNamespace (static getter)
opts-->>bp: return default or input value
bp->>bp: create() with containerNamespace
bp->>k8s: initialize with buildParameters
k8s->>k8s: set namespace = containerNamespace
k8s->>kubectl: namespace available
kubectl->>kubectl: append -n ${namespace} to logs flags
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10-15 minutes
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 inconclusive)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (2)
src/model/cloud-runner/providers/k8s/index.ts (2)
48-48: Simplify the conditional expression.The ternary operator can be simplified to use the logical OR operator for better readability.
Apply this diff:
- this.namespace = buildParameters.containerNamespace ? buildParameters.containerNamespace : 'default'; + this.namespace = buildParameters.containerNamespace || 'default';
48-48: Consider validating namespace existence and permissions.To provide better error messages and fail fast, consider validating that:
- The specified namespace exists in the cluster
- The service account has necessary permissions in that namespace
This would prevent cryptic runtime errors during job creation or pod operations.
Example validation logic could be added after line 48:
// Validate namespace exists try { await this.kubeClient.readNamespace(this.namespace); CloudRunnerLogger.log(`Using Kubernetes namespace: ${this.namespace}`); } catch (error: any) { throw new Error( `Kubernetes namespace '${this.namespace}' does not exist or is not accessible. ` + `Please ensure the namespace exists and the service account has appropriate permissions.` ); }
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (2)
dist/index.jsis excluded by!**/dist/**dist/index.js.mapis excluded by!**/dist/**,!**/*.map
📒 Files selected for processing (4)
src/model/build-parameters.ts(2 hunks)src/model/cloud-runner/options/cloud-runner-options.ts(1 hunks)src/model/cloud-runner/providers/k8s/index.ts(1 hunks)src/model/cloud-runner/providers/k8s/kubernetes-task-runner.ts(1 hunks)
🔇 Additional comments (5)
src/model/cloud-runner/options/cloud-runner-options.ts (1)
138-140: LGTM! Implementation follows established patterns.The new
containerNamespacegetter correctly defaults to'default'and follows the same pattern as other container configuration getters likecontainerCpuandcontainerMemory.src/model/build-parameters.ts (2)
62-62: LGTM! Field declaration follows the established pattern.The new
containerNamespacefield is properly declared and positioned logically near other Kubernetes-related configuration fields.
191-191: LGTM! Mapping correctly integrates the new parameter.The field is properly mapped from
CloudRunnerOptions.containerNamespacein thecreate()method, following the same pattern as other CloudRunner options.src/model/cloud-runner/providers/k8s/kubernetes-task-runner.ts (1)
33-34: Excellent fix! Namespace flag now consistently specified.This change ensures that
kubectl logscommands always include the-n ${namespace}flag in both code paths (running pod with follow mode and previous/terminated pod mode). This directly addresses the bug where kubectl would otherwise default to the runner's current namespace context, causing failures when the runner is in a different namespace than the workload.src/model/cloud-runner/providers/k8s/index.ts (1)
48-48: The review comment references code that does not exist in the repository.The review comment points to line 48 showing
this.namespace = buildParameters.containerNamespace ? buildParameters.containerNamespace : 'default';but the actual code at line 49 hardcodes the namespace to'default'. ThecontainerNamespaceproperty is not present in buildParameters anywhere in the codebase.Currently, users cannot specify arbitrary Kubernetes namespaces—the namespace is fixed to
'default'. The security concerns about RBAC permissions and namespace validation do not apply since there is no user-configurable namespace selection mechanism in the current code.Likely an incorrect or invalid review comment.

Changes
Successful Workflow Run Link
PRs don't have access to secrets so you will need to provide a link to a successful run of the workflows from your own
repo.
Checklist
code of conduct
in the documentation repo)
Summary by CodeRabbit
containerNamespaceconfiguration for Kubernetes deployments. Users can now specify a custom namespace; if not provided, it defaults to 'default'. The namespace is properly applied across build operations and log retrieval.✏️ Tip: You can customize this high-level summary in your review settings.