-
Notifications
You must be signed in to change notification settings - Fork 2
/
cron_deployment.go
73 lines (68 loc) · 2.4 KB
/
cron_deployment.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
package backend
import (
"fmt"
"github.com/3scale/saas-operator/pkg/basereconciler"
"github.com/3scale/saas-operator/pkg/generators/common_blocks/pod"
"github.com/3scale/saas-operator/pkg/util"
appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/intstr"
"sigs.k8s.io/controller-runtime/pkg/client"
)
// Deployment returns a basereconciler.GeneratorFunction funtion that will return a Deployment
// resource when called
func (gen *CronGenerator) Deployment() basereconciler.GeneratorFunction {
return func() client.Object {
dep := &appsv1.Deployment{
TypeMeta: metav1.TypeMeta{
Kind: "Deployment",
APIVersion: appsv1.SchemeGroupVersion.String(),
},
ObjectMeta: metav1.ObjectMeta{
Name: gen.GetComponent(),
Namespace: gen.Namespace,
Labels: gen.GetLabels(),
},
Spec: appsv1.DeploymentSpec{
Replicas: gen.CronSpec.Replicas,
Selector: gen.Selector(),
Strategy: appsv1.DeploymentStrategy{
Type: appsv1.RollingUpdateDeploymentStrategyType,
RollingUpdate: &appsv1.RollingUpdateDeployment{
MaxUnavailable: util.IntStrPtr(intstr.FromInt(0)),
MaxSurge: util.IntStrPtr(intstr.FromInt(1)),
},
},
Template: corev1.PodTemplateSpec{
ObjectMeta: metav1.ObjectMeta{
Labels: gen.LabelsWithSelector(),
},
Spec: corev1.PodSpec{
ImagePullSecrets: func() []corev1.LocalObjectReference {
if gen.Image.PullSecretName != nil {
return []corev1.LocalObjectReference{{Name: *gen.Image.PullSecretName}}
}
return nil
}(),
Containers: []corev1.Container{
{
Name: gen.GetComponent(),
Image: fmt.Sprintf("%s:%s", *gen.Image.Name, *gen.Image.Tag),
Args: []string{"backend-cron"},
Env: pod.BuildEnvironment(gen.Options),
Resources: corev1.ResourceRequirements(*gen.CronSpec.Resources),
ImagePullPolicy: *gen.Image.PullPolicy,
TerminationMessagePath: corev1.TerminationMessagePathDefault,
TerminationMessagePolicy: corev1.TerminationMessageReadFile,
},
},
Affinity: pod.Affinity(gen.Selector().MatchLabels, gen.CronSpec.NodeAffinity),
Tolerations: gen.CronSpec.Tolerations,
},
},
},
}
return dep
}
}