Feat cronjob #23
@@ -3,6 +3,7 @@ package generator
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"katenary/helm"
|
"katenary/helm"
|
||||||
|
"katenary/logger"
|
||||||
"log"
|
"log"
|
||||||
|
|
||||||
"github.com/compose-spec/compose-go/types"
|
"github.com/compose-spec/compose-go/types"
|
||||||
@@ -23,6 +24,7 @@ kubectl exec -i $pod -c %s -- sh -c '%s'`
|
|||||||
type CronDef struct {
|
type CronDef struct {
|
||||||
Command string `yaml:"command"`
|
Command string `yaml:"command"`
|
||||||
Schedule string `yaml:"schedule"`
|
Schedule string `yaml:"schedule"`
|
||||||
|
Image string `yaml:"image"`
|
||||||
Multi bool `yaml:"allPods,omitempty"`
|
Multi bool `yaml:"allPods,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -40,7 +42,6 @@ func buildCrontab(deployName string, deployment *helm.Deployment, s *types.Servi
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("error: %v", err)
|
log.Fatalf("error: %v", err)
|
||||||
}
|
}
|
||||||
log.Println(crons)
|
|
||||||
|
|
||||||
// create a serviceAccount
|
// create a serviceAccount
|
||||||
sa := helm.NewServiceAccount(deployName)
|
sa := helm.NewServiceAccount(deployName)
|
||||||
@@ -51,10 +52,13 @@ func buildCrontab(deployName string, deployment *helm.Deployment, s *types.Servi
|
|||||||
roleBinding := helm.NewRoleBinding(deployName, sa, role)
|
roleBinding := helm.NewRoleBinding(deployName, sa, role)
|
||||||
|
|
||||||
// make generation
|
// make generation
|
||||||
|
logger.Magenta(ICON_RBAC, "Generating ServiceAccount, Role and RoleBinding for cron jobs", deployName)
|
||||||
fileGeneratorChan <- sa
|
fileGeneratorChan <- sa
|
||||||
fileGeneratorChan <- role
|
fileGeneratorChan <- role
|
||||||
fileGeneratorChan <- roleBinding
|
fileGeneratorChan <- roleBinding
|
||||||
|
|
||||||
|
index := len(crons) - 1 // will be 0 when there is only one cron - made to name crons
|
||||||
|
|
||||||
// create crontabs
|
// create crontabs
|
||||||
for _, cron := range crons {
|
for _, cron := range crons {
|
||||||
var cmd, podget string
|
var cmd, podget string
|
||||||
@@ -69,14 +73,29 @@ func buildCrontab(deployName string, deployment *helm.Deployment, s *types.Servi
|
|||||||
cmd = fmt.Sprintf(cmd, s.Name, cron.Command)
|
cmd = fmt.Sprintf(cmd, s.Name, cron.Command)
|
||||||
cmd = podget + cmd
|
cmd = podget + cmd
|
||||||
|
|
||||||
|
if cron.Image == "" {
|
||||||
|
cron.Image = "bitnami/kubectl"
|
||||||
|
}
|
||||||
|
|
||||||
|
name := deployName
|
||||||
|
if index > 0 {
|
||||||
|
name = fmt.Sprintf("%s-%d", deployName, index)
|
||||||
|
index++
|
||||||
|
}
|
||||||
|
|
||||||
cronTab := helm.NewCrontab(
|
cronTab := helm.NewCrontab(
|
||||||
deployName,
|
name,
|
||||||
"bitnami/kubectl",
|
cron.Image,
|
||||||
cmd,
|
cmd,
|
||||||
cron.Schedule,
|
cron.Schedule,
|
||||||
sa,
|
sa,
|
||||||
)
|
)
|
||||||
// add crontab
|
// add crontab
|
||||||
|
suffix := ""
|
||||||
|
if index > 0 {
|
||||||
|
suffix = fmt.Sprintf("%d", index)
|
||||||
|
}
|
||||||
|
logger.Magenta(ICON_CRON, "Generating crontab", deployName, suffix)
|
||||||
fileGeneratorChan <- cronTab
|
fileGeneratorChan <- cronTab
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -28,6 +28,8 @@ const (
|
|||||||
ICON_CONF = "📝"
|
ICON_CONF = "📝"
|
||||||
ICON_STORE = "⚡"
|
ICON_STORE = "⚡"
|
||||||
ICON_INGRESS = "🌐"
|
ICON_INGRESS = "🌐"
|
||||||
|
ICON_RBAC = "🔑"
|
||||||
|
ICON_CRON = "🕒"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Values is kept in memory to create a values.yaml file.
|
// Values is kept in memory to create a values.yaml file.
|
||||||
|
@@ -28,22 +28,27 @@ const (
|
|||||||
func GetLabelsDocumentation() string {
|
func GetLabelsDocumentation() string {
|
||||||
t, _ := template.New("labels").Parse(`
|
t, _ := template.New("labels").Parse(`
|
||||||
# Labels
|
# Labels
|
||||||
{{.LABEL_IGNORE | printf "%-33s"}}: ignore the container, it will not yied any object in the helm chart
|
{{.LABEL_IGNORE | printf "%-33s"}}: ignore the container, it will not yied any object in the helm chart (bool)
|
||||||
{{.LABEL_SECRETVARS | printf "%-33s"}}: secret variables to push on a secret file
|
{{.LABEL_SECRETVARS | printf "%-33s"}}: secret variables to push on a secret file (coma separated)
|
||||||
{{.LABEL_ENV_SECRET | printf "%-33s"}}: set the given file names as a secret instead of configmap
|
{{.LABEL_ENV_SECRET | printf "%-33s"}}: set the given file names as a secret instead of configmap (coma separated)
|
||||||
{{.LABEL_MAP_ENV | printf "%-33s"}}: map environment variable to a template string (yaml style)
|
{{.LABEL_MAP_ENV | printf "%-33s"}}: map environment variable to a template string (yaml style, object)
|
||||||
{{.LABEL_PORT | printf "%-33s"}}: set the ports to expose as a service (coma separated)
|
{{.LABEL_PORT | printf "%-33s"}}: set the ports to expose as a service (coma separated)
|
||||||
{{.LABEL_INGRESS | printf "%-33s"}}: set the port to expose in an ingress (coma separated)
|
{{.LABEL_INGRESS | printf "%-33s"}}: set the port to expose in an ingress (coma separated)
|
||||||
{{.LABEL_VOL_CM | printf "%-33s"}}: specifies that the volumes points on a configmap (coma separated)
|
{{.LABEL_VOL_CM | printf "%-33s"}}: specifies that the volumes points on a configmap (coma separated)
|
||||||
{{.LABEL_SAMEPOD | printf "%-33s"}}: specifies that the pod should be deployed in the same pod than the given service name
|
{{.LABEL_SAMEPOD | printf "%-33s"}}: specifies that the pod should be deployed in the same pod than the given service name (string)
|
||||||
{{.LABEL_VOLUMEFROM | printf "%-33s"}}: specifies that the volumes to be mounted from the given service (yaml style)
|
{{.LABEL_VOLUMEFROM | printf "%-33s"}}: specifies that the volumes to be mounted from the given service (yaml style)
|
||||||
{{.LABEL_EMPTYDIRS | printf "%-33s"}}: specifies that the given volume names should be "emptyDir" instead of persistentVolumeClaim (coma separated)
|
{{.LABEL_EMPTYDIRS | printf "%-33s"}}: specifies that the given volume names should be "emptyDir" instead of persistentVolumeClaim (coma separated)
|
||||||
{{.LABEL_CRON | printf "%-33s"}}: specifies that the given cronjobs should be deployed (yaml style, array)
|
{{.LABEL_CRON | printf "%-33s"}}: specifies that the given cronjobs should be deployed (yaml style, array)
|
||||||
|
{{ printf "%-34s" ""}} The form is the following:
|
||||||
|
{{ printf "%-34s" ""}} - command: the command to run
|
||||||
|
{{ printf "%-34s" ""}} schedule: the schedule to run the command (e.g. "@daily" or "*/1 * * * *")
|
||||||
|
{{ printf "%-34s" ""}} image: the image to use for the command (default to "bitnami/kubectl")
|
||||||
|
{{ printf "%-34s" ""}} allPods: true if you want to run the command on all pods (default to false)
|
||||||
{{.LABEL_HEALTHCHECK | printf "%-33s"}}: specifies that the container should be monitored by a healthcheck, **it overrides the docker-compose healthcheck**.
|
{{.LABEL_HEALTHCHECK | printf "%-33s"}}: specifies that the container should be monitored by a healthcheck, **it overrides the docker-compose healthcheck**.
|
||||||
{{ printf "%-34s" ""}} You can use these form of label values:
|
{{ printf "%-34s" ""}} You can use these form of label values:
|
||||||
{{ printf "%-35s" ""}}- "http://[not used address][:port][/path]" to specify an http healthcheck
|
{{ printf "%-35s" ""}} "http://[not used address][:port][/path]" to specify an http healthcheck
|
||||||
{{ printf "%-35s" ""}}- "tcp://[not used address]:port" to specify a tcp healthcheck
|
{{ printf "%-35s" ""}} "tcp://[not used address]:port" to specify a tcp healthcheck
|
||||||
{{ printf "%-35s" ""}}- other string is condidered as a "command" healthcheck
|
{{ printf "%-35s" ""}} other string is condidered as a "command" healthcheck
|
||||||
`)
|
`)
|
||||||
buff := bytes.NewBuffer(nil)
|
buff := bytes.NewBuffer(nil)
|
||||||
t.Execute(buff, map[string]string{
|
t.Execute(buff, map[string]string{
|
||||||
|
Reference in New Issue
Block a user