Skip to content

Commit 95a68d1

Browse files
authored
Adding support for NodeJS auto instrumentation and integ tests (#220)
1 parent 15bfd18 commit 95a68d1

18 files changed

+365
-27
lines changed

.github/workflows/operator-integration-test.yml

Lines changed: 41 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,27 @@ jobs:
127127
go run integration-tests/manifests/cmd/validate_instrumentation_vars.go default integration-tests/manifests/cmd/ns_instrumentation_env_variables.json
128128
kubectl delete instrumentation sample-instrumentation
129129
130+
- name: Test for default instrumentation resources for nodejs
131+
run: |
132+
kubectl delete pods --all -n default
133+
sleep 5
134+
cat integration-tests/nodejs/sample-deployment-nodejs.yaml
135+
kubectl apply -f integration-tests/nodejs/sample-deployment-nodejs.yaml
136+
sleep 5
137+
kubectl wait --for=condition=Available deployment/nginx -n default
138+
kubectl get pods -A
139+
kubectl describe pods -n default
140+
go run integration-tests/manifests/cmd/validate_instrumentation_vars.go default integration-tests/nodejs/default_instrumentation_nodejs_env_variables.json
141+
142+
- name: Test for defined instrumentation resources for nodejs
143+
run: |
144+
kubectl apply -f integration-tests/manifests/sample-instrumentation.yaml
145+
kubectl delete pods --all -n default
146+
sleep 5
147+
kubectl wait --for=condition=Available deployment/nginx -n default
148+
sleep 5
149+
go run integration-tests/manifests/cmd/validate_instrumentation_vars.go default integration-tests/manifests/cmd/ns_instrumentation_env_variables.json
150+
kubectl delete instrumentation sample-instrumentation
130151
131152
- name: Test for default instrumentation resources for all languages
132153
run: |
@@ -142,7 +163,8 @@ jobs:
142163
kubectl apply -f integration-tests/manifests/sample-instrumentation.yaml
143164
kubectl delete pods --all -n default
144165
sleep 5
145-
kubectl wait --for=condition=Ready pod --all -n default
166+
kubectl wait --for=condition=Available deployment/nginx -n default
167+
sleep 5
146168
go run integration-tests/manifests/cmd/validate_instrumentation_vars.go default integration-tests/manifests/cmd/ns_instrumentation_env_variables.json
147169
kubectl delete instrumentation sample-instrumentation
148170
@@ -183,18 +205,21 @@ jobs:
183205
184206
- name: Test Annotations
185207
run: |
186-
kubectl apply -f integration-tests/manifests/sample-deployment.yaml
187208
kubectl get pods -A
188209
kubectl describe pods -n default
189-
sleep 5
210+
sleep 10
190211
go test -v -run TestAllLanguagesDeployment ./integration-tests/manifests/annotations -timeout 30m
212+
kubectl get pods -A
213+
kubectl describe pods -n default
191214
sleep 5
192215
go test -v -run TestJavaOnlyDeployment ./integration-tests/manifests/annotations -timeout 30m
193216
sleep 5
194217
go test -v -run TestPythonOnlyDeployment ./integration-tests/manifests/annotations -timeout 30m
195218
sleep 5
196219
go test -v -run TestDotNetOnlyDeployment ./integration-tests/manifests/annotations -timeout 30m
197220
sleep 5
221+
go test -v -run TestNodeJSOnlyDeployment ./integration-tests/manifests/annotations -timeout 30m
222+
sleep 5
198223
go test -v -run TestAnnotationsOnMultipleResources ./integration-tests/manifests/annotations -timeout 30m
199224
200225
DaemonsetAnnotationsTest:
@@ -233,18 +258,21 @@ jobs:
233258
234259
- name: Test Annotations
235260
run: |
236-
kubectl apply -f integration-tests/manifests/sample-daemonset.yaml
237261
sleep 5
238262
kubectl get pods -A
239263
kubectl describe pods -n default
240264
go test -v -run TestAllLanguagesDaemonSet ./integration-tests/manifests/annotations -timeout 30m
265+
kubectl get pods -A
266+
kubectl describe pods -n default
241267
sleep 5
242268
go test -v -run TestJavaOnlyDaemonSet ./integration-tests/manifests/annotations -timeout 30m
243269
sleep 5
244270
go test -v -run TestPythonOnlyDaemonSet ./integration-tests/manifests/annotations -timeout 30m
245271
sleep 5
246272
go test -v -run TestDotNetOnlyDaemonSet ./integration-tests/manifests/annotations -timeout 30m
247273
sleep 5
274+
go test -v -run TestNodeJSOnlyDaemonSet ./integration-tests/manifests/annotations -timeout 30m
275+
sleep 5
248276
go test -v -run TestAutoAnnotationForManualAnnotationRemoval ./integration-tests/manifests/annotations -timeout 30m
249277
250278
StatefulsetAnnotationsTest:
@@ -283,16 +311,20 @@ jobs:
283311
284312
- name: Test Annotations
285313
run: |
286-
kubectl apply -f integration-tests/manifests/sample-statefulset.yaml
287-
sleep 5
288314
kubectl get pods -A
289315
kubectl describe pods -n default
290316
go test -v -run TestAllLanguagesStatefulSet ./integration-tests/manifests/annotations -timeout 30m
317+
kubectl get pods -A
318+
kubectl describe pods -n default
291319
sleep 5
292320
go test -v -run TestJavaOnlyStatefulSet ./integration-tests/manifests/annotations -timeout 30m
293321
sleep 5
294322
go test -v -run TestPythonOnlyStatefulSet ./integration-tests/manifests/annotations -timeout 30m
295323
sleep 5
324+
go test -v -run TestDotNetOnlyStatefulSet ./integration-tests/manifests/annotations -timeout 30m
325+
sleep 5
326+
go test -v -run TestNodeJSOnlyStatefulSet ./integration-tests/manifests/annotations -timeout 30m
327+
sleep 5
296328
go test -v -run TestOnlyNonAnnotatedAppsShouldBeRestarted ./integration-tests/manifests/annotations -timeout 30m
297329
298330
@@ -342,4 +374,6 @@ jobs:
342374
sleep 5
343375
go test -v -run TestDotNetOnlyNamespace ./integration-tests/manifests/annotations -timeout 30m
344376
sleep 5
345-
go test -v -run TestAlreadyAutoAnnotatedResourceShouldNotRestart ./integration-tests/manifests/annotations -timeout 30m
377+
go test -v -run TestNodeJSOnlyNamespace ./integration-tests/manifests/annotations -timeout 30m
378+
sleep 5
379+
go test -v -run TestAlreadyAutoAnnotatedResourceShouldNotRestart ./integration-tests/manifests/annotations -timeout 30m

Dockerfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,12 @@ ARG AGENT_VERSION
2727
ARG AUTO_INSTRUMENTATION_JAVA_VERSION
2828
ARG AUTO_INSTRUMENTATION_PYTHON_VERSION
2929
ARG AUTO_INSTRUMENTATION_DOTNET_VERSION
30+
ARG AUTO_INSTRUMENTATION_NODEJS_VERSION
3031
ARG DCMG_EXPORTER_VERSION
3132
ARG NEURON_MONITOR_VERSION
3233

3334
# Build
34-
RUN CGO_ENABLED=0 GOOS=linux GO111MODULE=on go build -ldflags="-X ${VERSION_PKG}.version=${VERSION} -X ${VERSION_PKG}.buildDate=${VERSION_DATE} -X ${VERSION_PKG}.agent=${AGENT_VERSION} -X ${VERSION_PKG}.autoInstrumentationJava=${AUTO_INSTRUMENTATION_JAVA_VERSION} -X ${VERSION_PKG}.autoInstrumentationPython=${AUTO_INSTRUMENTATION_PYTHON_VERSION} -X ${VERSION_PKG}.autoInstrumentationDotNet=${AUTO_INSTRUMENTATION_DOTNET_VERSION} -X ${VERSION_PKG}.dcgmExporter=${DCMG_EXPORTER_VERSION} -X ${VERSION_PKG}.neuronMonitor=${NEURON_MONITOR_VERSION}" -a -o manager main.go
35+
RUN CGO_ENABLED=0 GOOS=linux GO111MODULE=on go build -ldflags="-X ${VERSION_PKG}.version=${VERSION} -X ${VERSION_PKG}.buildDate=${VERSION_DATE} -X ${VERSION_PKG}.agent=${AGENT_VERSION} -X ${VERSION_PKG}.autoInstrumentationJava=${AUTO_INSTRUMENTATION_JAVA_VERSION} -X ${VERSION_PKG}.autoInstrumentationPython=${AUTO_INSTRUMENTATION_PYTHON_VERSION} -X ${VERSION_PKG}.autoInstrumentationDotNet=${AUTO_INSTRUMENTATION_DOTNET_VERSION} -X ${VERSION_PKG}.autoInstrumentationNodeJS=${AUTO_INSTRUMENTATION_NODEJS_VERSION} -X ${VERSION_PKG}.dcgmExporter=${DCMG_EXPORTER_VERSION} -X ${VERSION_PKG}.neuronMonitor=${NEURON_MONITOR_VERSION}" -a -o manager main.go
3536

3637
# Use distroless as minimal base image to package the manager binary
3738
# Refer to https://github.com/GoogleContainerTools/distroless for more details

Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ AGENT_VERSION ?= "$(shell grep -v '\#' versions.txt | grep cloudwatch-agent | aw
66
AUTO_INSTRUMENTATION_JAVA_VERSION ?= "$(shell grep -v '\#' versions.txt | grep aws-otel-java-instrumentation | awk -F= '{print $$2}')"
77
AUTO_INSTRUMENTATION_PYTHON_VERSION ?= "$(shell grep -v '\#' versions.txt | grep aws-otel-python-instrumentation | awk -F= '{print $$2}')"
88
AUTO_INSTRUMENTATION_DOTNET_VERSION ?= "$(shell grep -v '\#' versions.txt | grep aws-otel-dotnet-instrumentation | awk -F= '{print $$2}')"
9+
AUTO_INSTRUMENTATION_NODEJS_VERSION ?= "$(shell grep -v '\#' versions.txt | grep aws-otel-nodejs-instrumentation | awk -F= '{print $$2}')"
910
DCGM_EXPORTER_VERSION ?= "$(shell grep -v '\#' versions.txt | grep dcgm-exporter | awk -F= '{print $$2}')"
1011
NEURON_MONITOR_VERSION ?= "$(shell grep -v '\#' versions.txt | grep neuron-monitor | awk -F= '{print $$2}')"
1112

@@ -154,7 +155,7 @@ generate: controller-gen api-docs
154155
# buildx is used to ensure same results for arm based systems (m1/2 chips)
155156
.PHONY: container
156157
container:
157-
docker buildx build --load --platform linux/${ARCH} -t ${IMG} --build-arg VERSION_PKG=${VERSION_PKG} --build-arg VERSION=${VERSION} --build-arg VERSION_DATE=${VERSION_DATE} --build-arg AGENT_VERSION=${AGENT_VERSION} --build-arg AUTO_INSTRUMENTATION_JAVA_VERSION=${AUTO_INSTRUMENTATION_JAVA_VERSION} --build-arg AUTO_INSTRUMENTATION_PYTHON_VERSION=${AUTO_INSTRUMENTATION_PYTHON_VERSION} --build-arg AUTO_INSTRUMENTATION_DOTNET_VERSION=${AUTO_INSTRUMENTATION_DOTNET_VERSION} --build-arg DCGM_EXPORTER_VERSION=${DCGM_EXPORTER_VERSION} --build-arg NEURON_MONITOR_VERSION=${NEURON_MONITOR_VERSION} .
158+
docker buildx build --load --platform linux/${ARCH} -t ${IMG} --build-arg VERSION_PKG=${VERSION_PKG} --build-arg VERSION=${VERSION} --build-arg VERSION_DATE=${VERSION_DATE} --build-arg AGENT_VERSION=${AGENT_VERSION} --build-arg AUTO_INSTRUMENTATION_JAVA_VERSION=${AUTO_INSTRUMENTATION_JAVA_VERSION} --build-arg AUTO_INSTRUMENTATION_PYTHON_VERSION=${AUTO_INSTRUMENTATION_PYTHON_VERSION} --build-arg AUTO_INSTRUMENTATION_DOTNET_VERSION=${AUTO_INSTRUMENTATION_DOTNET_VERSION} --build-arg AUTO_INSTRUMENTATION_NODEJS_VERSION=${AUTO_INSTRUMENTATION_NODEJS_VERSION} --build-arg DCGM_EXPORTER_VERSION=${DCGM_EXPORTER_VERSION} --build-arg NEURON_MONITOR_VERSION=${NEURON_MONITOR_VERSION} .
158159

159160
# Push the container image, used only for local dev purposes
160161
.PHONY: container-push

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ Supported Languages:
55
- Java
66
- Python
77
- .NET
8+
- NodeJS
89

910
This repo is based off of the [OpenTelemetry Operator](https://github.com/open-telemetry/opentelemetry-operator)
1011

integration-tests/manifests/annotations/validate_annotation_daemonset_test.go

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,12 @@ func TestAllLanguagesDaemonSet(t *testing.T) {
4242
Deployments: []string{""},
4343
StatefulSets: []string{""},
4444
},
45+
NodeJS: auto.AnnotationResources{
46+
Namespaces: []string{""},
47+
DaemonSets: []string{filepath.Join(uniqueNamespace, daemonSetName)},
48+
Deployments: []string{""},
49+
StatefulSets: []string{""},
50+
},
4551
}
4652
jsonStr, err := json.Marshal(annotationConfig)
4753
if err != nil {
@@ -51,7 +57,7 @@ func TestAllLanguagesDaemonSet(t *testing.T) {
5157
startTime := time.Now()
5258
updateTheOperator(t, clientSet, string(jsonStr))
5359

54-
if err := checkResourceAnnotations(t, clientSet, "daemonset", uniqueNamespace, daemonSetName, sampleDaemonsetYamlRelPath, startTime, []string{injectJavaAnnotation, autoAnnotateJavaAnnotation, injectPythonAnnotation, autoAnnotatePythonAnnotation, injectDotNetAnnotation, autoAnnotateDotNetAnnotation}, false); err != nil {
60+
if err := checkResourceAnnotations(t, clientSet, "daemonset", uniqueNamespace, daemonSetName, sampleDaemonsetYamlRelPath, startTime, []string{injectJavaAnnotation, autoAnnotateJavaAnnotation, injectPythonAnnotation, autoAnnotatePythonAnnotation, injectDotNetAnnotation, autoAnnotateDotNetAnnotation, injectNodeJSAnnotation, autoAnnotateNodeJSAnnotation}, false); err != nil {
5561
t.Fatalf("Failed annotation check: %s", err.Error())
5662
}
5763

@@ -156,3 +162,27 @@ func TestDotNetOnlyDaemonSet(t *testing.T) {
156162
}
157163

158164
}
165+
func TestNodeJSOnlyDaemonSet(t *testing.T) {
166+
clientSet := setupTest(t)
167+
randomNumber, err := rand.Int(rand.Reader, big.NewInt(9000))
168+
if err != nil {
169+
panic(err)
170+
}
171+
randomNumber.Add(randomNumber, big.NewInt(1000)) //adding a hash to namespace
172+
uniqueNamespace := fmt.Sprintf("daemonset-namespace-nodejs-only-%d", randomNumber)
173+
annotationConfig := auto.AnnotationConfig{
174+
NodeJS: auto.AnnotationResources{
175+
DaemonSets: []string{filepath.Join(uniqueNamespace, daemonSetName)},
176+
},
177+
}
178+
jsonStr, err := json.Marshal(annotationConfig)
179+
if err != nil {
180+
t.Error("Error:", err)
181+
}
182+
startTime := time.Now()
183+
updateTheOperator(t, clientSet, string(jsonStr))
184+
185+
if err := checkResourceAnnotations(t, clientSet, "daemonset", uniqueNamespace, daemonSetName, sampleDaemonsetYamlRelPath, startTime, []string{injectNodeJSAnnotation, autoAnnotateNodeJSAnnotation}, false); err != nil {
186+
t.Fatalf("Failed annotation check: %s", err.Error())
187+
}
188+
}

integration-tests/manifests/annotations/validate_annotation_methods.go

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ const (
3535
injectDotNetAnnotation = "instrumentation.opentelemetry.io/inject-dotnet"
3636
autoAnnotateDotNetAnnotation = "cloudwatch.aws.amazon.com/auto-annotate-dotnet"
3737

38+
injectNodeJSAnnotation = "instrumentation.opentelemetry.io/inject-nodejs"
39+
autoAnnotateNodeJSAnnotation = "cloudwatch.aws.amazon.com/auto-annotate-nodejs"
40+
3841
deploymentName = "sample-deployment"
3942
nginxDeploymentName = "nginx"
4043
statefulSetName = "sample-statefulset"
@@ -175,8 +178,9 @@ func checkNameSpaceAnnotations(t *testing.T, clientSet *kubernetes.Clientset, ex
175178
fmt.Println("There was an error getting namespace, ", err)
176179
return false
177180
}
181+
178182
for _, annotation := range expectedAnnotations {
179-
fmt.Printf("\n This is the annotation: %v and its status %v, namespace name: %v, \n", annotation, ns.Status, ns.Name)
183+
fmt.Printf("\n This is the annotation: %v and its status %v, namespace name: %v, \n", ns.ObjectMeta.Annotations, ns.Status, ns.Name)
180184
if ns.ObjectMeta.Annotations[annotation] != "true" {
181185
time.Sleep(timeBetweenRetries)
182186
correct = false
@@ -261,6 +265,25 @@ func checkIfAnnotationExists(clientset *kubernetes.Clientset, pods *v1.PodList,
261265
}
262266

263267
fmt.Println("Annotations not found in all pods or some pods are not in Running phase. Retrying...")
268+
cmd := exec.Command("kubectl", "rollout", "restart", "deployment", amazonControllerManager, "-n", amazonCloudwatchNamespace)
269+
270+
// Run the command and capture the output
271+
output, err := cmd.CombinedOutput()
272+
if err != nil {
273+
fmt.Printf("Error restarting deployment: %v\n", err)
274+
fmt.Printf("Output: %s\n", output)
275+
} else {
276+
fmt.Printf("Successfully deleted deployment: %s\n", output)
277+
}
278+
waitCmd := exec.Command("kubectl", "wait", "--for=condition=Available", "deployment/"+amazonControllerManager, "-n", amazonCloudwatchNamespace, "--timeout=300s")
279+
280+
waitOutput, err := waitCmd.CombinedOutput()
281+
if err != nil {
282+
fmt.Printf("Error waiting for deployment: %v\n", err)
283+
fmt.Printf("Output: %s\n", waitOutput)
284+
} else {
285+
fmt.Printf("Deployment is now available: %s\n", waitOutput)
286+
}
264287
time.Sleep(timeBetweenRetries)
265288
}
266289
}

integration-tests/manifests/annotations/validate_annotations_deployment_test.go

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,20 @@ func TestAllLanguagesDeployment(t *testing.T) {
4444
Deployments: []string{filepath.Join(uniqueNamespace, deploymentName)},
4545
StatefulSets: []string{""},
4646
},
47+
NodeJS: auto.AnnotationResources{
48+
Namespaces: []string{""},
49+
DaemonSets: []string{""},
50+
Deployments: []string{filepath.Join(uniqueNamespace, deploymentName)},
51+
StatefulSets: []string{""},
52+
},
4753
}
4854
jsonStr, err := json.Marshal(annotationConfig)
4955
assert.Nil(t, err)
5056

5157
startTime := time.Now()
5258
updateTheOperator(t, clientSet, string(jsonStr))
5359

54-
if err := checkResourceAnnotations(t, clientSet, "deployment", uniqueNamespace, deploymentName, sampleDeploymentYamlNameRelPath, startTime, []string{injectJavaAnnotation, autoAnnotateJavaAnnotation, injectPythonAnnotation, autoAnnotatePythonAnnotation, injectDotNetAnnotation, autoAnnotateDotNetAnnotation}, false); err != nil {
60+
if err := checkResourceAnnotations(t, clientSet, "deployment", uniqueNamespace, deploymentName, sampleDeploymentYamlNameRelPath, startTime, []string{injectJavaAnnotation, autoAnnotateJavaAnnotation, injectPythonAnnotation, autoAnnotatePythonAnnotation, injectDotNetAnnotation, autoAnnotateDotNetAnnotation, injectNodeJSAnnotation, autoAnnotateNodeJSAnnotation}, false); err != nil {
5561
t.Fatalf("Failed annotation check: %s", err.Error())
5662
}
5763

@@ -89,7 +95,7 @@ func TestJavaOnlyDeployment(t *testing.T) {
8995
updateTheOperator(t, clientSet, string(jsonStr))
9096

9197
if err := checkResourceAnnotations(t, clientSet, "deployment", uniqueNamespace, deploymentName, sampleDeploymentYamlNameRelPath, startTime, []string{injectJavaAnnotation, autoAnnotateJavaAnnotation}, false); err != nil {
92-
t.Fatalf("Failed annotation check: %s", err.Error())
98+
t.Fatalf("Failed annotation check: %s", err.Error())
9399
}
94100
}
95101

@@ -167,3 +173,40 @@ func TestDotNetOnlyDeployment(t *testing.T) {
167173
}
168174

169175
}
176+
177+
func TestNodeJSOnlyDeployment(t *testing.T) {
178+
179+
clientSet := setupTest(t)
180+
randomNumber, err := rand.Int(rand.Reader, big.NewInt(9000))
181+
if err != nil {
182+
panic(err)
183+
}
184+
randomNumber.Add(randomNumber, big.NewInt(1000)) //adding a hash to namespace
185+
uniqueNamespace := fmt.Sprintf("deployment-namespace-nodejs-only-%d", randomNumber)
186+
187+
annotationConfig := auto.AnnotationConfig{
188+
NodeJS: auto.AnnotationResources{
189+
Namespaces: []string{""},
190+
DaemonSets: []string{""},
191+
Deployments: []string{filepath.Join(uniqueNamespace, deploymentName)},
192+
StatefulSets: []string{""},
193+
},
194+
}
195+
jsonStr, err := json.Marshal(annotationConfig)
196+
if err != nil {
197+
t.Error("Error:", err)
198+
t.Error("Error:", err)
199+
200+
}
201+
202+
startTime := time.Now()
203+
updateTheOperator(t, clientSet, string(jsonStr))
204+
if err != nil {
205+
t.Errorf("Failed to get deployment app: %s", err.Error())
206+
}
207+
208+
if err := checkResourceAnnotations(t, clientSet, "deployment", uniqueNamespace, deploymentName, sampleDeploymentYamlNameRelPath, startTime, []string{injectNodeJSAnnotation, autoAnnotateNodeJSAnnotation}, false); err != nil {
209+
t.Fatalf("Failed annotation check: %s", err.Error())
210+
}
211+
212+
}

integration-tests/manifests/annotations/validate_annotations_namespace_test.go

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,12 @@ func TestAllLanguagesNamespace(t *testing.T) {
5050
Deployments: []string{""},
5151
StatefulSets: []string{""},
5252
},
53+
NodeJS: auto.AnnotationResources{
54+
Namespaces: []string{uniqueNamespace},
55+
DaemonSets: []string{""},
56+
Deployments: []string{""},
57+
StatefulSets: []string{""},
58+
},
5359
}
5460
jsonStr, err := json.Marshal(annotationConfig)
5561
if err != nil {
@@ -58,7 +64,7 @@ func TestAllLanguagesNamespace(t *testing.T) {
5864
startTime := time.Now()
5965

6066
updateTheOperator(t, clientSet, string(jsonStr))
61-
if !checkNameSpaceAnnotations(t, clientSet, []string{injectJavaAnnotation, autoAnnotateJavaAnnotation, injectPythonAnnotation, autoAnnotatePythonAnnotation, injectDotNetAnnotation, autoAnnotateDotNetAnnotation}, uniqueNamespace, startTime) {
67+
if !checkNameSpaceAnnotations(t, clientSet, []string{injectJavaAnnotation, autoAnnotateJavaAnnotation, injectPythonAnnotation, autoAnnotatePythonAnnotation, injectDotNetAnnotation, autoAnnotateDotNetAnnotation, injectNodeJSAnnotation, autoAnnotateNodeJSAnnotation}, uniqueNamespace, startTime) {
6268
t.Error("Missing Languages annotations")
6369
}
6470
}
@@ -184,6 +190,44 @@ func TestDotNetOnlyNamespace(t *testing.T) {
184190
}
185191
}
186192

193+
func TestNodeJSOnlyNamespace(t *testing.T) {
194+
195+
clientSet := setupTest(t)
196+
randomNumber, err := rand.Int(rand.Reader, big.NewInt(9000))
197+
if err != nil {
198+
panic(err)
199+
}
200+
randomNumber.Add(randomNumber, big.NewInt(1000)) //adding a hash to namespace
201+
uniqueNamespace := fmt.Sprintf("namespace-nodejs-only-%d", randomNumber)
202+
if err := createNamespace(clientSet, uniqueNamespace); err != nil {
203+
t.Fatalf("Failed to create/apply resoures on namespace: %v", err)
204+
}
205+
206+
defer func() {
207+
if err := deleteNamespace(clientSet, uniqueNamespace); err != nil {
208+
t.Fatalf("Failed to delete namespace: %v", err)
209+
}
210+
}()
211+
212+
annotationConfig := auto.AnnotationConfig{
213+
NodeJS: auto.AnnotationResources{
214+
Namespaces: []string{uniqueNamespace},
215+
},
216+
}
217+
jsonStr, err := json.Marshal(annotationConfig)
218+
if err != nil {
219+
t.Error("Error:", err)
220+
}
221+
222+
startTime := time.Now()
223+
224+
updateTheOperator(t, clientSet, string(jsonStr))
225+
226+
if !checkNameSpaceAnnotations(t, clientSet, []string{injectNodeJSAnnotation, autoAnnotateNodeJSAnnotation}, uniqueNamespace, startTime) {
227+
t.Error("Missing nodejs annotations")
228+
}
229+
}
230+
187231
// Multiple resources on the same namespace should all get annotations
188232
func TestAnnotationsOnMultipleResources(t *testing.T) {
189233

0 commit comments

Comments
 (0)