Skip to content

Commit

Permalink
feat: Support Resources/EnvFrom/Env/VolumeMounts/Volumes to minioJob (#…
Browse files Browse the repository at this point in the history
…2124)

* feat: Support Resources/EnvFrom/Env/VolumeMounts/Volumes to minioJob
  • Loading branch information
jiuker committed May 24, 2024
1 parent a57c3e0 commit ce0a300
Show file tree
Hide file tree
Showing 8 changed files with 2,040 additions and 296 deletions.
893 changes: 893 additions & 0 deletions helm/operator/templates/job.min.io_jobs.yaml

Large diffs are not rendered by default.

29 changes: 29 additions & 0 deletions pkg/apis/job.min.io/v1alpha1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,35 @@ type CommandSpec struct {
// 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"`

// Compute Resources required by this container.
// Cannot be updated.
// More info: https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/
// +optional
Resources corev1.ResourceRequirements `json:"resources,omitempty"`

// List of sources to populate environment variables in the container.
// The keys defined within a source must be a C_IDENTIFIER. All invalid keys
// will be reported as an event when the container is starting. When a key exists in multiple
// sources, the value associated with the last source will take precedence.
// Values defined by an Env with a duplicate key will take precedence.
// Cannot be updated.
// +optional
EnvFrom []corev1.EnvFromSource `json:"envFrom,omitempty"`
// List of environment variables to set in the container.
// Cannot be updated.
// +optional
Env []corev1.EnvVar `json:"env,omitempty"`

// Pod volumes to mount into the container's filesystem.
// Cannot be updated.
// +optional
VolumeMounts []corev1.VolumeMount `json:"volumeMounts,omitempty"`

// List of volumes that can be mounted by containers belonging to the pod.
// More info: https://kubernetes.io/docs/concepts/storage/volumes
// +optional
Volumes []corev1.Volume `json:"volumes,omitempty"`
}

// TenantRef Is the reference to the target tenant of the jobs
Expand Down
14 changes: 3 additions & 11 deletions pkg/controller/job-controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ func (c *JobController) SyncHandler(key string) (Result, error) {
if err != nil {
return WrapResult(Result{}, err)
}
err = intervalJob.CreateCommandJob(ctx, c.k8sClient)
err = intervalJob.CreateCommandJob(ctx, c.k8sClient, STSDefaultPort)
if err != nil {
jobCR.Status.Phase = miniojob.MinioJobPhaseError
jobCR.Status.Message = fmt.Sprintf("Create job error:%v", err)
Expand Down Expand Up @@ -304,15 +304,7 @@ func checkMinIOJob(jobCR *v1alpha1.MinIOJob) (intervalJob *miniojob.MinIOInterva
return intervalJob, fmt.Errorf("serviceaccount name is empty")
}
for index, val := range jobCR.Spec.Commands {
mcCommand, found := miniojob.OperationAliasToMC(val.Operation)
if !found {
return intervalJob, fmt.Errorf("operation %s is not supported", val.Operation)
}
argsFuncs, found := miniojob.JobOperation[mcCommand]
if !found {
return intervalJob, fmt.Errorf("operation %s is not supported", mcCommand)
}
jobCommand, err := miniojob.GenerateMinIOIntervalJobCommand(mcCommand, index, val.DependsOn, val.Name, val.Args, argsFuncs)
jobCommand, err := miniojob.GenerateMinIOIntervalJobCommand(val, index)
if err != nil {
return intervalJob, err
}
Expand All @@ -321,7 +313,7 @@ func checkMinIOJob(jobCR *v1alpha1.MinIOJob) (intervalJob *miniojob.MinIOInterva
}
// check all dependon
for _, command := range intervalJob.Command {
for _, dep := range command.DepnedsOn {
for _, dep := range command.CommandSpec.DependsOn {
_, found := intervalJob.CommandMap[dep]
if !found {
return intervalJob, fmt.Errorf("dependent job %s not found", dep)
Expand Down
7 changes: 4 additions & 3 deletions pkg/controller/sts.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"encoding/xml"
"errors"
"fmt"
"net/http"
"os"
"sync"
Expand Down Expand Up @@ -34,8 +35,8 @@ const (

// STS API constants
const (
STSDefaultPort = "4223"
STSEndpoint = "/sts"
STSDefaultPort int = 4223
STSEndpoint = "/sts"
)

const (
Expand Down Expand Up @@ -263,7 +264,7 @@ func configureSTSServer(c *Controller) *http.Server {
router.NotFoundHandler = http.NotFoundHandler()

s := &http.Server{
Addr: ":" + STSDefaultPort,
Addr: fmt.Sprintf(":%d", STSDefaultPort),
Handler: router,
ReadTimeout: time.Minute,
WriteTimeout: time.Minute,
Expand Down
58 changes: 1 addition & 57 deletions pkg/utils/miniojob/minioJob.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,25 +22,9 @@ import (
"strings"
)

// ArgType - arg type
type ArgType int

const (
// ArgTypeKey - key=value print value
ArgTypeKey ArgType = iota
// ArgTypeFile - key=value print /temp/value.ext
ArgTypeFile
// ArgTypeKeyFile - key=value print key="/temp/value.ext"
ArgTypeKeyFile
)

// Arg - parse the arg result
type Arg struct {
Command string
FileName string
FileExt string
FileContext string
ArgType ArgType
Command string
}

// FieldsFunc - alias function
Expand Down Expand Up @@ -68,27 +52,6 @@ func Static(val string) FieldsFunc {
}
}

// File - fName is the the key, value is content, ext is the file ext
func File(fName string, ext string) FieldsFunc {
return func(args map[string]string) (out Arg, err error) {
if args == nil {
return out, fmt.Errorf("args is nil")
}
if val, ok := args[fName]; ok {
if val == "" {
return out, fmt.Errorf("value is empty")
}
out.FileName = fName
out.FileExt = ext
out.FileContext = strings.TrimSpace(val)
out.ArgType = ArgTypeFile
delete(args, fName)
return out, nil
}
return out, fmt.Errorf("file %s not found", fName)
}
}

// KeyValue - match key and putout the key, like endpoint="https://webhook-1.example.net"
func KeyValue(key string) FieldsFunc {
return func(args map[string]string) (out Arg, err error) {
Expand All @@ -105,25 +68,6 @@ func KeyValue(key string) FieldsFunc {
}
}

// KeyFile - match key and putout the key, like client_cert="[here is content]"
func KeyFile(key string, ext string) FieldsFunc {
return func(args map[string]string) (out Arg, err error) {
if args == nil {
return out, fmt.Errorf("args is nil")
}
val, ok := args[key]
if !ok {
return out, fmt.Errorf("key %s not found", key)
}
out.FileName = key
out.FileExt = ext
out.FileContext = strings.TrimSpace(val)
out.ArgType = ArgTypeKeyFile
delete(args, key)
return out, nil
}
}

// Option - ignore the error
func Option(opt FieldsFunc) FieldsFunc {
return func(args map[string]string) (out Arg, err error) {
Expand Down
Loading

0 comments on commit ce0a300

Please sign in to comment.