diff --git a/test/e2e_node/e2e_node_suite_test.go b/test/e2e_node/e2e_node_suite_test.go index 085e1c0fd2b..b6ac3d71072 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) diff --git a/test/e2e_node/node_problem_detector_linux.go b/test/e2e_node/node_problem_detector_linux.go index 82d2bb3239d..1092d48d98a 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" @@ -296,9 +297,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")}, }, }, },