-
Notifications
You must be signed in to change notification settings - Fork 13
/
merge_job.go
40 lines (36 loc) · 1.53 KB
/
merge_job.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package taskcontroller
import (
"fmt"
"path/filepath"
"github.com/ccremer/clustercode/pkg/api/v1alpha1"
internaltypes "github.com/ccremer/clustercode/pkg/internal/types"
"github.com/ccremer/clustercode/pkg/internal/utils"
batchv1 "k8s.io/api/batch/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
)
func (r *TaskReconciler) createMergeJob(ctx *TaskContext) error {
configMountRoot := filepath.Join("/clustercode", internaltypes.ConfigSubMountPath)
targetMountRoot := filepath.Join("/clustercode", internaltypes.TargetSubMountPath)
variables := map[string]string{
"${INPUT}": filepath.Join(configMountRoot, v1alpha1.ConfigMapFileName),
"${OUTPUT}": filepath.Join(targetMountRoot, ctx.task.Spec.TargetUrl.GetPath()),
}
job := &batchv1.Job{ObjectMeta: metav1.ObjectMeta{
Name: fmt.Sprintf("%s-%s", ctx.task.Spec.TaskId, internaltypes.JobTypeMerge),
Namespace: ctx.task.Namespace,
}}
_, err := controllerutil.CreateOrUpdate(ctx, r.Client, job, func() error {
createClustercodeJobDefinition(job, ctx.task, TaskOpts{
template: ctx.task.Spec.Encode.PodTemplate,
image: DefaultFfmpegContainerImage,
args: utils.MergeArgsAndReplaceVariables(variables, ctx.task.Spec.Encode.MergeCommandArgs),
jobType: internaltypes.JobTypeMerge,
mountIntermediate: true,
mountTarget: true,
mountConfig: true,
})
return controllerutil.SetControllerReference(ctx.task, job, r.Client.Scheme())
})
return err
}