Skip to content

fix: ensure kubelet and containerd in kube.slice via systemd drop-ins#8958

Open
titilambert wants to merge 11 commits into
mainfrom
fix-test-ensure-kubelet-and
Open

fix: ensure kubelet and containerd in kube.slice via systemd drop-ins#8958
titilambert wants to merge 11 commits into
mainfrom
fix-test-ensure-kubelet-and

Conversation

@titilambert

@titilambert titilambert commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

What this PR does / why we need it:

When node hardening is enabled, ensureKubeletCgroupHierarchy() creates a dedicated kubelet.slice for kube-reserved cgroup enforcement. However the existing drop-in for kubelet.service only declared Wants= and After= ordering — it did not set Slice=kubelet.slice, so kubelet remained in system.slice. Additionally, containerd.service had no drop-in at all and was never placed in the slice.

This PR fixes both issues:

  1. Adds Slice=kubelet.slice to the kubelet drop-in so kubelet actually runs inside the dedicated slice.
  2. Creates an equivalent drop-in for containerd.service (10-kubelet-slice.conf) so containerd is co-located in the same slice.

Without this fix, cgroup resource accounting under kubelet.slice is incomplete — node hardening's kube-reserved budget doesn't capture the real resource usage of kubelet and containerd, which blocks nodes to be ready since they are affected to system.slice which has a low max memory limit

Testing:

  • Updated ShellSpec tests to validate both drop-ins are written with the
    correct [Service] Slice=kubelet.slice directive.
  •  $ systemctl status containerd | grep "CGroup"
     CGroup: /kubelet.slice/containerd.service
     $ systemctl status kubelet | grep "CGroup"
     CGroup: /kubelet.slice/kubelet.service
    

Which issue(s) this PR fixes:

Fixes #

@titilambert

Copy link
Copy Markdown
Contributor Author

This change is part of the following stack:

Change managed by git-spice.

Copilot AI 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.

Pull request overview

This PR updates the Linux CSE helper responsible for Node Memory Hardening cgroup hierarchy setup so that both kubelet and containerd are configured to run under kubelet.slice, and adjusts ShellSpec coverage accordingly.

Changes:

  • Extend ensureKubeletCgroupHierarchy to set Slice=kubelet.slice for kubelet.service and add a matching drop-in for containerd.service.
  • Update ShellSpec assertions to validate the additional systemd drop-in content for containerd.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
parts/linux/cloud-init/artifacts/cse_helpers.sh Adds systemd drop-ins to place kubelet and containerd into kubelet.slice when hardening cgroups are enabled.
spec/parts/linux/cloud-init/artifacts/cse_helpers_spec.sh Updates tests to assert Slice= and validates the containerd drop-in is created.

Comment thread parts/linux/cloud-init/artifacts/cse_helpers.sh Outdated
Comment thread spec/parts/linux/cloud-init/artifacts/cse_helpers_spec.sh
Copilot AI review requested due to automatic review settings July 15, 2026 19:42
@titilambert
titilambert force-pushed the fix-test-ensure-kubelet-and branch from 39476df to 4045739 Compare July 15, 2026 19:42

Copilot AI 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.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

Comment thread parts/linux/cloud-init/artifacts/cse_helpers.sh Outdated
Comment thread spec/parts/linux/cloud-init/artifacts/cse_helpers_spec.sh
@titilambert titilambert changed the title fix(test): ensure kubelet and containerd are in kubelet.slice when node hardening is on fix: place kubelet and containerd in kubelet.slice via systemd drop-ins Jul 15, 2026

@SriHarsha001 SriHarsha001 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.

We need to look into the AI's comments, apart from that changes look good to me.

Copilot AI 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.

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.

Comment thread parts/linux/cloud-init/artifacts/cse_config.sh
Comment thread parts/linux/cloud-init/artifacts/cse_config.sh
@titilambert
titilambert enabled auto-merge (squash) July 16, 2026 20:55
@aks-node-assistant

Copy link
Copy Markdown
Contributor
### AgentBaker Linux gate detective

Run: https://msazure.visualstudio.com/CloudNativeCompute/_build/results?buildId=172575900

Failed job/stage/task: e2e / Run AgentBaker E2E / Run AgentBaker E2E

Detective summary: The primary terminal failure is the known Ubuntu2204 HTTPSProxy PrivateDNS E2E proxy flake. CSE failed before kubelet startup while apt refreshed packages.microsoft.com through the scenario proxy.

Likely cause/signature: vmssCSE exited 99 after apt-get update to packages.microsoft.com via proxy 10.14.1.120:8888 returned connection refused. Wiki signature: e2e-httpsproxy-privatedns-err-outbound-conn-fail.

Confidence: High for E2E infra/proxy availability; low that this PR caused the failure.

Recommended owner/action: E2E/test-infra owner should track this under repair item #38837639 and harden proxy readiness/diagnostics for the HTTPSProxy PrivateDNS scenario. No PR action is expected from this signal.

Strongest alternative: PR CSE/helper changes broke provisioning. Less likely because the concrete failure is TCP connection refused to the scenario proxy during apt-get update, before kubelet/containerd slice behavior was reached.

Evidence:

Copilot AI review requested due to automatic review settings July 17, 2026 13:15
@titilambert
titilambert force-pushed the fix-test-ensure-kubelet-and branch from 4da0d05 to 939cc03 Compare July 17, 2026 13:15

Copilot AI 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.

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.

Comment on lines +885 to +889
tee "/etc/systemd/system/kubelet.service.d/10-containerd-base-flag.conf" > /dev/null <<EOF
[Service]
Environment="KUBELET_CONTAINERD_FLAGS=--runtime-request-timeout=15m --container-runtime-endpoint=unix:///run/containerd/containerd.sock --runtime-cgroups=${containerd_runtime_cgroups}"
EOF

