Feat cronjob #23
@@ -78,7 +78,7 @@ func buildCrontab(deployName string, deployment *helm.Deployment, s *types.Servi
|
|||||||
cmd = podget + cmd
|
cmd = podget + cmd
|
||||||
|
|
||||||
if cron.Image == "" {
|
if cron.Image == "" {
|
||||||
cron.Image = "bitnami/kubectl:1.20"
|
cron.Image = `bitnami/kubectl:{{ printf "%s.%s" .Capabilities.KubeVersion.Major .Capabilities.KubeVersion.Minor }}`
|
||||||
}
|
}
|
||||||
|
|
||||||
name := deployName
|
name := deployName
|
||||||
@@ -87,6 +87,11 @@ func buildCrontab(deployName string, deployment *helm.Deployment, s *types.Servi
|
|||||||
index++
|
index++
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// add crontab
|
||||||
|
suffix := ""
|
||||||
|
if index > 0 {
|
||||||
|
suffix = fmt.Sprintf("%d", index)
|
||||||
|
}
|
||||||
cronTab := helm.NewCrontab(
|
cronTab := helm.NewCrontab(
|
||||||
name,
|
name,
|
||||||
cron.Image,
|
cron.Image,
|
||||||
@@ -94,11 +99,6 @@ func buildCrontab(deployName string, deployment *helm.Deployment, s *types.Servi
|
|||||||
cron.Schedule,
|
cron.Schedule,
|
||||||
sa,
|
sa,
|
||||||
)
|
)
|
||||||
// add crontab
|
|
||||||
suffix := ""
|
|
||||||
if index > 0 {
|
|
||||||
suffix = fmt.Sprintf("%d", index)
|
|
||||||
}
|
|
||||||
logger.Magenta(ICON_CRON, "Generating crontab", deployName, suffix)
|
logger.Magenta(ICON_CRON, "Generating crontab", deployName, suffix)
|
||||||
fileGeneratorChan <- cronTab
|
fileGeneratorChan <- cronTab
|
||||||
}
|
}
|
||||||
|
@@ -182,7 +182,9 @@ func Generate(p *compose.Parser, katernayVersion, appName, appVersion, chartVers
|
|||||||
writers.BuildConfigMap(c, kind, n, name, templatesDir)
|
writers.BuildConfigMap(c, kind, n, name, templatesDir)
|
||||||
|
|
||||||
default:
|
default:
|
||||||
fname := filepath.Join(templatesDir, n+"."+kind+".yaml")
|
name := c.(helm.Named).Name() + "-" + c.GetType()
|
||||||
|
name = PrefixRE.ReplaceAllString(name, "")
|
||||||
|
fname := filepath.Join(templatesDir, name+".yaml")
|
||||||
fp, err := os.Create(fname)
|
fp, err := os.Create(fname)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
|
@@ -50,15 +50,21 @@ func NewCrontab(name, image, command, schedule string, serviceAccount *ServiceAc
|
|||||||
cron.Spec.JobTemplate.Spec.Template.Spec = Job{
|
cron.Spec.JobTemplate.Spec.Template.Spec = Job{
|
||||||
ServiceAccount: serviceAccount.Name(),
|
ServiceAccount: serviceAccount.Name(),
|
||||||
ServiceAccountName: serviceAccount.Name(),
|
ServiceAccountName: serviceAccount.Name(),
|
||||||
Containers: []Container{
|
RestartPolicy: "OnFailure",
|
||||||
{
|
}
|
||||||
Name: name,
|
if command != "" {
|
||||||
Image: image,
|
cron.AddCommand(command, image, name)
|
||||||
Command: []string{"sh", "-c", command},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
RestartPolicy: "OnFailure",
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return cron
|
return cron
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// AddCommand adds a command to the cron job
|
||||||
|
func (c *CronTab) AddCommand(command, image, name string) {
|
||||||
|
container := Container{
|
||||||
|
Name: name,
|
||||||
|
Image: image,
|
||||||
|
Command: []string{"sh", "-c", command},
|
||||||
|
}
|
||||||
|
c.Spec.JobTemplate.Spec.Template.Spec.Containers = append(c.Spec.JobTemplate.Spec.Template.Spec.Containers, container)
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user