NO-JIRA: fix default namespace pull secret patch when imagePullSecrets is missing#16788
NO-JIRA: fix default namespace pull secret patch when imagePullSecrets is missing#16788kchawlani19 wants to merge 1 commit into
Conversation
…lSecrets Fetch the latest default ServiceAccount during pull secret submit and choose the JSON patch path based on whether imagePullSecrets already exists. Add focused regression tests for patch selection and submit flow sequencing. Co-authored-by: Cursor <cursoragent@cursor.com>
|
Pipeline controller notification For optional jobs, comment This repository is configured in: LGTM mode |
|
@kchawlani19: This pull request explicitly references no jira issue. DetailsIn response to this:
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 openshift-eng/jira-lifecycle-plugin repository. |
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: kchawlani19 The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
WalkthroughThe modal now creates a namespace pull secret, fetches the default service account, and applies a conditional JSON patch depending on whether ChangesNamespace pull secret configuration
Estimated code review effort: 3 (Moderate) | ~20 minutes Sequence Diagram(s)sequenceDiagram
participant Modal
participant KubernetesAPI
participant Overlay
Modal->>KubernetesAPI: Create pull secret
Modal->>KubernetesAPI: Fetch default ServiceAccount
Modal->>KubernetesAPI: Apply conditional JSON patch
Modal->>Overlay: Close overlay
🚥 Pre-merge checks | ✅ 15✅ Passed checks (15 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.
🧹 Nitpick comments (1)
frontend/public/components/modals/configure-ns-pull-secret-modal.tsx (1)
157-160: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valuePrefer native checks over Lodash for improved robustness.
Using
Array.isArrayprovides a stronger guarantee thatimagePullSecretsis actually an array before computing a patch that appends to it (/-). This avoids potential422 Unprocessable EntityAPI errors in the rare event that the field is explicitly set tonull, and it reduces reliance on Lodash.♻️ Proposed refactor
const defaultServiceAccountPatch = getDefaultServiceAccountPatch( - _.has(serviceAccount, 'imagePullSecrets'), + Array.isArray(serviceAccount?.imagePullSecrets), pullSecretName, );🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@frontend/public/components/modals/configure-ns-pull-secret-modal.tsx` around lines 157 - 160, Replace the Lodash _.has check in the defaultServiceAccountPatch computation with an Array.isArray check on serviceAccount.imagePullSecrets, so the append patch is generated only when the field is an actual array and not when it is null or another non-array value.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@frontend/public/components/modals/configure-ns-pull-secret-modal.tsx`:
- Around line 157-160: Replace the Lodash _.has check in the
defaultServiceAccountPatch computation with an Array.isArray check on
serviceAccount.imagePullSecrets, so the append patch is generated only when the
field is an actual array and not when it is null or another non-array value.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository: openshift/coderabbit/.coderabbit.yaml
Review profile: CHILL
Plan: Enterprise
Run ID: 90304646-0cd6-4970-afe6-b75674fd8b35
📒 Files selected for processing (2)
frontend/public/components/modals/__tests__/configure-ns-pull-secret-modal.spec.tsxfrontend/public/components/modals/configure-ns-pull-secret-modal.tsx
|
@kchawlani19: The following test failed, say
Full PR test history. Your PR dashboard. DetailsInstructions 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. |
Problem
Creating a default pull secret in a newly created namespace can fail with an invalid ServiceAccount patch request.
Root cause
The submit flow always attempted to append using JSON patch path
/imagePullSecrets/-on the default ServiceAccount.For new namespaces,
imagePullSecretsmay not exist yet, so append-to-array fails.Solution
imagePullSecretsexists: append to/imagePullSecrets/-/imagePullSecretswith the new secret entryk8sCreate -> k8sGet -> k8sPatchByName)k8sGetcall argumentsTesting
node .yarn/releases/yarn-4.14.1.cjs test public/components/modals/__tests__/configure-ns-pull-secret-modal.spec.tsx public/components/__tests__/namespace.spec.tsx --runInBandnode .yarn/releases/yarn-4.14.1.cjs eslint public/components/modals/configure-ns-pull-secret-modal.tsx public/components/modals/__tests__/configure-ns-pull-secret-modal.spec.tsxNotes
Summary by CodeRabbit
Bug Fixes
Tests