Skip to content

Commit f374915

Browse files
authored
add jobImagePullSecrets (#472)
* add jobImagePullSecrets to be used for the job pods for pulling the image * fix golangci-lint
1 parent 11db232 commit f374915

File tree

7 files changed

+35
-23
lines changed

7 files changed

+35
-23
lines changed

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ Controller configuration
2929
```yaml
3030
name: "" # name of the controller; will also be used as prefix for the job pods
3131
jobServiceAccount: "" # service account to be used for the job pods. If empty the default will be used
32-
jobNodeSelector: { } # node selector labels to define in which nodes to run the jobs
32+
jobImagePullSecrets: # pull secrets to be used for the job pods for pulling the image
33+
- name: secret_name
34+
jobNodeSelector: { } # node selector labels to define in which nodes to run the jobs
3335
runOnUnscheduledNodes: true # if true, jobs are also started on nodes that are unschedulable
3436
cronExpression: "42 3 * * *" # the cron expression to trigger the job execution
3537
reportDirectory: "/var/www" # directory to store and serve the reports

helm/example-batch-job-controller/Chart.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
apiVersion: v2
22
name: batch-job-controller
3-
version: 1.4.5
4-
appVersion: v1.4.5
3+
version: 1.4.6
4+
appVersion: v1.4.6
55
description: Install batch job controller
66
icon: https://emojigraph.org/media/google/man-construction-worker_1f477-200d-2642-fe0f.png
77
sources:

helm/example-batch-job-controller/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# batch-job-controller
22

3-
![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)
3+
![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)
44

55
Install batch job controller
66

helm/example-batch-job-controller/templates/configmap.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ data:
1414
config.yaml: |-
1515
name: {{ template "batch-job-controller.name" . }}
1616
jobServiceAccount: ""
17+
jobImagePullSecrets: {}
1718
jobNodeSelector: {}
1819
cronExpression: "{{ .Values.deployment.cronExpression }}"
1920
reportHistory: {{ .Values.deployment.reportHistory }}

pkg/config/types.go

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"strings"
1010
"time"
1111

12+
corev1 "k8s.io/api/core/v1"
1213
"k8s.io/apimachinery/pkg/runtime"
1314
"sigs.k8s.io/controller-runtime/pkg/healthz"
1415
)
@@ -20,18 +21,19 @@ const (
2021

2122
// Config struct
2223
type Config struct {
23-
Name string `json:"name"`
24-
JobServiceAccount string `json:"jobServiceAccount"`
25-
JobNodeSelector map[string]string `json:"jobNodeSelector"`
26-
RunOnUnscheduledNodes bool `json:"runOnUnscheduledNodes"`
27-
CronExpression string `json:"cronExpression"`
28-
ReportDirectory string `json:"reportDirectory"`
29-
ReportHistory int `json:"reportHistory"`
30-
PodPoolSize int `json:"podPoolSize"`
31-
RunOnStartup bool `json:"runOnStartup"`
32-
StartupDelay time.Duration `json:"startupDelay"`
33-
Metrics Metrics `json:"metrics"`
34-
HealthProbePort int `json:"healthProbePort"`
24+
Name string `json:"name"`
25+
JobServiceAccount string `json:"jobServiceAccount"`
26+
JobImagePullSecrets []corev1.LocalObjectReference `json:"imagePullSecrets"`
27+
JobNodeSelector map[string]string `json:"jobNodeSelector"`
28+
RunOnUnscheduledNodes bool `json:"runOnUnscheduledNodes"`
29+
CronExpression string `json:"cronExpression"`
30+
ReportDirectory string `json:"reportDirectory"`
31+
ReportHistory int `json:"reportHistory"`
32+
PodPoolSize int `json:"podPoolSize"`
33+
RunOnStartup bool `json:"runOnStartup"`
34+
StartupDelay time.Duration `json:"startupDelay"`
35+
Metrics Metrics `json:"metrics"`
36+
HealthProbePort int `json:"healthProbePort"`
3537
// LatestMetricsLabel if true, each result metric is also created with executionID=latest
3638
LatestMetricsLabel bool `json:"latestMetricsLabel"`
3739
Custom map[string]interface{} `json:"custom"`

pkg/job/job.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,9 @@ func New(cfg *config.Config, nodeName, id, callbackAddress string, owner runtime
9999
// assure correct service account
100100
pod.Spec.ServiceAccountName = cfg.JobServiceAccount
101101

102+
// assure correct image pull secrets
103+
pod.Spec.ImagePullSecrets = cfg.JobImagePullSecrets
104+
102105
// assure restart policy is set to never
103106
pod.Spec.RestartPolicy = corev1.RestartPolicyNever
104107

pkg/job/job_test.go

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,25 @@ import (
1616
var _ = Describe("Job", func() {
1717
Context("New", func() {
1818
var (
19-
cfg *config.Config
20-
name string
21-
namespace string
22-
nodeName string
23-
id string
24-
serviceIP string
25-
sacc string
19+
cfg *config.Config
20+
name string
21+
namespace string
22+
nodeName string
23+
id string
24+
serviceIP string
25+
sacc string
26+
imagePullSecrets []corev1.LocalObjectReference
2627
)
2728
BeforeEach(func() {
2829
name = uuid.New().String()
2930
namespace = uuid.New().String()
3031
sacc = uuid.New().String()
32+
imagePullSecrets = []corev1.LocalObjectReference{{Name: "mySecret"}}
3133
cfg = &config.Config{
3234
Name: name,
3335
Namespace: namespace,
3436
JobServiceAccount: sacc,
37+
JobImagePullSecrets: imagePullSecrets,
3538
JobPodTemplate: "kind: Pod",
3639
CallbackServicePort: 12345,
3740
}
@@ -49,6 +52,7 @@ var _ = Describe("Job", func() {
4952
Ω(pod.Spec.RestartPolicy).Should(Equal(corev1.RestartPolicyNever))
5053
Ω(pod.Spec.NodeName).Should(Equal(nodeName))
5154
Ω(pod.Spec.ServiceAccountName).Should(Equal(sacc))
55+
Ω(pod.Spec.ImagePullSecrets).Should(Equal(imagePullSecrets))
5256

5357
Ω(pod.Labels[controller.LabelExecutionID]).Should(Equal(id))
5458
Ω(pod.Labels[controller.LabelOwner]).Should(Equal(name))

0 commit comments

Comments
 (0)