-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdeploy.go
45 lines (41 loc) · 1.11 KB
/
deploy.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
// Copyright 2023 Volvo Car Corporation
// SPDX-License-Identifier: Apache-2.0
package kubeutil
import (
appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
// SimpleDeployment creates a simple deployment with a single container.
func SimpleDeployment(
name, namespace string,
labels map[string]string,
replicas int32,
image string,
) *appsv1.Deployment {
return &appsv1.Deployment{
TypeMeta: TypeDeploymentV1,
ObjectMeta: ObjectMeta(name, namespace, labels, nil),
Spec: appsv1.DeploymentSpec{
Replicas: P(replicas),
Selector: &metav1.LabelSelector{MatchLabels: labels},
Template: corev1.PodTemplateSpec{
ObjectMeta: metav1.ObjectMeta{Labels: labels},
Spec: corev1.PodSpec{
ServiceAccountName: name,
Containers: []corev1.Container{
{
Name: name,
Image: image,
},
},
},
},
},
}
}
// SetDeploySA sets the ServiceAccountName in the deployment.
func SetDeploySA(deploy *appsv1.Deployment, saName string) *appsv1.Deployment {
deploy.Spec.Template.Spec.ServiceAccountName = saName
return deploy
}