forked from kedacore/http-add-on
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathk8s_objects_util_test.go
67 lines (63 loc) · 1.47 KB
/
k8s_objects_util_test.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
package main
import (
appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"github.com/kedacore/http-add-on/pkg/k8s"
)
// newDeployment creates a new deployment object
// with the given name and the given image. This does not actually create
// the deployment in the cluster, it just creates the deployment object
// in memory
func newDeployment(
namespace,
name,
image string,
ports []int32,
env []corev1.EnvVar,
labels map[string]string,
pullPolicy corev1.PullPolicy,
) *appsv1.Deployment {
containerPorts := make([]corev1.ContainerPort, len(ports))
for i, port := range ports {
containerPorts[i] = corev1.ContainerPort{
ContainerPort: port,
}
}
deployment := &appsv1.Deployment{
TypeMeta: metav1.TypeMeta{
Kind: "Deployment",
},
ObjectMeta: metav1.ObjectMeta{
Name: name,
Namespace: namespace,
Labels: labels,
},
Spec: appsv1.DeploymentSpec{
Selector: &metav1.LabelSelector{
MatchLabels: labels,
},
Replicas: k8s.Int32P(1),
Template: corev1.PodTemplateSpec{
ObjectMeta: metav1.ObjectMeta{
Labels: labels,
},
Spec: corev1.PodSpec{
Containers: []corev1.Container{
{
Image: image,
Name: name,
ImagePullPolicy: pullPolicy,
Ports: containerPorts,
Env: env,
},
},
},
},
},
Status: appsv1.DeploymentStatus{
ReadyReplicas: 1,
},
}
return deployment
}