From 16b6a73532d95fa1865feaaa5cad40ea429595a2 Mon Sep 17 00:00:00 2001 From: jiuker <2818723467@qq.com> Date: Fri, 7 Jun 2024 09:24:23 +0800 Subject: [PATCH 1/3] support command for minioJob support commands for minioJob --- helm/operator/templates/job.min.io_jobs.yaml | 4 ++ pkg/apis/job.min.io/v1alpha1/types.go | 4 ++ pkg/controller/job-controller.go | 1 + pkg/utils/miniojob/types.go | 62 ++++++++++--------- resources/base/crds/job.min.io_miniojobs.yaml | 4 ++ 5 files changed, 47 insertions(+), 28 deletions(-) diff --git a/helm/operator/templates/job.min.io_jobs.yaml b/helm/operator/templates/job.min.io_jobs.yaml index 8ffc3bdc0e6..a9b7ac080d4 100644 --- a/helm/operator/templates/job.min.io_jobs.yaml +++ b/helm/operator/templates/job.min.io_jobs.yaml @@ -43,6 +43,10 @@ spec: additionalProperties: type: string type: object + command: + items: + type: string + type: array dependsOn: items: type: string diff --git a/pkg/apis/job.min.io/v1alpha1/types.go b/pkg/apis/job.min.io/v1alpha1/types.go index 6515c3b44cd..6d444edc596 100644 --- a/pkg/apis/job.min.io/v1alpha1/types.go +++ b/pkg/apis/job.min.io/v1alpha1/types.go @@ -142,6 +142,10 @@ type CommandSpec struct { // +optional Args map[string]string `json:"args,omitempty"` + // Command custom command to run + // +optional + Command []string `json:"command,omitempty"` + // DependsOn List of named `command` in this MinioJob that have to be scheduled and executed before this command runs // +optional DependsOn []string `json:"dependsOn,omitempty"` diff --git a/pkg/controller/job-controller.go b/pkg/controller/job-controller.go index 633495b4790..d0bb57e9f39 100644 --- a/pkg/controller/job-controller.go +++ b/pkg/controller/job-controller.go @@ -120,6 +120,7 @@ func NewJobController( } controller.enqueueJob(new) }, + DeleteFunc: controller.enqueueJob, }) jobInformer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{ diff --git a/pkg/utils/miniojob/types.go b/pkg/utils/miniojob/types.go index 3eb7fd73462..9089038d80c 100644 --- a/pkg/utils/miniojob/types.go +++ b/pkg/utils/miniojob/types.go @@ -131,16 +131,20 @@ func (jobCommand *MinIOIntervalJobCommand) createJob(ctx context.Context, k8sCli } jobCommand.mutex.RUnlock() jobCommands := []string{} - commands := []string{"mc"} - commands = append(commands, strings.SplitN(jobCommand.MCOperation, "/", -1)...) - commands = append(commands, strings.SplitN(jobCommand.Command, " ", -1)...) - for _, command := range commands { - trimCommand := strings.TrimSpace(command) - if trimCommand != "" { - jobCommands = append(jobCommands, trimCommand) + if len(jobCommand.CommandSpec.Command) == 0 { + commands := []string{"mc"} + commands = append(commands, strings.SplitN(jobCommand.MCOperation, "/", -1)...) + commands = append(commands, strings.SplitN(jobCommand.Command, " ", -1)...) + for _, command := range commands { + trimCommand := strings.TrimSpace(command) + if trimCommand != "" { + jobCommands = append(jobCommands, trimCommand) + } } + jobCommands = append(jobCommands, "--insecure") + } else { + jobCommands = append(jobCommands, jobCommand.CommandSpec.Command...) } - jobCommands = append(jobCommands, "--insecure") mcImage := jobCR.Spec.MCImage if mcImage == "" { mcImage = DefaultMCImage @@ -340,30 +344,32 @@ func (intervalJob *MinIOIntervalJob) CreateCommandJob(ctx context.Context, k8sCl // GenerateMinIOIntervalJobCommand - generate command func GenerateMinIOIntervalJobCommand(commandSpec v1alpha1.CommandSpec, commandIndex int) (*MinIOIntervalJobCommand, error) { - mcCommand, found := OperationAliasToMC(commandSpec.Operation) - if !found { - return nil, fmt.Errorf("operation %s is not supported", commandSpec.Operation) - } - argsFuncs, found := JobOperation[mcCommand] - if !found { - return nil, fmt.Errorf("operation %s is not supported", mcCommand) + jobCommand := &MinIOIntervalJobCommand{ + JobName: commandSpec.Name, + CommandSpec: commandSpec, } - commands := []string{} - for _, argsFunc := range argsFuncs { - jobArg, err := argsFunc(commandSpec.Args) - if err != nil { - return nil, err + if len(commandSpec.Command) == 0 { + mcCommand, found := OperationAliasToMC(commandSpec.Operation) + if !found { + return nil, fmt.Errorf("operation %s is not supported", commandSpec.Operation) } - if jobArg.Command != "" { - commands = append(commands, jobArg.Command) + argsFuncs, found := JobOperation[mcCommand] + if !found { + return nil, fmt.Errorf("operation %s is not supported", mcCommand) } + commands := []string{} + for _, argsFunc := range argsFuncs { + jobArg, err := argsFunc(commandSpec.Args) + if err != nil { + return nil, err + } + if jobArg.Command != "" { + commands = append(commands, jobArg.Command) + } - } - jobCommand := &MinIOIntervalJobCommand{ - JobName: commandSpec.Name, - MCOperation: mcCommand, - Command: strings.Join(commands, " "), - CommandSpec: commandSpec, + } + jobCommand.MCOperation = mcCommand + jobCommand.Command = strings.Join(commands, " ") } // some commands need to have a empty name if jobCommand.JobName == "" { diff --git a/resources/base/crds/job.min.io_miniojobs.yaml b/resources/base/crds/job.min.io_miniojobs.yaml index 8ffc3bdc0e6..a9b7ac080d4 100644 --- a/resources/base/crds/job.min.io_miniojobs.yaml +++ b/resources/base/crds/job.min.io_miniojobs.yaml @@ -43,6 +43,10 @@ spec: additionalProperties: type: string type: object + command: + items: + type: string + type: array dependsOn: items: type: string From 54186ac074507ba9778ce60e26bbd9562ebb689b Mon Sep 17 00:00:00 2001 From: jiuker <2818723467@qq.com> Date: Fri, 7 Jun 2024 11:12:00 +0800 Subject: [PATCH 2/3] doc doc --- pkg/apis/job.min.io/v1alpha1/types.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/apis/job.min.io/v1alpha1/types.go b/pkg/apis/job.min.io/v1alpha1/types.go index 6d444edc596..0e829de6b97 100644 --- a/pkg/apis/job.min.io/v1alpha1/types.go +++ b/pkg/apis/job.min.io/v1alpha1/types.go @@ -142,7 +142,7 @@ type CommandSpec struct { // +optional Args map[string]string `json:"args,omitempty"` - // Command custom command to run + // Command Execute All User-Defined Commands // +optional Command []string `json:"command,omitempty"` From 594b3b05af8dcf4ebfcac47ceaaa17e6b4b6b3a4 Mon Sep 17 00:00:00 2001 From: jiuker <2818723467@qq.com> Date: Mon, 10 Jun 2024 22:33:39 +0800 Subject: [PATCH 3/3] suggestion suggestion --- pkg/utils/miniojob/types.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pkg/utils/miniojob/types.go b/pkg/utils/miniojob/types.go index 9089038d80c..a5259d2d653 100644 --- a/pkg/utils/miniojob/types.go +++ b/pkg/utils/miniojob/types.go @@ -136,9 +136,9 @@ func (jobCommand *MinIOIntervalJobCommand) createJob(ctx context.Context, k8sCli commands = append(commands, strings.SplitN(jobCommand.MCOperation, "/", -1)...) commands = append(commands, strings.SplitN(jobCommand.Command, " ", -1)...) for _, command := range commands { - trimCommand := strings.TrimSpace(command) - if trimCommand != "" { - jobCommands = append(jobCommands, trimCommand) + trimmedCommand := strings.TrimSpace(command) + if trimmedCommand != "" { + jobCommands = append(jobCommands, trimmedCommand) } } jobCommands = append(jobCommands, "--insecure")