diff --git a/changelogs/unreleased/8774-mpryc b/changelogs/unreleased/8774-mpryc new file mode 100644 index 000000000..6e2300992 --- /dev/null +++ b/changelogs/unreleased/8774-mpryc @@ -0,0 +1 @@ +host_pods should not be mandatory to node-agent diff --git a/pkg/cmd/cli/nodeagent/server.go b/pkg/cmd/cli/nodeagent/server.go index 22b3974ed..8c54f41d4 100644 --- a/pkg/cmd/cli/nodeagent/server.go +++ b/pkg/cmd/cli/nodeagent/server.go @@ -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") } } diff --git a/pkg/cmd/cli/nodeagent/server_test.go b/pkg/cmd/cli/nodeagent/server_test.go index bf3e203ca..ad89bc10c 100644 --- a/pkg/cmd/cli/nodeagent/server_test.go +++ b/pkg/cmd/cli/nodeagent/server_test.go @@ -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) + } } }