Merge pull request #8774 from mpryc/upstream_8649
Some checks failed
Run the E2E test on kind / build (push) Failing after 7m29s
Run the E2E test on kind / setup-test-matrix (push) Successful in 3s
Run the E2E test on kind / run-e2e-test (push) Has been skipped
Main CI / Build (push) Failing after 39s
Close stale issues and PRs / stale (push) Successful in 9s
Trivy Nightly Scan / Trivy nightly scan (velero, main) (push) Failing after 1m19s
Trivy Nightly Scan / Trivy nightly scan (velero-restore-helper, main) (push) Failing after 1m8s

issue 8649: host_pods should not be mandatory to node-agent
This commit is contained in:
lyndon-li
2025-03-12 08:39:00 +08:00
committed by GitHub
3 changed files with 40 additions and 17 deletions

View File

@@ -0,0 +1 @@
host_pods should not be mandatory to node-agent

View File

@@ -80,6 +80,8 @@ const (
// files will be written to
defaultCredentialsDirectory = "/tmp/credentials"
defaultHostPodsPath = "/host_pods"
defaultResourceTimeout = 10 * time.Minute
defaultDataMoverPrepareTimeout = 30 * time.Minute
defaultDataPathConcurrentNum = 1
@@ -414,8 +416,12 @@ func (s *nodeAgentServer) waitCacheForResume() error {
// validatePodVolumesHostPath validates that the pod volumes path contains a
// directory for each Pod running on this node
func (s *nodeAgentServer) validatePodVolumesHostPath(client kubernetes.Interface) error {
files, err := s.fileSystem.ReadDir("/host_pods/")
files, err := s.fileSystem.ReadDir(defaultHostPodsPath)
if err != nil {
if errors.Is(err, os.ErrNotExist) {
s.logger.Warnf("Pod volumes host path [%s] doesn't exist, fs-backup is disabled", defaultHostPodsPath)
return nil
}
return errors.Wrap(err, "could not read pod volumes host path")
}
@@ -446,7 +452,7 @@ func (s *nodeAgentServer) validatePodVolumesHostPath(client kubernetes.Interface
valid = false
s.logger.WithFields(logrus.Fields{
"pod": fmt.Sprintf("%s/%s", pod.GetNamespace(), pod.GetName()),
"path": "/host_pods/" + dirName,
"path": defaultHostPodsPath + "/" + dirName,
}).Debug("could not find volumes for pod in host path")
}
}

View File

@@ -37,10 +37,11 @@ import (
func Test_validatePodVolumesHostPath(t *testing.T) {
tests := []struct {
name string
pods []*corev1.Pod
dirs []string
wantErr bool
name string
pods []*corev1.Pod
dirs []string
createDir bool
wantErr bool
}{
{
name: "no error when pod volumes are present",
@@ -48,8 +49,9 @@ func Test_validatePodVolumesHostPath(t *testing.T) {
builder.ForPod("foo", "bar").ObjectMeta(builder.WithUID("foo")).Result(),
builder.ForPod("zoo", "raz").ObjectMeta(builder.WithUID("zoo")).Result(),
},
dirs: []string{"foo", "zoo"},
wantErr: false,
dirs: []string{"foo", "zoo"},
createDir: true,
wantErr: false,
},
{
name: "no error when pod volumes are present and there are mirror pods",
@@ -57,8 +59,9 @@ func Test_validatePodVolumesHostPath(t *testing.T) {
builder.ForPod("foo", "bar").ObjectMeta(builder.WithUID("foo")).Result(),
builder.ForPod("zoo", "raz").ObjectMeta(builder.WithUID("zoo"), builder.WithAnnotations(corev1.MirrorPodAnnotationKey, "baz")).Result(),
},
dirs: []string{"foo", "baz"},
wantErr: false,
dirs: []string{"foo", "baz"},
createDir: true,
wantErr: false,
},
{
name: "error when all pod volumes missing",
@@ -66,8 +69,9 @@ func Test_validatePodVolumesHostPath(t *testing.T) {
builder.ForPod("foo", "bar").ObjectMeta(builder.WithUID("foo")).Result(),
builder.ForPod("zoo", "raz").ObjectMeta(builder.WithUID("zoo")).Result(),
},
dirs: []string{"unexpected-dir"},
wantErr: true,
dirs: []string{"unexpected-dir"},
createDir: true,
wantErr: true,
},
{
name: "error when some pod volumes missing",
@@ -75,8 +79,18 @@ func Test_validatePodVolumesHostPath(t *testing.T) {
builder.ForPod("foo", "bar").ObjectMeta(builder.WithUID("foo")).Result(),
builder.ForPod("zoo", "raz").ObjectMeta(builder.WithUID("zoo")).Result(),
},
dirs: []string{"foo"},
wantErr: true,
dirs: []string{"foo"},
createDir: true,
wantErr: true,
},
{
name: "no error when pod volumes are not present",
pods: []*corev1.Pod{
builder.ForPod("foo", "bar").ObjectMeta(builder.WithUID("foo")).Result(),
},
dirs: []string{"foo"},
createDir: false,
wantErr: false,
},
}
for _, tt := range tests {
@@ -84,9 +98,11 @@ func Test_validatePodVolumesHostPath(t *testing.T) {
fs := testutil.NewFakeFileSystem()
for _, dir := range tt.dirs {
err := fs.MkdirAll(filepath.Join("/host_pods/", dir), os.ModePerm)
if err != nil {
t.Error(err)
if tt.createDir {
err := fs.MkdirAll(filepath.Join(defaultHostPodsPath, dir), os.ModePerm)
if err != nil {
t.Error(err)
}
}
}