diff --git a/pkg/ddc/alluxio/operations/base.go b/pkg/ddc/alluxio/operations/base.go index d745cfd6e6e..8b3ff2ebe56 100644 --- a/pkg/ddc/alluxio/operations/base.go +++ b/pkg/ddc/alluxio/operations/base.go @@ -479,13 +479,13 @@ func (a AlluxioFileUtils) MasterPodName() (masterPodName string, err error) { redactedCommand := securityutils.FilterCommand(command) str := strings.Split(stdout, "\n") - if len(str) < 1 { + if len(str) < 2 { message := fmt.Sprintf("get wrong result when using command %v", redactedCommand) return a.podName, errors.New(message) } data := strings.Fields(str[1]) - if len(data) < 2 { + if len(data) < 3 { message := fmt.Sprintf("get wrong result when using command %v", redactedCommand) return a.podName, errors.New(message) } diff --git a/pkg/ddc/alluxio/operations/base_test.go b/pkg/ddc/alluxio/operations/base_test.go index 09e1f752772..84be72aa6fb 100644 --- a/pkg/ddc/alluxio/operations/base_test.go +++ b/pkg/ddc/alluxio/operations/base_test.go @@ -797,6 +797,22 @@ func TestAlluxioFileUtils_MasterPodName(t *testing.T) { if address != "192.168.0.193" { t.Errorf("check failure, want: %s, got: %s", "192.168.0.193", address) } + + // Output that does not have the master address on the second line must return an error, not panic. + for _, stdout := range []string{ + "", + "Alluxio cluster summary: ", + "Alluxio cluster summary: \n", + "Alluxio cluster summary: \n Master Address:", + } { + ExecUnexpected := func(a AlluxioFileUtils, command []string, verbose bool) (string, string, error) { + return stdout, "", nil + } + patches.ApplyPrivateMethod(reflect.TypeOf(AlluxioFileUtils{}), "exec", ExecUnexpected) + if _, err := a.MasterPodName(); err == nil { + t.Errorf("check failure for stdout %q, want err, got nil", stdout) + } + } } func TestAlluxioFileUtils_ExecMountScripts(t *testing.T) {