-
Notifications
You must be signed in to change notification settings - Fork 2
/
deployment.go
60 lines (54 loc) · 1.9 KB
/
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
package echoapi
import (
"fmt"
"github.com/3scale-ops/basereconciler/util"
"github.com/3scale-ops/saas-operator/pkg/resource_builders/marin3r"
"github.com/3scale-ops/saas-operator/pkg/resource_builders/pod"
appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/util/intstr"
)
func (gen *Generator) deployment() *appsv1.Deployment {
dep := &appsv1.Deployment{
Spec: appsv1.DeploymentSpec{
Replicas: gen.Spec.Replicas,
Strategy: appsv1.DeploymentStrategy{
Type: appsv1.RollingUpdateDeploymentStrategyType,
RollingUpdate: &appsv1.RollingUpdateDeployment{
MaxUnavailable: util.Pointer(intstr.FromInt(0)),
MaxSurge: util.Pointer(intstr.FromInt(1)),
},
},
Template: corev1.PodTemplateSpec{
Spec: corev1.PodSpec{
ImagePullSecrets: func() []corev1.LocalObjectReference {
if gen.Spec.Image.PullSecretName != nil {
return []corev1.LocalObjectReference{{Name: *gen.Spec.Image.PullSecretName}}
}
return nil
}(),
Containers: []corev1.Container{
{
Name: "echo-api",
Image: fmt.Sprintf("%s:%s", *gen.Spec.Image.Name, *gen.Spec.Image.Tag),
Ports: pod.ContainerPorts(
pod.ContainerPortTCP("http", 9292),
),
Resources: corev1.ResourceRequirements(*gen.Spec.Resources),
ImagePullPolicy: *gen.Spec.Image.PullPolicy,
LivenessProbe: pod.TCPProbe(intstr.FromInt(9292), *gen.Spec.LivenessProbe),
ReadinessProbe: pod.HTTPProbe("/", intstr.FromInt(9292), corev1.URISchemeHTTP, *gen.Spec.ReadinessProbe),
},
},
Affinity: pod.Affinity(gen.GetSelector(), gen.Spec.NodeAffinity),
Tolerations: gen.Spec.Tolerations,
TerminationGracePeriodSeconds: util.Pointer[int64](30),
},
},
},
}
if !gen.Spec.Marin3r.IsDeactivated() {
dep = marin3r.EnableSidecar(*dep, *gen.Spec.Marin3r)
}
return dep
}