diff --git a/pkg/engine/delete_object_task.go b/pkg/engine/delete_object_task.go index 2b6591d..1066bae 100644 --- a/pkg/engine/delete_object_task.go +++ b/pkg/engine/delete_object_task.go @@ -87,8 +87,10 @@ func (task *DeleteObjTask) Exec(ctx context.Context) error { return err } + task.log.V(4).Info("Deleting objects", "GVR", info.GVR.String(), "names", info.Names) + for _, name := range info.Names { - err := task.client.Resource(info.GVR).Delete(ctx, name, v1.DeleteOptions{}) + err = task.client.Resource(info.GVR).Namespace(info.Namespace).Delete(ctx, name, v1.DeleteOptions{}) if err != nil { return err } diff --git a/pkg/engine/submit_object_task.go b/pkg/engine/submit_object_task.go index 0ef39c6..e9b5998 100644 --- a/pkg/engine/submit_object_task.go +++ b/pkg/engine/submit_object_task.go @@ -114,7 +114,7 @@ func (task *SubmitObjTask) Exec(ctx context.Context) error { return fmt.Errorf("%s: failed to get object type: %v", task.ID(), err) } - objs, podCount, podRegexp, err := task.getGenericObjects(regObjParams) + objs, names, podCount, podRegexp, err := task.getGenericObjects(regObjParams) if err != nil { return err } @@ -135,13 +135,13 @@ func (task *SubmitObjTask) Exec(ctx context.Context) error { } return task.accessor.SetObjInfo(task.taskID, - NewObjInfo([]string{objs[0].Metadata.Name}, objs[0].Metadata.Namespace, regObjParams.gvr, podCount, podRegexp...)) + NewObjInfo(names, objs[0].Metadata.Namespace, regObjParams.gvr, podCount, podRegexp...)) } -func (task *SubmitObjTask) getGenericObjects(regObjParams *RegisterObjParams) ([]GenericObject, int, []string, error) { +func (task *SubmitObjTask) getGenericObjects(regObjParams *RegisterObjParams) ([]GenericObject, []string, int, []string, error) { names, err := utils.GenerateNames(regObjParams.NameFormat, task.Count, task.Params) if err != nil { - return nil, 0, nil, fmt.Errorf("%s: failed to generate object names: %v", task.ID(), err) + return nil, nil, 0, nil, fmt.Errorf("%s: failed to generate object names: %v", task.ID(), err) } objs := make([]GenericObject, task.Count) @@ -152,17 +152,17 @@ func (task *SubmitObjTask) getGenericObjects(regObjParams *RegisterObjParams) ([ data, err := utils.ExecTemplate(regObjParams.objTpl, task.Params) if err != nil { - return nil, 0, nil, err + return nil, nil, 0, nil, err } if err = yaml.Unmarshal(data, &objs[i]); err != nil { - return nil, 0, nil, err + return nil, nil, 0, nil, err } if regObjParams.podNameTpl != nil { data, err = utils.ExecTemplate(regObjParams.podNameTpl, task.Params) if err != nil { - return nil, 0, nil, err + return nil, nil, 0, nil, err } re := strings.Trim(strings.TrimSpace(string(data)), "\"") podRegexp = append(podRegexp, re) @@ -173,18 +173,18 @@ func (task *SubmitObjTask) getGenericObjects(regObjParams *RegisterObjParams) ([ if regObjParams.podCountTpl != nil { data, err := utils.ExecTemplate(regObjParams.podCountTpl, task.Params) if err != nil { - return nil, 0, nil, err + return nil, nil, 0, nil, err } str := string(data) podCount, err = strconv.Atoi(str) if err != nil { - return nil, 0, nil, fmt.Errorf("%s: failed to convert pod count %s to int: %v", task.ID(), str, err) + return nil, nil, 0, nil, fmt.Errorf("%s: failed to convert pod count %s to int: %v", task.ID(), str, err) } podCount *= task.Count } task.log.V(4).Info("Generating object specs", "podCount", podCount, "podRegexp", podRegexp) - return objs, podCount, podRegexp, nil + return objs, names, podCount, podRegexp, nil } func (obj *GenericObject) UnmarshalYAML(unmarshal func(interface{}) error) error { diff --git a/pkg/engine/submit_object_task_test.go b/pkg/engine/submit_object_task_test.go index bfdb963..7eee44e 100644 --- a/pkg/engine/submit_object_task_test.go +++ b/pkg/engine/submit_object_task_test.go @@ -89,6 +89,7 @@ func TestNewSubmitObjTask(t *testing.T) { err string task *SubmitObjTask objs []GenericObject + names []string podCount int podRegexp []string }{ @@ -178,6 +179,7 @@ func TestNewSubmitObjTask(t *testing.T) { Spec: spec, }, }, + names: []string{"job1"}, podRegexp: []string{}, }, { @@ -232,6 +234,7 @@ func TestNewSubmitObjTask(t *testing.T) { Spec: spec, }, }, + names: []string{"job1", "job2"}, podCount: 4, podRegexp: []string{"job1-test-[0-9]+", "job2-test-[0-9]+"}, }, @@ -280,9 +283,10 @@ func TestNewSubmitObjTask(t *testing.T) { require.NoError(t, err) } - objs, podCount, podRegexp, err := task.getGenericObjects(tc.regObjParams) + objs, names, podCount, podRegexp, err := task.getGenericObjects(tc.regObjParams) require.NoError(t, err) require.Equal(t, tc.objs, objs) + require.Equal(t, tc.names, names) require.Equal(t, tc.podCount, podCount) require.Equal(t, tc.podRegexp, podRegexp) } diff --git a/resources/tests/volcano/test-job.yml b/resources/tests/volcano/test-job.yml index 73ca893..4906313 100644 --- a/resources/tests/volcano/test-job.yml +++ b/resources/tests/volcano/test-job.yml @@ -27,3 +27,7 @@ tasks: refTaskId: job status: Running timeout: 5s +- id: delete + type: DeleteObj + params: + refTaskId: job