Skip to content

Commit

Permalink
add jobImagePullSecrets (#472)
Browse files Browse the repository at this point in the history
* add jobImagePullSecrets to be used for the job pods for pulling the image

* fix golangci-lint
  • Loading branch information
xosk31 authored Jun 3, 2024
1 parent 11db232 commit f374915
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 23 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ Controller configuration
```yaml
name: "" # name of the controller; will also be used as prefix for the job pods
jobServiceAccount: "" # service account to be used for the job pods. If empty the default will be used
jobNodeSelector: { } # node selector labels to define in which nodes to run the jobs
jobImagePullSecrets: # pull secrets to be used for the job pods for pulling the image
- name: secret_name
jobNodeSelector: { } # node selector labels to define in which nodes to run the jobs
runOnUnscheduledNodes: true # if true, jobs are also started on nodes that are unschedulable
cronExpression: "42 3 * * *" # the cron expression to trigger the job execution
reportDirectory: "/var/www" # directory to store and serve the reports
Expand Down
4 changes: 2 additions & 2 deletions helm/example-batch-job-controller/Chart.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
apiVersion: v2
name: batch-job-controller
version: 1.4.5
appVersion: v1.4.5
version: 1.4.6
appVersion: v1.4.6
description: Install batch job controller
icon: https://emojigraph.org/media/google/man-construction-worker_1f477-200d-2642-fe0f.png
sources:
Expand Down
2 changes: 1 addition & 1 deletion helm/example-batch-job-controller/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# batch-job-controller

![Version: 1.4.5](https://img.shields.io/badge/Version-1.4.5-informational?style=flat-square) ![AppVersion: v1.4.5](https://img.shields.io/badge/AppVersion-v1.4.5-informational?style=flat-square)
![Version: 1.4.6](https://img.shields.io/badge/Version-1.4.6-informational?style=flat-square) ![AppVersion: v1.4.6](https://img.shields.io/badge/AppVersion-v1.4.6-informational?style=flat-square)

Install batch job controller

Expand Down
1 change: 1 addition & 0 deletions helm/example-batch-job-controller/templates/configmap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ data:
config.yaml: |-
name: {{ template "batch-job-controller.name" . }}
jobServiceAccount: ""
jobImagePullSecrets: {}
jobNodeSelector: {}
cronExpression: "{{ .Values.deployment.cronExpression }}"
reportHistory: {{ .Values.deployment.reportHistory }}
Expand Down
26 changes: 14 additions & 12 deletions pkg/config/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"strings"
"time"

corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/runtime"
"sigs.k8s.io/controller-runtime/pkg/healthz"
)
Expand All @@ -20,18 +21,19 @@ const (

// Config struct
type Config struct {
Name string `json:"name"`
JobServiceAccount string `json:"jobServiceAccount"`
JobNodeSelector map[string]string `json:"jobNodeSelector"`
RunOnUnscheduledNodes bool `json:"runOnUnscheduledNodes"`
CronExpression string `json:"cronExpression"`
ReportDirectory string `json:"reportDirectory"`
ReportHistory int `json:"reportHistory"`
PodPoolSize int `json:"podPoolSize"`
RunOnStartup bool `json:"runOnStartup"`
StartupDelay time.Duration `json:"startupDelay"`
Metrics Metrics `json:"metrics"`
HealthProbePort int `json:"healthProbePort"`
Name string `json:"name"`
JobServiceAccount string `json:"jobServiceAccount"`
JobImagePullSecrets []corev1.LocalObjectReference `json:"imagePullSecrets"`
JobNodeSelector map[string]string `json:"jobNodeSelector"`
RunOnUnscheduledNodes bool `json:"runOnUnscheduledNodes"`
CronExpression string `json:"cronExpression"`
ReportDirectory string `json:"reportDirectory"`
ReportHistory int `json:"reportHistory"`
PodPoolSize int `json:"podPoolSize"`
RunOnStartup bool `json:"runOnStartup"`
StartupDelay time.Duration `json:"startupDelay"`
Metrics Metrics `json:"metrics"`
HealthProbePort int `json:"healthProbePort"`
// LatestMetricsLabel if true, each result metric is also created with executionID=latest
LatestMetricsLabel bool `json:"latestMetricsLabel"`
Custom map[string]interface{} `json:"custom"`
Expand Down
3 changes: 3 additions & 0 deletions pkg/job/job.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@ func New(cfg *config.Config, nodeName, id, callbackAddress string, owner runtime
// assure correct service account
pod.Spec.ServiceAccountName = cfg.JobServiceAccount

// assure correct image pull secrets
pod.Spec.ImagePullSecrets = cfg.JobImagePullSecrets

// assure restart policy is set to never
pod.Spec.RestartPolicy = corev1.RestartPolicyNever

Expand Down
18 changes: 11 additions & 7 deletions pkg/job/job_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,25 @@ import (
var _ = Describe("Job", func() {
Context("New", func() {
var (
cfg *config.Config
name string
namespace string
nodeName string
id string
serviceIP string
sacc string
cfg *config.Config
name string
namespace string
nodeName string
id string
serviceIP string
sacc string
imagePullSecrets []corev1.LocalObjectReference
)
BeforeEach(func() {
name = uuid.New().String()
namespace = uuid.New().String()
sacc = uuid.New().String()
imagePullSecrets = []corev1.LocalObjectReference{{Name: "mySecret"}}
cfg = &config.Config{
Name: name,
Namespace: namespace,
JobServiceAccount: sacc,
JobImagePullSecrets: imagePullSecrets,
JobPodTemplate: "kind: Pod",
CallbackServicePort: 12345,
}
Expand All @@ -49,6 +52,7 @@ var _ = Describe("Job", func() {
Ω(pod.Spec.RestartPolicy).Should(Equal(corev1.RestartPolicyNever))
Ω(pod.Spec.NodeName).Should(Equal(nodeName))
Ω(pod.Spec.ServiceAccountName).Should(Equal(sacc))
Ω(pod.Spec.ImagePullSecrets).Should(Equal(imagePullSecrets))

Ω(pod.Labels[controller.LabelExecutionID]).Should(Equal(id))
Ω(pod.Labels[controller.LabelOwner]).Should(Equal(name))
Expand Down

0 comments on commit f374915

Please sign in to comment.