-
Notifications
You must be signed in to change notification settings - Fork 2
/
deployment.go
65 lines (60 loc) · 2.42 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
61
62
63
64
65
package mappingservice
import (
"fmt"
"github.com/3scale/saas-operator/pkg/resource_builders/pod"
"github.com/3scale/saas-operator/pkg/util"
appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/util/intstr"
"k8s.io/utils/pointer"
)
// deployment returns a function that will return a *appsv1.Deployment for echo-api
func (gen *Generator) deployment() func() *appsv1.Deployment {
return func() *appsv1.Deployment {
return &appsv1.Deployment{
Spec: appsv1.DeploymentSpec{
Replicas: gen.Spec.Replicas,
Strategy: appsv1.DeploymentStrategy{
Type: appsv1.RollingUpdateDeploymentStrategyType,
RollingUpdate: &appsv1.RollingUpdateDeployment{
MaxUnavailable: util.IntStrPtr(intstr.FromInt(0)),
MaxSurge: util.IntStrPtr(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: "mapping-service",
Image: fmt.Sprintf("%s:%s", *gen.Spec.Image.Name, *gen.Spec.Image.Tag),
Ports: pod.ContainerPorts(
pod.ContainerPortTCP("mapping", 8093),
pod.ContainerPortTCP("management", 8090),
pod.ContainerPortTCP("metrics", 9421),
),
Env: pod.BuildEnvironment(gen.Options),
Resources: corev1.ResourceRequirements(*gen.Spec.Resources),
ImagePullPolicy: *gen.Spec.Image.PullPolicy,
LivenessProbe: pod.TCPProbe(intstr.FromString("mapping"), *gen.Spec.LivenessProbe),
ReadinessProbe: pod.HTTPProbe("/status/ready", intstr.FromString("management"), corev1.URISchemeHTTP, *gen.Spec.ReadinessProbe),
TerminationMessagePath: corev1.TerminationMessagePathDefault,
TerminationMessagePolicy: corev1.TerminationMessageReadFile,
},
},
RestartPolicy: corev1.RestartPolicyAlways,
SecurityContext: &corev1.PodSecurityContext{},
Affinity: pod.Affinity(gen.GetSelector(), gen.Spec.NodeAffinity),
Tolerations: gen.Spec.Tolerations,
TerminationGracePeriodSeconds: pointer.Int64(30),
},
},
},
}
}
}