Skip to content
This repository was archived by the owner on Oct 30, 2024. It is now read-only.

Commit effff78

Browse files
committed
feat: add support for batch v1 cronjob
Signed-off-by: Nico Braun <rainbowstack@gmail.com>
1 parent ad40a0c commit effff78

5 files changed

Lines changed: 53 additions & 0 deletions

File tree

internal/k8sinternal/client_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ func TestGetAllResources(t *testing.T) {
8686
k8s.NewStatefulSet(),
8787
k8s.NewPodTemplate(),
8888
k8s.NewCronJob(),
89+
k8s.NewCronJobV1(),
8990
k8s.NewServiceAccount(),
9091
k8s.NewService(),
9192
k8s.NewJob(),
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
apiVersion: v1
2+
kind: Namespace
3+
metadata:
4+
name: cronjob-v1
5+
---
6+
apiVersion: batch/v1
7+
kind: CronJob
8+
metadata:
9+
name: cronjob-v1
10+
namespace: cronjob-v1
11+
spec:
12+
schedule: "*/1 * * * *"
13+
jobTemplate:
14+
spec:
15+
template:
16+
spec:
17+
restartPolicy: OnFailure
18+
hostPID: true
19+
hostIPC: true
20+
hostNetwork: true
21+
containers:
22+
- name: container
23+
image: scratch

pkg/k8s/helpers.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,8 @@ func GetPodTemplateSpec(resource Resource) *PodTemplateSpecV1 {
111111
switch kubeType := resource.(type) {
112112
case *CronJobV1Beta1:
113113
return &kubeType.Spec.JobTemplate.Spec.Template
114+
case *CronJobV1:
115+
return &kubeType.Spec.JobTemplate.Spec.Template
114116
case *DaemonSetV1:
115117
return &kubeType.Spec.Template
116118
case *DeploymentV1:

pkg/k8s/resources.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,24 @@ func NewCronJob() *CronJobV1Beta1 {
127127
}
128128
}
129129

130+
// NewCronJobV1 creates a new CronJob resource
131+
func NewCronJobV1() *CronJobV1 {
132+
return &CronJobV1{
133+
TypeMeta: TypeMetaV1{
134+
Kind: "CronJob",
135+
APIVersion: "batch/v1",
136+
},
137+
ObjectMeta: ObjectMetaV1{},
138+
Spec: CronJobSpecV1{
139+
JobTemplate: JobTemplateSpecV1{
140+
Spec: JobSpecV1{
141+
Template: podTemplateSpec,
142+
},
143+
},
144+
},
145+
}
146+
}
147+
130148
// NewServiceAccount creates a new ServiceAccount resource
131149
func NewServiceAccount() *ServiceAccountV1 {
132150
return &ServiceAccountV1{

pkg/k8s/types.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@ type CronJobV1Beta1 = batchv1beta1.CronJob
2525
// CronJobSpecV1Beta1 is a type alias for the v1beta1 version of the k8s batch API.
2626
type CronJobSpecV1Beta1 = batchv1beta1.CronJobSpec
2727

28+
// CronJobV1 is a type alias for the v1 version of the k8s batch API.
29+
type CronJobV1 = batchv1.CronJob
30+
31+
// CronJobSpecV1 is a type alias for the v1 version of the k8s batch API.
32+
type CronJobSpecV1 = batchv1.CronJobSpec
33+
2834
// DaemonSetSpecV1 is a type alias for the v1 version of the k8s apps API.
2935
type DaemonSetSpecV1 = appsv1.DaemonSetSpec
3036

@@ -40,6 +46,9 @@ type DeploymentV1 = appsv1.Deployment
4046
// JobTemplateSpecV1Beta1 is a type alias for the v1beta1 version of the k8s batch API.
4147
type JobTemplateSpecV1Beta1 = batchv1beta1.JobTemplateSpec
4248

49+
// JobTemplateSpecV1 is a type alias for the v1 version of the k8s batch API.
50+
type JobTemplateSpecV1 = batchv1.JobTemplateSpec
51+
4352
// JobSpecV1 is a type alias for the v1 version of the k8s batch API.
4453
type JobSpecV1 = batchv1.JobSpec
4554

0 commit comments

Comments
 (0)