Skip to content

Commit e4448a6

Browse files
authored
[chore] update make target and restore unittests (#1832)
1 parent 6a6ba28 commit e4448a6

8 files changed

+285
-1
lines changed

Makefile

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,15 @@ pre-commit: render ## Test the Helm chart with pre-commit
9696
.PHONY: unittest
9797
unittest: ## Run unittests on the Helm chart
9898
@echo "Running unit tests on helm chart..."
99-
cd helm-charts/splunk-otel-collector && helm unittest --strict -f "../../test/unittests/*.yaml" . || exit 1
99+
@if [ ! -d "unittests" ]; then \
100+
echo "Error: 'unittests' directory does not exist."; \
101+
exit 1; \
102+
fi
103+
@if ! ls unittests/*.yaml 1> /dev/null 2>&1; then \
104+
echo "Error: No test files found in 'unittests' directory."; \
105+
exit 1; \
106+
fi
107+
cd helm-charts/splunk-otel-collector && helm unittest --strict -f "../../unittests/*.yaml" . || exit 1
100108

101109
# Example Usage:
102110
# make functionaltest
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
suite: splunk-otel-collector.convertMemToMib
2+
templates:
3+
- "deployment-cluster-receiver.yaml"
4+
- "configmap-cluster-receiver.yaml" # referenced in deployment
5+
values:
6+
- ./values/basic.yaml
7+
tests:
8+
- it: convert floating-point memory limit (G to Mi)
9+
templates:
10+
- "deployment-cluster-receiver.yaml"
11+
set:
12+
clusterReceiver.resources.limits.memory: 1.5G
13+
asserts:
14+
- contains:
15+
path: spec.template.spec.containers[0].env
16+
content:
17+
name: SPLUNK_MEMORY_TOTAL_MIB
18+
value: "1430"
19+
- it: convert integer memory limit (M to Mi)
20+
templates:
21+
- "deployment-cluster-receiver.yaml"
22+
set:
23+
clusterReceiver.resources.limits.memory: 1000M
24+
asserts:
25+
- contains:
26+
path: spec.template.spec.containers[0].env
27+
content:
28+
name: SPLUNK_MEMORY_TOTAL_MIB
29+
value: "953"
30+
- it: convert integer memory limit (Ki to Mi)
31+
templates:
32+
- "deployment-cluster-receiver.yaml"
33+
set:
34+
clusterReceiver.resources.limits.memory: 1680Ki
35+
asserts:
36+
- contains:
37+
path: spec.template.spec.containers[0].env
38+
content:
39+
name: SPLUNK_MEMORY_TOTAL_MIB
40+
value: "1"
41+
- it: convert floating-point memory limit (Gi to Mi)
42+
templates:
43+
- "deployment-cluster-receiver.yaml"
44+
set:
45+
clusterReceiver.resources.limits.memory: 0.5Gi
46+
asserts:
47+
- contains:
48+
path: spec.template.spec.containers[0].env
49+
content:
50+
name: SPLUNK_MEMORY_TOTAL_MIB
51+
value: "512"
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
suite: splunk-otel-collector.operatorCustomized
2+
templates:
3+
- "operator/instrumentation.yaml"
4+
values:
5+
- ./values/operator_customized.yaml
6+
tests:
7+
- it: should render the Instrumentation spec correctly with default values
8+
asserts:
9+
- hasDocuments:
10+
count: 1
11+
- equal:
12+
path: spec.exporter.endpoint
13+
value: http://RELEASE-NAME-splunk-otel-collector-agent.NAMESPACE.svc.cluster.local:4317
14+
- contains:
15+
path: spec.env
16+
content:
17+
name: SPLUNK_PROFILER_ENABLED
18+
value: "true"
19+
- contains:
20+
path: spec.env
21+
content:
22+
name: SPLUNK_PROFILER_MEMORY_ENABLED
23+
value: "true"
24+
- contains:
25+
path: spec.nodejs.env
26+
content:
27+
name: OTEL_EXPORTER_OTLP_ENDPOINT
28+
value: "http://SOME-OTHER-RELEASE-NAME-splunk-otel-collector-agent.NAMESPACE.svc.cluster.local:4318"
29+
- contains:
30+
path: spec.nodejs.env
31+
content:
32+
name: SPLUNK_PROFILER_ENABLED
33+
value: "false"
34+
- contains:
35+
path: spec.nodejs.env
36+
content:
37+
name: SPLUNK_PROFILER_MEMORY_ENABLED
38+
value: "false"

unittests/operator_default_test.yaml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
suite: splunk-otel-collector.operatorDefault
2+
templates:
3+
- "operator/instrumentation.yaml"
4+
values:
5+
- ./values/operator_default.yaml
6+
tests:
7+
- it: should render the Instrumentation spec correctly with default values
8+
asserts:
9+
- hasDocuments:
10+
count: 1
11+
- equal:
12+
path: spec.exporter.endpoint
13+
value: http://RELEASE-NAME-splunk-otel-collector-agent.NAMESPACE.svc.cluster.local:4317
14+
- contains:
15+
path: spec.propagators
16+
content: tracecontext
17+
- contains:
18+
path: spec.propagators
19+
content: baggage
20+
- contains:
21+
path: spec.propagators
22+
content: b3
23+
- contains:
24+
path: spec.dotnet.env
25+
content:
26+
name: OTEL_DOTNET_AUTO_PLUGINS
27+
value: Splunk.OpenTelemetry.AutoInstrumentation.Plugin,Splunk.OpenTelemetry.AutoInstrumentation
28+
- contains:
29+
path: spec.dotnet.env
30+
content:
31+
name: OTEL_EXPORTER_OTLP_ENDPOINT
32+
value: http://RELEASE-NAME-splunk-otel-collector-agent.NAMESPACE.svc.cluster.local:4318
33+
- contains:
34+
path: spec.java.env
35+
content:
36+
name: OTEL_EXPORTER_OTLP_ENDPOINT
37+
value: http://RELEASE-NAME-splunk-otel-collector-agent.NAMESPACE.svc.cluster.local:4318

unittests/service_account_test.yaml

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
suite: splunk-otel-collector.serviceAccount
2+
values:
3+
- ./values/basic.yaml
4+
templates:
5+
- serviceAccount.yaml
6+
- deployment-cluster-receiver.yaml
7+
- configmap-cluster-receiver.yaml
8+
- daemonset.yaml
9+
- configmap-fluentd.yaml
10+
- configmap-agent.yaml
11+
release:
12+
name: test-release
13+
tests:
14+
- it: should render serviceaccount correctly
15+
set:
16+
image:
17+
imagePullSecrets:
18+
- secret1
19+
- secret2
20+
serviceAccount:
21+
create: true
22+
annotations:
23+
key1: value1
24+
featureGates:
25+
explicitMountServiceAccountToken: true # automount should be false
26+
template: serviceAccount.yaml
27+
asserts:
28+
- isKind:
29+
of: ServiceAccount
30+
template: serviceAccount.yaml
31+
- equal:
32+
path: metadata.name
33+
value: "test-release-splunk-otel-collector"
34+
- equal:
35+
path: metadata.annotations
36+
value:
37+
key1: value1
38+
- equal:
39+
path: automountServiceAccountToken
40+
value: false
41+
- equal:
42+
path: imagePullSecrets
43+
value:
44+
- name: secret1
45+
- name: secret2
46+
- it: should add default serviceAccountName to deployment and daemonset
47+
set:
48+
serviceAccount:
49+
create: true
50+
templates:
51+
- deployment-cluster-receiver.yaml
52+
- daemonset.yaml
53+
asserts:
54+
- equal:
55+
path: spec.template.spec.serviceAccountName
56+
value: "test-release-splunk-otel-collector"
57+
template: deployment-cluster-receiver.yaml
58+
- equal:
59+
path: spec.template.spec.serviceAccountName
60+
value: "test-release-splunk-otel-collector"
61+
template: daemonset.yaml
62+
- it: should not render serviceaccount
63+
set:
64+
serviceAccount:
65+
create: false
66+
template: serviceAccount.yaml
67+
asserts:
68+
- hasDocuments:
69+
count: 0
70+
- it: should set custom service account name correctly in serviceaccount, deployment and daemonset
71+
set:
72+
serviceAccount:
73+
create: true
74+
name: custom-service-account
75+
templates:
76+
- deployment-cluster-receiver.yaml
77+
- daemonset.yaml
78+
- serviceAccount.yaml
79+
asserts:
80+
- equal:
81+
path: spec.template.spec.serviceAccountName
82+
value: custom-service-account
83+
template: deployment-cluster-receiver.yaml
84+
- equal:
85+
path: spec.template.spec.serviceAccountName
86+
value: custom-service-account
87+
template: daemonset.yaml
88+
- equal:
89+
path: metadata.name
90+
value: custom-service-account
91+
template: serviceAccount.yaml
92+
- it: should set custom service account name correctly in deployment and daemonset with no serviceaccount
93+
set:
94+
serviceAccount:
95+
create: false
96+
name: custom-service-account
97+
templates:
98+
- deployment-cluster-receiver.yaml
99+
- daemonset.yaml
100+
- serviceAccount.yaml
101+
asserts:
102+
- equal:
103+
path: spec.template.spec.serviceAccountName
104+
value: custom-service-account
105+
template: deployment-cluster-receiver.yaml
106+
- equal:
107+
path: spec.template.spec.serviceAccountName
108+
value: custom-service-account
109+
template: daemonset.yaml
110+
- hasDocuments:
111+
count: 0
112+
template: serviceAccount.yaml

unittests/values/basic.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
clusterReceiver:
2+
enabled: true
3+
clusterName: test
4+
splunkObservability:
5+
realm: test
6+
accessToken: test
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
clusterName: test-gateway
2+
splunkObservability:
3+
realm: test
4+
accessToken: test
5+
# Should update instrumentation.env to include SPLUNK_PROFILER_ENABLED="true" and SPLUNK_PROFILER_MEMORY_ENABLED="true"
6+
profilingEnabled: true
7+
environment: test
8+
agent:
9+
enabled: false
10+
gateway:
11+
enabled: true
12+
operator:
13+
enabled: true
14+
instrumentation:
15+
sampler:
16+
type: traceidratio
17+
argument: "0.95"
18+
nodejs:
19+
env:
20+
- name: OTEL_EXPORTER_OTLP_ENDPOINT
21+
value: http://SOME-OTHER-RELEASE-NAME-splunk-otel-collector-agent.NAMESPACE.svc.cluster.local:4318
22+
- name: SPLUNK_PROFILER_ENABLED
23+
value: "false"
24+
- name: SPLUNK_PROFILER_MEMORY_ENABLED
25+
value: "false"
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
clusterName: test
2+
splunkObservability:
3+
realm: test
4+
accessToken: test
5+
environment: test
6+
operator:
7+
enabled: true

0 commit comments

Comments
 (0)