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

Commit

Permalink
feat: add support for batch v1 cronjob
Browse files Browse the repository at this point in the history
Signed-off-by: Nico Braun <[email protected]>
  • Loading branch information
bluebrown committed Jan 31, 2023
1 parent ad40a0c commit 7308fe2
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 0 deletions.
1 change: 1 addition & 0 deletions internal/k8sinternal/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ func TestGetAllResources(t *testing.T) {
k8s.NewStatefulSet(),
k8s.NewPodTemplate(),
k8s.NewCronJob(),
k8s.NewCronJobV1(),
k8s.NewServiceAccount(),
k8s.NewService(),
k8s.NewJob(),
Expand Down
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

0 comments on commit 7308fe2

Please sign in to comment.