-
Notifications
You must be signed in to change notification settings - Fork 15
/
cronjobs.go
75 lines (73 loc) · 2.15 KB
/
cronjobs.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package resource
import (
"github.com/dev4devs-com/postgresql-operator/pkg/apis/postgresql/v1alpha1"
"github.com/dev4devs-com/postgresql-operator/pkg/utils"
batchv1 "k8s.io/api/batch/v1"
"k8s.io/api/batch/v1beta1"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
)
//Returns the NewBackupCronJob object for the Database Backup
func NewBackupCronJob(bkp *v1alpha1.Backup, scheme *runtime.Scheme) *v1beta1.CronJob {
cron := &v1beta1.CronJob{
ObjectMeta: v1.ObjectMeta{
Name: bkp.Name,
Namespace: bkp.Namespace,
Labels: utils.GetLabels(bkp.Name),
},
Spec: v1beta1.CronJobSpec{
Schedule: bkp.Spec.Schedule,
JobTemplate: v1beta1.JobTemplateSpec{
Spec: batchv1.JobSpec{
Template: corev1.PodTemplateSpec{
Spec: corev1.PodSpec{
ServiceAccountName: "postgresql-operator",
Containers: []corev1.Container{
{
Name: bkp.Name,
Image: bkp.Spec.Image,
Command: []string{"/opt/intly/tools/entrypoint.sh", "-c", "postgres", "-n", bkp.Namespace, "-b", "s3", "-e", ""},
Env: []corev1.EnvVar{
{
Name: "BACKEND_SECRET_NAME",
Value: utils.GetAWSSecretName(bkp),
},
{
Name: "BACKEND_SECRET_NAMESPACE",
Value: utils.GetAwsSecretNamespace(bkp),
},
{
Name: "ENCRYPTION_SECRET_NAME",
Value: utils.GetEncSecretName(bkp),
},
{
Name: "ENCRYPTION_SECRET_NAMESPACE",
Value: utils.GetEncSecretNamespace(bkp),
},
{
Name: "COMPONENT_SECRET_NAME",
Value: utils.DbSecretPrefix + bkp.Name,
},
{
Name: "COMPONENT_SECRET_NAMESPACE",
Value: bkp.Namespace,
},
{
Name: "PRODUCT_NAME",
Value: bkp.Spec.ProductName,
},
},
},
},
RestartPolicy: corev1.RestartPolicyOnFailure,
},
},
},
},
},
}
controllerutil.SetControllerReference(bkp, cron, scheme)
return cron
}