WIP: OCPBUGS-10431: clear staticPodPath template default when user sets it to empty - #6319
WIP: OCPBUGS-10431: clear staticPodPath template default when user sets it to empty#6319harche wants to merge 1 commit into
Conversation
|
Pipeline controller notification For optional jobs, comment This repository is configured in: LGTM mode |
|
@harche: This pull request references Jira Issue OCPBUGS-10431, which is invalid:
Comment The bug has been updated to refer to the pull request using the external bug tracker. 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. |
|
Skipping CI for Draft Pull Request. |
WalkthroughKubelet configuration generation now preserves an explicitly empty ChangesStatic Pod Path Handling
Estimated code review effort: 2 (Simple) | ~10 minutes 🚥 Pre-merge checks | ✅ 14 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (14 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 |
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: harche 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 |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (2)
pkg/controller/kubelet-config/helpers.go (1)
6-6: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueRemove unused import.
If you apply the suggested fix below to use
yaml.NewYAMLOrJSONDecoderinstead ofjson.Unmarshal, thisencoding/jsonimport will become unused and can be removed.♻️ Proposed refactor
- "encoding/json"🤖 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 `@pkg/controller/kubelet-config/helpers.go` at line 6, Remove the unused encoding/json import from the imports in helpers.go after replacing json.Unmarshal with yaml.NewYAMLOrJSONDecoder.pkg/controller/kubelet-config/staticpodpath_render_test.go (1)
69-69: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueAvoid reusing a mutable configuration object without copying.
generateKubeletIgnFilesmutates theoriginalKubeConfigobject throughmergo.Mergeand direct field assignments. The subsequentoriginal2 := originalKubeConfig.DeepCopy()at line 86 copies the already-mutated state from this first call. To ensure the second test case runs against a pristine configuration, deep copyoriginalKubeConfigbefore passing it to the first function call.♻️ Proposed fix
- kubeletIgn, _, _, err := generateKubeletIgnFiles(kc, originalKubeConfig) + kubeletIgn, _, _, err := generateKubeletIgnFiles(kc, originalKubeConfig.DeepCopy())🤖 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 `@pkg/controller/kubelet-config/staticpodpath_render_test.go` at line 69, Deep-copy originalKubeConfig before the first generateKubeletIgnFiles call so that function receives an isolated mutable configuration. Preserve the existing originalKubeConfig object for the later original2 copy, ensuring both test cases start from pristine state.
🤖 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.
Inline comments:
In `@pkg/controller/kubelet-config/helpers.go`:
- Around line 556-561: Update the raw kubelet configuration parsing near
DecodeKubeletConfig to use yaml.NewYAMLOrJSONDecoder, preserving support for
both YAML and JSON payloads. Handle and explicitly return the decoder error
instead of silently skipping the staticPodPath override, while retaining the
existing override behavior for an explicitly empty value.
---
Nitpick comments:
In `@pkg/controller/kubelet-config/helpers.go`:
- Line 6: Remove the unused encoding/json import from the imports in helpers.go
after replacing json.Unmarshal with yaml.NewYAMLOrJSONDecoder.
In `@pkg/controller/kubelet-config/staticpodpath_render_test.go`:
- Line 69: Deep-copy originalKubeConfig before the first generateKubeletIgnFiles
call so that function receives an isolated mutable configuration. Preserve the
existing originalKubeConfig object for the later original2 copy, ensuring both
test cases start from pristine state.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository: openshift/coderabbit/.coderabbit.yaml
Review profile: CHILL
Plan: Enterprise
Run ID: b8b438f0-eb46-4464-9b89-23b7534cbe3b
📒 Files selected for processing (2)
pkg/controller/kubelet-config/helpers.gopkg/controller/kubelet-config/staticpodpath_render_test.go
… to empty mergo.Merge never overwrites a destination field with a zero-value source, so an explicit staticPodPath "" in a KubeletConfig CR passes validation (after openshift#5724) but is dropped during the merge, and the rendered kubelet.conf still contains the template default /etc/kubernetes/manifests. Detect the explicit empty value in the raw config with a YAMLOrJSON presence check and clear the default before merging, mirroring the existing protectKernelDefaults workaround. Add a render-path test asserting that an explicit empty staticPodPath (JSON or YAML) clears the default and that an unset field keeps it.
3625b20 to
460b78c
Compare
|
@harche: This pull request references Jira Issue OCPBUGS-10431. The bug has been updated to no longer refer to the pull request using the external bug tracker. 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. |
The kube-rbac-proxy-crio static pod (added in openshift#4175 / OCPNODE-2098) is the only static pod that runs on every node role, which blocks disabling staticPodPath on worker pools to satisfy STIG V-242397: removing staticPodPath kills the proxy, port 9637 goes dead, and CRI-O metrics disappear for those nodes. Run the proxy as a container in the machine-config-daemon daemonset instead. The daemonset is hostNetwork, so the container still binds node:9637 and forwards to CRI-O's loopback-only metrics endpoint at 127.0.0.1:9537 using the same kubelet serving certificate and client CA, keeping the cluster-monitoring-operator kubelet ServiceMonitor scrape chain (job="crio") unchanged. The static authorizer config moves from a MachineConfig-written host file to the kube-rbac-proxy-crio ConfigMap, and the proxy now uses in-cluster service account credentials (the MCD service account already holds tokenreview/subjectaccessreview permissions) instead of the kubelet kubeconfig. The kube-rbac-proxy-crio Service selects the machine-config-daemon pods so its endpoints keep pointing at port 9637. Upgrade ordering: the operator waits for the MCD daemonset rollout before it syncs the node configs that delete the static pod manifest, so the new container waits for the manifest to disappear and the port to be released before starting the proxy rather than crashlooping on a bind failure and deadlocking the rollout. The container also declares no ports: with hostNetwork a declared containerPort acts as a hostPort, and the kubelet would reject the pod at admission while the legacy static pod still declares port 9637. Also clear the staticPodPath template default when a KubeletConfig sets it to empty (previously in openshift#6319): the rendered config is produced by mergo.Merge, which never overwrites a field with an empty value, so staticPodPath: "" was silently ignored while the CR reported Success — the same empty-value problem already worked around for protectKernelDefaults. With both changes, disabling staticPodPath on worker pools resolves STIG V-242397 without losing CRI-O metrics. Verified on two live 4.22.6 clusters: daemonset rolls out Ready while the static pods still exist, hands off port 9637 as each node updates, up{job="crio"} stays 1 on all nodes throughout, and staticPodPath: "" on workers removes the setting from kubelet.conf with metrics uninterrupted. Claude-Session: https://claude.ai/code/session_01ChGPtsm6ZxReyA3oZjq79o
- What I did
Follow-up to #5724. That PR relaxed validation so a KubeletConfig CR with
staticPodPath: ""is accepted for worker and custom pools, but the empty value never reached the rendered kubelet.conf:mergo.Merge(..., mergo.WithOverride)ingenerateKubeletIgnFilesdoes not overwrite a destination field with a zero-value source, so the template default/etc/kubernetes/manifestssurvived the merge.This change detects an explicit
staticPodPath: ""in the raw KubeletConfig (presence check on the raw JSON, since after decoding an explicit empty value is indistinguishable from unset) and clears the template default before merging, mirroring the existingprotectKernelDefaultsworkaround a few lines above.Also adds a render-path unit test asserting that:
{"staticPodPath":""}renders a kubelet.conf without/etc/kubernetes/manifestsstaticPodPathkeeps the template default- How to verify it
staticPodPath: ""oc get mc 99-worker-generated-kubelet -o yaml) or/etc/kubernetes/kubelet.confon a worker node: thestaticPodPathentry should be absentstaticPodPath: /etc/kubernetes/manifestseven though the CR is accepted- Description for the changelog
Fix
staticPodPath: ""in a KubeletConfig CR not taking effect in the rendered kubelet configuration.WIP: pending cluster testing.
Summary by CodeRabbit
Bug Fixes
staticPodPathso it’s rendered as intended, rather than falling back to the template default.Tests
staticPodPathbehavior when the value is omitted or explicitly empty, validating handling across supported configuration input formats.