From 5cf3c4fdd2b5d8d90a64ec91f81163f7cb6318a5 Mon Sep 17 00:00:00 2001 From: Karthik Bhat Date: Wed, 11 Mar 2026 11:46:14 +0530 Subject: [PATCH 1/2] Replaces hardcoded `/var/lib/kubelet` paths with `framework.TestContext.KubeletRootDir` in node e2e tests --- test/e2e_node/node_problem_detector_linux.go | 5 ++--- test/e2e_node/quota_lsci_test.go | 8 ++------ test/e2e_node/volume_manager_test.go | 8 +++----- 3 files changed, 7 insertions(+), 14 deletions(-) diff --git a/test/e2e_node/node_problem_detector_linux.go b/test/e2e_node/node_problem_detector_linux.go index da8e7b4694a..35e9610d804 100644 --- a/test/e2e_node/node_problem_detector_linux.go +++ b/test/e2e_node/node_problem_detector_linux.go @@ -23,6 +23,7 @@ import ( "fmt" "os" "path" + "path/filepath" "time" "github.com/onsi/ginkgo/v2" @@ -295,9 +296,7 @@ current-context: local-context }, }, }) - // TODO: remove hardcoded kubelet volume directory path - // framework.TestContext.KubeVolumeDir is currently not populated for node e2e - hostLogFile = "/var/lib/kubelet/pods/" + string(pod.UID) + "/volumes/kubernetes.io~empty-dir" + logFile + hostLogFile = filepath.Join(framework.TestContext.KubeletRootDir, "pods", string(pod.UID), "volumes/kubernetes.io~empty-dir") + logFile }) ginkgo.It("should generate node condition and events for corresponding errors", func(ctx context.Context) { diff --git a/test/e2e_node/quota_lsci_test.go b/test/e2e_node/quota_lsci_test.go index f4bf6cc059d..eb4b9fba94d 100644 --- a/test/e2e_node/quota_lsci_test.go +++ b/test/e2e_node/quota_lsci_test.go @@ -48,10 +48,8 @@ func runOneQuotaTest(f *framework.Framework, quotasRequested bool, userNamespace sizeLimit := resource.MustParse("100Mi") useOverLimit := 101 /* Mb */ useUnderLimit := 99 /* Mb */ - // TODO: remove hardcoded kubelet volume directory path - // framework.TestContext.KubeVolumeDir is currently not populated for node e2e // As for why we do this: see comment below at isXfs. - if isXfs("/var/lib/kubelet") { + if isXfs(framework.TestContext.KubeletRootDir) { useUnderLimit = 50 /* Mb */ } priority := 0 @@ -61,12 +59,10 @@ func runOneQuotaTest(f *framework.Framework, quotasRequested bool, userNamespace ginkgo.Context(fmt.Sprintf(testContextFmt, fmt.Sprintf("use quotas for LSCI monitoring (quotas enabled: %v, userNamespacesEnabled: %v)", quotasRequested, userNamespacesEnabled)), func() { tempSetCurrentKubeletConfig(f, func(ctx context.Context, initialConfig *kubeletconfig.KubeletConfiguration) { defer withFeatureGate(LSCIQuotaFeature, quotasRequested)() - // TODO: remove hardcoded kubelet volume directory path - // framework.TestContext.KubeVolumeDir is currently not populated for node e2e if !supportsUserNS(ctx, f) { e2eskipper.Skipf("runtime does not support user namespaces") } - if quotasRequested && !supportsQuotas("/var/lib/kubelet", userNamespacesEnabled) { + if quotasRequested && !supportsQuotas(framework.TestContext.KubeletRootDir, userNamespacesEnabled) { // No point in running this as a positive test if quotas are not // enabled on the underlying filesystem. e2eskipper.Skipf("Cannot run LocalStorageCapacityIsolationFSQuotaMonitoring on filesystem without project quota enabled") diff --git a/test/e2e_node/volume_manager_test.go b/test/e2e_node/volume_manager_test.go index ab98f83e4da..5b89b5edffd 100644 --- a/test/e2e_node/volume_manager_test.go +++ b/test/e2e_node/volume_manager_test.go @@ -18,6 +18,8 @@ package e2enode import ( "context" + "fmt" + "path/filepath" "time" v1 "k8s.io/api/core/v1" @@ -27,8 +29,6 @@ import ( e2epod "k8s.io/kubernetes/test/e2e/framework/pod" admissionapi "k8s.io/pod-security-admission/api" - "fmt" - "github.com/onsi/ginkgo/v2" ) @@ -107,9 +107,7 @@ var _ = SIGDescribe("Kubelet Volume Manager", func() { { Name: "kubelet-pods", VolumeSource: v1.VolumeSource{ - // TODO: remove hardcoded kubelet volume directory path - // framework.TestContext.KubeVolumeDir is currently not populated for node e2e - HostPath: &v1.HostPathVolumeSource{Path: "/var/lib/kubelet/pods"}, + HostPath: &v1.HostPathVolumeSource{Path: filepath.Join(framework.TestContext.KubeletRootDir, "pods")}, }, }, }, From 79c88be4af25ab1bb67d01b64808794e9ccee5bf Mon Sep 17 00:00:00 2001 From: Karthik Bhat Date: Wed, 15 Apr 2026 16:07:59 +0530 Subject: [PATCH 2/2] Fix hostpath test failure --- test/e2e_node/e2e_node_suite_test.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/test/e2e_node/e2e_node_suite_test.go b/test/e2e_node/e2e_node_suite_test.go index 0249eb512d6..65f2333fdea 100644 --- a/test/e2e_node/e2e_node_suite_test.go +++ b/test/e2e_node/e2e_node_suite_test.go @@ -372,6 +372,13 @@ func updateTestContext(ctx context.Context) error { setExtraEnvs() updateImageAllowList(ctx) + // Set KubeletRootDir to match the kubelet configuration used in node e2e tests. + // This ensures tests that use framework.TestContext.KubeletRootDir (e.g., for HostPath volumes) + // use the correct path. + if framework.TestContext.KubeletRootDir == "" { + framework.TestContext.KubeletRootDir = services.KubeletRootDirectory + } + client, err := getAPIServerClient() if err != nil { return fmt.Errorf("failed to get apiserver client: %w", err)