-
Notifications
You must be signed in to change notification settings - Fork 130
Expand file tree
/
Copy pathappruntime_controller_test.go
More file actions
83 lines (72 loc) · 2.46 KB
/
appruntime_controller_test.go
File metadata and controls
83 lines (72 loc) · 2.46 KB
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
package controller
import (
"context"
enterpriseApi "github.com/splunk/splunk-operator/api/v4"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
"k8s.io/client-go/kubernetes/scheme"
"sigs.k8s.io/controller-runtime/pkg/client/fake"
)
var _ = Describe("AppRuntime Controller", func() {
BeforeEach(func() {
Expect(enterpriseApi.AddToScheme(scheme.Scheme)).To(Succeed())
})
It("creates a headless service that exposes the appruntime port", func() {
ctx := context.Background()
ar := &enterpriseApi.AppRuntime{
ObjectMeta: metav1.ObjectMeta{
Name: "stack1-standalone-appruntime",
Namespace: "test",
},
}
reconciler := AppRuntimeReconciler{
Client: fake.NewClientBuilder().WithScheme(scheme.Scheme).WithObjects(ar).Build(),
Scheme: scheme.Scheme,
}
svc, err := reconciler.createHeadlessService(ctx, ar, types.NamespacedName{
Name: getHeadlessName(ar.Name),
Namespace: ar.Namespace,
})
Expect(err).NotTo(HaveOccurred())
Expect(svc.Spec.ClusterIP).To(Equal(corev1.ClusterIPNone))
Expect(svc.Spec.Ports).To(HaveLen(1))
Expect(svc.Spec.Ports[0].Name).To(Equal("appruntime"))
Expect(svc.Spec.Ports[0].Port).To(Equal(int32(9000)))
Expect(svc.Spec.Ports[0].TargetPort.IntValue()).To(Equal(9000))
})
It("creates appruntime pods with container port 9000", func() {
ctx := context.Background()
ar := &enterpriseApi.AppRuntime{
ObjectMeta: metav1.ObjectMeta{
Name: "stack1-standalone-appruntime",
Namespace: "test",
},
Spec: enterpriseApi.AppRuntimeSpec{
Image: "supervisor:0.0.1",
Replicas: 1,
},
}
reconciler := AppRuntimeReconciler{
Client: fake.NewClientBuilder().WithScheme(scheme.Scheme).WithObjects(ar).Build(),
Scheme: scheme.Scheme,
}
err := reconciler.createPod(ctx, ar, types.NamespacedName{
Name: getPodName(ar.Name, 0),
Namespace: ar.Namespace,
}, "splunk-stack1-standalone", 0)
Expect(err).NotTo(HaveOccurred())
pod := &corev1.Pod{}
err = reconciler.Get(ctx, types.NamespacedName{
Name: getPodName(ar.Name, 0),
Namespace: ar.Namespace,
}, pod)
Expect(err).NotTo(HaveOccurred())
Expect(pod.Spec.Containers).NotTo(BeEmpty())
Expect(pod.Spec.Containers[0].Ports).To(HaveLen(1))
Expect(pod.Spec.Containers[0].Ports[0].Name).To(Equal("appruntime"))
Expect(pod.Spec.Containers[0].Ports[0].ContainerPort).To(Equal(int32(9000)))
})
})