Skip to content

Commit 5fc2b38

Browse files
committed
Fixes
Signed-off-by: Rafal Lal <rafall@splunk.com>
1 parent dfb0713 commit 5fc2b38

5 files changed

Lines changed: 154 additions & 4 deletions

File tree

helm-chart/splunk-operator/templates/deployment.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ spec:
7878
- name: SPLUNK_GENERAL_TERMS
7979
value: {{ .Values.splunkOperator.splunkGeneralTerms | default "" }}
8080
{{- with .Values.extraEnvs }}
81-
{{- toYaml . | trim | nindent 10 }}
81+
{{- toYaml . | trim | nindent 12 }}
8282
{{- end }}
8383
ports:
8484
{{- range .Values.splunkOperator.service.ports }}
@@ -109,4 +109,4 @@ spec:
109109
{{- with .Values.splunkOperator.volumes }}
110110
volumes:
111111
{{- toYaml .| nindent 8 }}
112-
{{- end }}
112+
{{- end }}

helm-chart/splunk-operator/templates/rbac/clusterrole.yaml

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,32 @@ rules:
144144
- patch
145145
- update
146146
- watch
147+
- apiGroups:
148+
- enterprise.splunk.com
149+
resources:
150+
- appruntimes
151+
verbs:
152+
- create
153+
- delete
154+
- get
155+
- list
156+
- patch
157+
- update
158+
- watch
159+
- apiGroups:
160+
- enterprise.splunk.com
161+
resources:
162+
- appruntimes/status
163+
verbs:
164+
- get
165+
- patch
166+
- update
167+
- apiGroups:
168+
- enterprise.splunk.com
169+
resources:
170+
- appruntimes/finalizers
171+
verbs:
172+
- update
147173
- apiGroups:
148174
- enterprise.splunk.com
149175
resources:
@@ -430,4 +456,4 @@ rules:
430456
- get
431457
- patch
432458
- update
433-
{{- end }}
459+
{{- end }}

helm-chart/splunk-operator/templates/rbac/role.yaml

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,32 @@ rules:
144144
- patch
145145
- update
146146
- watch
147+
- apiGroups:
148+
- enterprise.splunk.com
149+
resources:
150+
- appruntimes
151+
verbs:
152+
- create
153+
- delete
154+
- get
155+
- list
156+
- patch
157+
- update
158+
- watch
159+
- apiGroups:
160+
- enterprise.splunk.com
161+
resources:
162+
- appruntimes/status
163+
verbs:
164+
- get
165+
- patch
166+
- update
167+
- apiGroups:
168+
- enterprise.splunk.com
169+
resources:
170+
- appruntimes/finalizers
171+
verbs:
172+
- update
147173
- apiGroups:
148174
- enterprise.splunk.com
149175
resources:
@@ -430,4 +456,4 @@ rules:
430456
- get
431457
- patch
432458
- update
433-
{{- end }}
459+
{{- end }}