Comment thread e2e/validators.go
Comment on lines +3490 to +3499
// ValidateServiceInSlice asserts that the given systemd service is running in the expected slice.
func ValidateServiceInSlice(ctx context.Context, s *Scenario, service, expectedSlice string) {
s.T.Helper()
result := execScriptOnVMForScenarioValidateExitCode(ctx, s,
fmt.Sprintf("systemctl show %s -p Slice --value", service), 0,
fmt.Sprintf("could not query Slice property of %s", service))
actual := strings.TrimSpace(result.stdout)
require.Equal(s.T, expectedSlice, actual,
"expected %s to be in %s, but got %s", service, expectedSlice, actual)
}
@titilambert
titilambert disabled auto-merge July 17, 2026 13:24
@aks-node-assistant

Copy link
Copy Markdown
Contributor

AgentBaker Linux gate detective

Run: https://msazure.visualstudio.com/CloudNativeCompute/_build/results?buildId=172680420

Failed job/stage/task: e2e / Run AgentBaker E2E / Go package compile

Detective summary: The E2E gate failed before running any tests because the e2e package did not compile.

Likely cause/signature: scenario_test.go references SkipScriptlessNBC in a Config literal, but Config does not define that field. Wiki signature: e2e-compile-config-unknown-field-skip-scriptless-nbc.

Confidence: Very high that this is PR/test-code caused; infra was not reached.

Recommended owner/action: PR author should fix the Config field definition or use the correct config struct/field and run an E2E compile check before retrying the gate.

Strongest alternative: stale generated source or checkout mismatch. Less likely because the compiler points at the PR-touched scenario_test.go and zero tests ran.

Evidence:

Copilot AI review requested due to automatic review settings July 17, 2026 20:36
@github-actions

github-actions Bot commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

The latest Buf updates on your PR. Results from workflow Buf CI / buf (pull_request).

BuildFormatLintBreakingUpdated (UTC)
✅ passed✅ passed✅ passed✅ passedJul 17, 2026, 9:28 PM

@github-actions

Copy link
Copy Markdown
Contributor

The latest Buf updates on your PR. Results from workflow Buf CI / buf (pull_request).

BuildFormatLintBreakingUpdated (UTC)
✅ passed✅ passed✅ passed✅ passedJul 17, 2026, 8:36 PM

@titilambert titilambert changed the title fix: ensure kubelet and containerd in kubelet.slice via systemd drop-ins fix: ensure kubelet and containerd in kube.slice via systemd drop-ins Jul 17, 2026

Copilot AI 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.

Pull request overview

Copilot reviewed 9 out of 10 changed files in this pull request and generated 2 comments.

Files not reviewed (1)
  • aks-node-controller/pkg/gen/aksnodeconfig/v1/kubelet_config.pb.go: Generated file

Comment on lines 1543 to 1551
# Validate supported values: only /kube.slice (or bare kube.slice) is
# supported for KUBE_RESERVED_CGROUP, and only /system.slice for
# SYSTEM_RESERVED_CGROUP (a built-in systemd slice). Reject any other value
# explicitly so kubelet doesn't fail later with an opaque enforcement error.
case "${KUBE_RESERVED_CGROUP:-}" in
""|"/kubelet.slice"|"kubelet.slice") ;;
""|"/kube.slice"|"kube.slice") ;;
*)
echo "ensureKubeletCgroupHierarchy: unsupported KUBE_RESERVED_CGROUP=${KUBE_RESERVED_CGROUP}; only /kubelet.slice is supported"
echo "ensureKubeletCgroupHierarchy: unsupported KUBE_RESERVED_CGROUP=${KUBE_RESERVED_CGROUP}; only /kube.slice is supported"
return 1
Comment thread e2e/scenario_test.go
})
}

func Test_Ubuntu2204_NodeHardening_KubeletSlice(t *testing.T) {
Copilot AI review requested due to automatic review settings July 17, 2026 21:28

Copilot AI 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.

Pull request overview

Copilot reviewed 9 out of 10 changed files in this pull request and generated 3 comments.

Files not reviewed (1)
  • aks-node-controller/pkg/gen/aksnodeconfig/v1/kubelet_config.pb.go: Generated file

Comment on lines +1543 to 1551
# Validate supported values: only /kube-reserved.slice (or bare kube-reserved.slice) is
# supported for KUBE_RESERVED_CGROUP, and only /system.slice for
# SYSTEM_RESERVED_CGROUP (a built-in systemd slice). Reject any other value
# explicitly so kubelet doesn't fail later with an opaque enforcement error.
case "${KUBE_RESERVED_CGROUP:-}" in
""|"/kubelet.slice"|"kubelet.slice") ;;
""|"/kube-reserved.slice"|"kube-reserved.slice") ;;
*)
echo "ensureKubeletCgroupHierarchy: unsupported KUBE_RESERVED_CGROUP=${KUBE_RESERVED_CGROUP}; only /kubelet.slice is supported"
echo "ensureKubeletCgroupHierarchy: unsupported KUBE_RESERVED_CGROUP=${KUBE_RESERVED_CGROUP}; only /kube-reserved.slice is supported"
return 1
Comment on lines +885 to +889
tee "/etc/systemd/system/kubelet.service.d/10-containerd-base-flag.conf" > /dev/null <<EOF
[Service]
Environment="KUBELET_CONTAINERD_FLAGS=--runtime-request-timeout=15m --container-runtime-endpoint=unix:///run/containerd/containerd.sock --runtime-cgroups=${containerd_runtime_cgroups}"
EOF

Comment thread e2e/scenario_test.go
})
}

func Test_Ubuntu2204_NodeHardening_KubeletSlice(t *testing.T) {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants