in pkg/trait/deployment.go [112:203]
func (t *deploymentTrait) getDeploymentFor(e *Environment) *appsv1.Deployment {
// create a copy to avoid sharing the underlying annotation map
annotations := make(map[string]string)
if e.Integration.Annotations != nil {
for k, v := range filterTransferableAnnotations(e.Integration.Annotations) {
annotations[k] = v
}
}
deadline := defaultProgressDeadline
if t.ProgressDeadlineSeconds != nil {
deadline = *t.ProgressDeadlineSeconds
}
deployment := appsv1.Deployment{
TypeMeta: metav1.TypeMeta{
Kind: "Deployment",
APIVersion: appsv1.SchemeGroupVersion.String(),
},
ObjectMeta: metav1.ObjectMeta{
Name: e.Integration.Name,
Namespace: e.Integration.Namespace,
Labels: map[string]string{
v1.IntegrationLabel: e.Integration.Name,
},
Annotations: annotations,
},
Spec: appsv1.DeploymentSpec{
ProgressDeadlineSeconds: &deadline,
Replicas: e.Integration.Spec.Replicas,
Selector: &metav1.LabelSelector{
MatchLabels: map[string]string{
v1.IntegrationLabel: e.Integration.Name,
},
},
Template: corev1.PodTemplateSpec{
ObjectMeta: metav1.ObjectMeta{
Labels: map[string]string{
v1.IntegrationLabel: e.Integration.Name,
},
Annotations: annotations,
},
Spec: corev1.PodSpec{
ServiceAccountName: e.Integration.Spec.ServiceAccountName,
},
},
},
}
switch t.Strategy {
case appsv1.RecreateDeploymentStrategyType:
deployment.Spec.Strategy = appsv1.DeploymentStrategy{
Type: t.Strategy,
}
case appsv1.RollingUpdateDeploymentStrategyType:
deployment.Spec.Strategy = appsv1.DeploymentStrategy{
Type: t.Strategy,
}
if t.RollingUpdateMaxSurge != nil || t.RollingUpdateMaxUnavailable != nil {
var maxSurge *intstr.IntOrString
var maxUnavailable *intstr.IntOrString
if t.RollingUpdateMaxSurge != nil {
v := t.RollingUpdateMaxSurge
maxSurge = v
}
if t.RollingUpdateMaxUnavailable != nil {
v := t.RollingUpdateMaxUnavailable
maxUnavailable = v
}
deployment.Spec.Strategy.RollingUpdate = &appsv1.RollingUpdateDeployment{
MaxSurge: maxSurge,
MaxUnavailable: maxUnavailable,
}
}
}
// Reconcile the deployment replicas
replicas := e.Integration.Spec.Replicas
// Deployment replicas defaults to 1, so we avoid forcing
// an update to nil that will result to another update cycle
// back to that default value by the Deployment controller.
if replicas == nil {
one := int32(1)
replicas = &one
}
deployment.Spec.Replicas = replicas
return &deployment
}