From 8156f8cfa220776548afcb82e20c277c09b41238 Mon Sep 17 00:00:00 2001 From: Patrice Ferlet Date: Fri, 10 Jun 2022 11:33:09 +0200 Subject: [PATCH] Fixup jobs, roles... --- generator/crontabs.go | 2 +- generator/main.go | 1 + helm/cronTab.go | 12 +++++++++--- helm/deployment.go | 7 +++++++ helm/role.go | 9 +++++++-- 5 files changed, 25 insertions(+), 6 deletions(-) diff --git a/generator/crontabs.go b/generator/crontabs.go index 4066866..6eeb819 100644 --- a/generator/crontabs.go +++ b/generator/crontabs.go @@ -78,7 +78,7 @@ func buildCrontab(deployName string, deployment *helm.Deployment, s *types.Servi cmd = podget + cmd if cron.Image == "" { - cron.Image = "bitnami/kubectl" + cron.Image = "bitnami/kubectl:1.20" } name := deployName diff --git a/generator/main.go b/generator/main.go index e3471d7..a88dd56 100644 --- a/generator/main.go +++ b/generator/main.go @@ -74,6 +74,7 @@ func buildDeployment(name string, s *types.ServiceConfig, linked map[string]type // Add selectors selectors := buildSelector(name, s) + selectors[helm.K+"/resource"] = "deployment" deployment.Spec.Selector = map[string]interface{}{ "matchLabels": selectors, } diff --git a/helm/cronTab.go b/helm/cronTab.go index 5316503..ef79c63 100644 --- a/helm/cronTab.go +++ b/helm/cronTab.go @@ -5,8 +5,11 @@ type CronTab struct { Spec CronSpec `yaml:"spec"` } type CronSpec struct { - Schedule string `yaml:"schedule"` - JobTemplate JobTemplate `yaml:"jobTemplate"` + Schedule string `yaml:"schedule"` + JobTemplate JobTemplate `yaml:"jobTemplate"` + SuccessfulJobsHistoryLimit int `yaml:"successfulJobsHistoryLimit"` + FailedJobsHistoryLimit int `yaml:"failedJobsHistoryLimit"` + ConcurrencyPolicy string `yaml:"concurrencyPolicy"` } type JobTemplate struct { Spec JobSpecDescription `yaml:"spec"` @@ -38,6 +41,9 @@ func NewCrontab(name, image, command, schedule string, serviceAccount *ServiceAc cron.K8sBase.Metadata.Name = ReleaseNameTpl + "-" + name cron.K8sBase.Metadata.Labels[K+"/component"] = name cron.Spec.Schedule = schedule + cron.Spec.SuccessfulJobsHistoryLimit = 3 + cron.Spec.FailedJobsHistoryLimit = 3 + cron.Spec.ConcurrencyPolicy = "Forbid" cron.Spec.JobTemplate.Spec.Template.Metadata = Metadata{ Labels: cron.K8sBase.Metadata.Labels, } @@ -48,7 +54,7 @@ func NewCrontab(name, image, command, schedule string, serviceAccount *ServiceAc { Name: name, Image: image, - Command: []string{command}, + Command: []string{"sh", "-c", command}, }, }, RestartPolicy: "OnFailure", diff --git a/helm/deployment.go b/helm/deployment.go index 3943423..649d1db 100644 --- a/helm/deployment.go +++ b/helm/deployment.go @@ -25,6 +25,13 @@ type DepSpec struct { func NewDepSpec() *DepSpec { return &DepSpec{ Replicas: 1, + Template: PodTemplate{ + Metadata: Metadata{ + Labels: map[string]string{ + K + "/resource": "deployment", + }, + }, + }, } } diff --git a/helm/role.go b/helm/role.go index c708b21..111058a 100644 --- a/helm/role.go +++ b/helm/role.go @@ -24,8 +24,13 @@ func NewCronRole(name string) *Role { role.Rules = []Rule{ { ApiGroup: []string{""}, - Resources: []string{"pods", "pods/exec"}, - Verbs: []string{"get", "list", "create"}, + Resources: []string{"pods", "pods/log"}, + Verbs: []string{"get", "list", "watch", "create", "update", "patch", "delete"}, + }, + { + ApiGroup: []string{""}, + Resources: []string{"pods/exec"}, + Verbs: []string{"create"}, }, }