Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support command for minioJob #2151

Merged
merged 3 commits into from
Jun 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions helm/operator/templates/job.min.io_jobs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ spec:
additionalProperties:
type: string
type: object
command:
items:
type: string
type: array
dependsOn:
items:
type: string
Expand Down
4 changes: 4 additions & 0 deletions pkg/apis/job.min.io/v1alpha1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,10 @@ type CommandSpec struct {
// +optional
Args map[string]string `json:"args,omitempty"`

// Command Execute All User-Defined Commands
// +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"`
Expand Down
1 change: 1 addition & 0 deletions pkg/controller/job-controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ func NewJobController(
}
controller.enqueueJob(new)
},
DeleteFunc: controller.enqueueJob,
})

jobInformer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{
Expand Down
62 changes: 34 additions & 28 deletions pkg/utils/miniojob/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
trimmedCommand := strings.TrimSpace(command)
if trimmedCommand != "" {
jobCommands = append(jobCommands, trimmedCommand)
}
}
jobCommands = append(jobCommands, "--insecure")
} else {
jobCommands = append(jobCommands, jobCommand.CommandSpec.Command...)
}
jobCommands = append(jobCommands, "--insecure")
mcImage := jobCR.Spec.MCImage
if mcImage == "" {
mcImage = DefaultMCImage
Expand Down Expand Up @@ -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 == "" {
Expand Down
4 changes: 4 additions & 0 deletions resources/base/crds/job.min.io_miniojobs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ spec:
additionalProperties:
type: string
type: object
command:
items:
type: string
type: array
dependsOn:
items:
type: string
Expand Down
Loading