2022-05-24 14:44:31 +02:00
|
|
|
package helm
|
|
|
|
|
2022-06-01 15:55:06 +02:00
|
|
|
type CronTab struct {
|
|
|
|
*K8sBase `yaml:",inline"`
|
|
|
|
Spec CronSpec `yaml:"spec"`
|
2022-05-24 14:44:31 +02:00
|
|
|
}
|
2022-06-01 15:55:06 +02:00
|
|
|
type CronSpec struct {
|
|
|
|
Schedule string `yaml:"schedule"`
|
|
|
|
JobTemplate JobTemplate `yaml:"jobTemplate"`
|
2022-05-24 14:44:31 +02:00
|
|
|
}
|
|
|
|
type JobTemplate struct {
|
2022-06-01 15:55:06 +02:00
|
|
|
Spec JobSpecDescription `yaml:"spec"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type JobSpecDescription struct {
|
|
|
|
Template JobSpecTemplate `yaml:"template"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type JobSpecTemplate struct {
|
2022-05-24 14:44:31 +02:00
|
|
|
Metadata Metadata `yaml:"metadata"`
|
2022-06-01 15:55:06 +02:00
|
|
|
Spec Job `yaml:"spec"`
|
2022-05-24 14:44:31 +02:00
|
|
|
}
|
|
|
|
|
2022-06-01 15:55:06 +02:00
|
|
|
type Job struct {
|
|
|
|
ServiceAccount string `yaml:"serviceAccount,omitempty"`
|
|
|
|
ServiceAccountName string `yaml:"serviceAccountName,omitempty"`
|
|
|
|
Containers []Container `yaml:"containers"`
|
|
|
|
RestartPolicy string `yaml:"restartPolicy,omitempty"`
|
2022-05-24 14:44:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func NewCrontab(name, image, command, schedule string, serviceAccount *ServiceAccount) *CronTab {
|
|
|
|
cron := &CronTab{
|
|
|
|
K8sBase: NewBase(),
|
|
|
|
}
|
|
|
|
cron.K8sBase.ApiVersion = "batch/v1"
|
|
|
|
cron.K8sBase.Kind = "CronJob"
|
|
|
|
|
|
|
|
cron.K8sBase.Metadata.Name = ReleaseNameTpl + "-" + name
|
|
|
|
cron.K8sBase.Metadata.Labels[K+"/component"] = name
|
2022-06-01 15:55:06 +02:00
|
|
|
cron.Spec.Schedule = schedule
|
|
|
|
cron.Spec.JobTemplate.Spec.Template.Metadata = Metadata{
|
|
|
|
Labels: cron.K8sBase.Metadata.Labels,
|
|
|
|
}
|
|
|
|
cron.Spec.JobTemplate.Spec.Template.Spec = Job{
|
|
|
|
ServiceAccount: serviceAccount.Name(),
|
|
|
|
ServiceAccountName: serviceAccount.Name(),
|
|
|
|
Containers: []Container{
|
|
|
|
{
|
|
|
|
Name: name,
|
|
|
|
Image: image,
|
|
|
|
Command: []string{command},
|
2022-05-24 14:44:31 +02:00
|
|
|
},
|
|
|
|
},
|
2022-06-01 15:55:06 +02:00
|
|
|
RestartPolicy: "OnFailure",
|
2022-05-24 14:44:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return cron
|
|
|
|
}
|