internal/controller/appruntime_controller.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818
"k8s.io/apimachinery/pkg/labels"
1919
"k8s.io/apimachinery/pkg/runtime"
2020
"k8s.io/apimachinery/pkg/types"
21+
"k8s.io/apimachinery/pkg/util/intstr"
2122
"k8s.io/client-go/tools/record"
2223
ctrl "sigs.k8s.io/controller-runtime"
2324
"sigs.k8s.io/controller-runtime/pkg/client"
@@ -271,6 +272,14 @@ func (r *AppRuntimeReconciler) createHeadlessService(ctx context.Context, ar *en
271272
svc.Labels = getCommonLabels(ar.Name)
272273
svc.Spec.Selector = svc.Labels
273274
svc.Spec.ClusterIP = corev1.ClusterIPNone
275+
svc.Spec.Ports = []corev1.ServicePort{
276+
{
277+
Name: "appruntime",
278+
Port: 9000,
279+
Protocol: corev1.ProtocolTCP,
280+
TargetPort: intstr.FromInt(9000),
281+
},
282+
}
274283
err = r.Create(ctx, svc)
275284
if err != nil {
276285
return nil, err
@@ -316,6 +325,13 @@ func (r *AppRuntimeReconciler) createPod(ctx context.Context, appRuntime *enterp
316325
Command: []string{
317326
"/usr/bin/splunk-eps",
318327
},
328+
Ports: []corev1.ContainerPort{
329+
{
330+
Name: "appruntime",
331+
ContainerPort: 9000,
332+
Protocol: corev1.ProtocolTCP,
333+
},
334+
},
319335
VolumeMounts: []corev1.VolumeMount{
320336
{
321337
Name: "pvc-etc",
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,83 @@
11
package controller
2+
3+
import (
4+
"context"
5+
6+
enterpriseApi "github.com/splunk/splunk-operator/api/v4"
7+
8+
. "github.com/onsi/ginkgo/v2"
9+
. "github.com/onsi/gomega"
10+
corev1 "k8s.io/api/core/v1"
11+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
12+
"k8s.io/apimachinery/pkg/types"
13+
"k8s.io/client-go/kubernetes/scheme"
14+
"sigs.k8s.io/controller-runtime/pkg/client/fake"
15+
)
16+
17+
var _ = Describe("AppRuntime Controller", func() {
18+
BeforeEach(func() {
19+
Expect(enterpriseApi.AddToScheme(scheme.Scheme)).To(Succeed())
20+
})
21+
22+
It("creates a headless service that exposes the appruntime port", func() {
23+
ctx := context.Background()
24+
ar := &enterpriseApi.AppRuntime{
25+
ObjectMeta: metav1.ObjectMeta{
26+
Name: "stack1-standalone-appruntime",
27+
Namespace: "test",
28+
},
29+
}
30+
31+
reconciler := AppRuntimeReconciler{
32+
Client: fake.NewClientBuilder().WithScheme(scheme.Scheme).WithObjects(ar).Build(),
33+
Scheme: scheme.Scheme,
34+
}
35+
36+
svc, err := reconciler.createHeadlessService(ctx, ar, types.NamespacedName{
37+
Name: getHeadlessName(ar.Name),
38+
Namespace: ar.Namespace,
39+
})
40+
Expect(err).NotTo(HaveOccurred())
41+
Expect(svc.Spec.ClusterIP).To(Equal(corev1.ClusterIPNone))
42+
Expect(svc.Spec.Ports).To(HaveLen(1))
43+
Expect(svc.Spec.Ports[0].Name).To(Equal("appruntime"))
44+
Expect(svc.Spec.Ports[0].Port).To(Equal(int32(9000)))
45+
Expect(svc.Spec.Ports[0].TargetPort.IntValue()).To(Equal(9000))
46+
})
47+
48+
It("creates appruntime pods with container port 9000", func() {
49+
ctx := context.Background()
50+
ar := &enterpriseApi.AppRuntime{
51+
ObjectMeta: metav1.ObjectMeta{
52+
Name: "stack1-standalone-appruntime",
53+
Namespace: "test",
54+
},
55+
Spec: enterpriseApi.AppRuntimeSpec{
56+
Image: "supervisor:0.0.1",
57+
Replicas: 1,
58+
},
59+
}
60+
61+
reconciler := AppRuntimeReconciler{
62+
Client: fake.NewClientBuilder().WithScheme(scheme.Scheme).WithObjects(ar).Build(),
63+
Scheme: scheme.Scheme,
64+
}
65+
66+
err := reconciler.createPod(ctx, ar, types.NamespacedName{
67+
Name: getPodName(ar.Name, 0),
68+
Namespace: ar.Namespace,
69+
}, "splunk-stack1-standalone", 0)
70+
Expect(err).NotTo(HaveOccurred())
71+
72+
pod := &corev1.Pod{}
73+
err = reconciler.Get(ctx, types.NamespacedName{
74+
Name: getPodName(ar.Name, 0),
75+
Namespace: ar.Namespace,
76+
}, pod)
77+
Expect(err).NotTo(HaveOccurred())
78+
Expect(pod.Spec.Containers).NotTo(BeEmpty())
79+
Expect(pod.Spec.Containers[0].Ports).To(HaveLen(1))
80+
Expect(pod.Spec.Containers[0].Ports[0].Name).To(Equal("appruntime"))
81+
Expect(pod.Spec.Containers[0].Ports[0].ContainerPort).To(Equal(int32(9000)))
82+
})
83+
})

0 commit comments

Comments
 (0)