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

feat: add support for batch v1 cronjob #522

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion internal/k8sinternal/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func TestGetAllResources(t *testing.T) {
k8s.NewReplicationController(),
k8s.NewStatefulSet(),
k8s.NewPodTemplate(),
k8s.NewCronJob(),
k8s.NewCronJobV1(),
k8s.NewServiceAccount(),
k8s.NewService(),
k8s.NewJob(),
Expand Down
23 changes: 23 additions & 0 deletions internal/test/fixtures/all_resources/cronjob-v1.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
apiVersion: v1
kind: Namespace
metadata:
name: cronjob-v1
---
apiVersion: batch/v1
kind: CronJob
metadata:
name: cronjob-v1
namespace: cronjob-v1
spec:
schedule: "*/1 * * * *"
jobTemplate:
spec:
template:
spec:
restartPolicy: OnFailure
hostPID: true
hostIPC: true
hostNetwork: true
containers:
- name: container
image: scratch
2 changes: 2 additions & 0 deletions pkg/k8s/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ func GetPodTemplateSpec(resource Resource) *PodTemplateSpecV1 {
switch kubeType := resource.(type) {
case *CronJobV1Beta1:
return &kubeType.Spec.JobTemplate.Spec.Template
case *CronJobV1:
return &kubeType.Spec.JobTemplate.Spec.Template
case *DaemonSetV1:
return &kubeType.Spec.Template
case *DeploymentV1:
Expand Down
18 changes: 18 additions & 0 deletions pkg/k8s/resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,24 @@ func NewCronJob() *CronJobV1Beta1 {
}
}

// NewCronJobV1 creates a new CronJob resource
func NewCronJobV1() *CronJobV1 {
return &CronJobV1{
TypeMeta: TypeMetaV1{
Kind: "CronJob",
APIVersion: "batch/v1",
},
ObjectMeta: ObjectMetaV1{},
Spec: CronJobSpecV1{
JobTemplate: JobTemplateSpecV1{
Spec: JobSpecV1{
Template: podTemplateSpec,
},
},
},
}
}

// NewServiceAccount creates a new ServiceAccount resource
func NewServiceAccount() *ServiceAccountV1 {
return &ServiceAccountV1{
Expand Down
9 changes: 9 additions & 0 deletions pkg/k8s/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ type CronJobV1Beta1 = batchv1beta1.CronJob
// CronJobSpecV1Beta1 is a type alias for the v1beta1 version of the k8s batch API.
type CronJobSpecV1Beta1 = batchv1beta1.CronJobSpec

// CronJobV1 is a type alias for the v1 version of the k8s batch API.
type CronJobV1 = batchv1.CronJob

// CronJobSpecV1 is a type alias for the v1 version of the k8s batch API.
type CronJobSpecV1 = batchv1.CronJobSpec

// DaemonSetSpecV1 is a type alias for the v1 version of the k8s apps API.
type DaemonSetSpecV1 = appsv1.DaemonSetSpec

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

// JobTemplateSpecV1 is a type alias for the v1 version of the k8s batch API.
type JobTemplateSpecV1 = batchv1.JobTemplateSpec

// JobSpecV1 is a type alias for the v1 version of the k8s batch API.
type JobSpecV1 = batchv1.JobSpec

Expand Down