Skip to content

Commit

Permalink
Fix Tests for New Operator Version (#117)
Browse files Browse the repository at this point in the history
* Update python test app for new operator version

* Update python test app

* Update testing workflows

* Fix Makefile issues by using 1 namespace like CI

* Silence github security warnings in test app

* Updating all agent helm charts to be similar

* Bump tests

* Add read only docker hub token for rate limits

* Remove unnecessary line

* Restore missing PHP annotation

* Fix PHP app name

* Drop cert-manager from make all

* Remove secret dependency for Makefile

* Automatically update helm repos

* Add waits to PHP curl requests in CI

* Add suggestions from code review
  • Loading branch information
TimPansino authored Oct 16, 2024
1 parent 92564f1 commit 3cc7b64
Show file tree
Hide file tree
Showing 24 changed files with 125 additions and 111 deletions.
15 changes: 7 additions & 8 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,13 @@ jobs:
with:
persist-credentials: false

# Gives higher rate limits for image pulls
- name: Login to Docker Hub Container Registry (Read Only)
uses: docker/login-action@9780b0c442fbb1117ed29e0efdff1e18412f7567 # 3.3.0
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_TOKEN_READ_ONLY }}

- name: Enable arm64 emulation
if: inputs.ARCHITECTURE != 'linux/amd64'
uses: docker/setup-qemu-action@49b3bc8e6bdd4a60e6116a5414239cba5943d3cf # 3.2.0
Expand All @@ -63,20 +70,12 @@ jobs:
- name: Start minikube
uses: medyagh/setup-minikube@d8c0eb871f6f455542491d86a574477bd3894533 # 0.0.18

- name: Deploy cert-manager to minikube
run: |
helm repo add jetstack https://charts.jetstack.io --force-update
helm install cert-manager jetstack/cert-manager --namespace cert-manager --create-namespace --version v1.14.5 --set installCRDs=true
sleep 5
kubectl wait --for=condition=Ready -n cert-manager --all pods
- name: Deploy New Relic k8s-agents-operator to minikube
run: |
helm repo add k8s-agents-operator https://newrelic.github.io/k8s-agents-operator
helm upgrade --install k8s-agents-operator k8s-agents-operator/k8s-agents-operator \
--namespace=default \
--set=licenseKey=${{ secrets.NEW_RELIC_LICENSE_KEY }} \
--set=newRelicHost=${{ vars.NEW_RELIC_HOST }} \
--set=controllerManager.manager.image.tag=${{ inputs.K8S_OPERATOR_IMAGE_TAG }}
sleep 5
kubectl wait --for=condition=Ready -n default --all pods
Expand Down
35 changes: 12 additions & 23 deletions tests/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,58 +14,47 @@ default: all

# Install all dependencies and run tests
.PHONY: all
all: minikube cert-manager operator test
all: minikube operator test

# Start minikube
.PHONY: minikube
minikube:
minikube start --driver=docker

# Install jetstack/cert-manager dependency
.PHONY: cert-manager
cert-manager:
helm repo add jetstack https://charts.jetstack.io --force-update
helm upgrade --install cert-manager jetstack/cert-manager --namespace cert-manager --create-namespace --version v1.14.5 --set installCRDs=true
sleep 1
kubectl wait --for=condition=Ready -n cert-manager --all pods --timeout=60s
helm repo update

# Install official k8s-agents-operator repo
.PHONY: operator
operator: cert-manager license_key_secret
operator:
helm uninstall k8s-agents-operator --ignore-not-found
helm repo add k8s-agents-operator https://newrelic.github.io/k8s-agents-operator
helm upgrade --install k8s-agents-operator k8s-agents-operator/k8s-agents-operator \
--create-namespace \
--namespace=k8s-agents-operator \
--set=licenseKey=${NEW_RELIC_LICENSE_KEY} \
--set=controllerManager.manager.image.tag=edge
sleep 1
kubectl wait --for=condition=Ready -n k8s-agents-operator --all pods
sleep 5
kubectl wait --for=condition=Ready pods $$(kubectl get pods | grep k8s-agents-operator | cut -d" " -f1)

# Build and install local copy of k8s-agents-operator
.PHONY: operator-local
operator-local: license_key_secret
operator-local:
eval $$(minikube docker-env --shell=bash) && \
docker build ${LOCAL_OPERATOR_REPO_PATH}/ -t e2e/k8s-agents-operator:e2e
helm uninstall k8s-agents-operator --ignore-not-found
sleep 1
helm upgrade --install k8s-agents-operator ${LOCAL_OPERATOR_REPO_PATH}/charts/k8s-agents-operator/ \
--create-namespace \
--namespace=k8s-agents-operator \
--set=licenseKey=${NEW_RELIC_LICENSE_KEY} \
--set=newRelicHost=${NEW_RELIC_HOST} \
--set=controllerManager.manager.image.pullPolicy=Never \
--set=controllerManager.manager.image.repository=e2e/k8s-agents-operator \
--set=controllerManager.manager.image.tag=e2e
sleep 1
kubectl wait --for=condition=Ready -n k8s-agents-operator --all pods
sleep 5
kubectl wait --for=condition=Ready pods $$(kubectl get pods | grep k8s-agents-operator | cut -d" " -f1)

# Set license key in default namespace
.PHONY: license_key_secret
license_key_secret:
kubectl delete secret newrelic-key-secret --ignore-not-found
kubectl create secret generic newrelic-key-secret \
--from-literal="new_relic_license_key=${NEW_RELIC_LICENSE_KEY}" \
-n default
--from-literal="new_relic_license_key=${NEW_RELIC_LICENSE_KEY}"

# Build local initcontainer image
.PHONY: build-initcontainer
Expand Down Expand Up @@ -100,9 +89,9 @@ logs-testapp:
kubectl logs $$(kubectl get pods -n default | grep test-app- | cut -d" " -f1)

# View test app container logs
.PHONY: logs-testapp
.PHONY: logs-operator
logs-operator:
kubectl logs -n k8s-agents-operator $$(kubectl get pods -n k8s-agents-operator | grep k8s-agents-operator | cut -d" " -f1)
kubectl logs $$(kubectl get pods | grep k8s-agents-operator | cut -d" " -f1)

.PHONY: check-language-arg
check-language-arg:
Expand Down
14 changes: 7 additions & 7 deletions tests/dotnet/chart/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,20 @@ spec:
metadata:
labels:
app: test-app-dotnet
annotations:
instrumentation.newrelic.com/inject-dotnet: "true"
app.newrelic.instrumentation: newrelic-dotnet-agent
spec:
containers:
- name: test-app-dotnet
image: e2e/test-app-dotnet:e2e
imagePullPolicy: Never
ports:
- containerPort: 80
- containerPort: {{ .Values.exposedPort }}
env:
- name: NEW_RELIC_APP_NAME
value: k8s-e2e-test-app-dotnet
# used by the e2e Github action
# labels used by the e2e Github action
- name: NEW_RELIC_LABELS
value: 'testKey:{{ .Values.scenarioTag | default "NOTSET" }}'
value: "testKey:{{ .Values.scenarioTag | default "NOTSET" }}"
# for testing, comment out if not needed
- name: NEWRELIC_LOG_LEVEL
value: finest
Expand All @@ -40,8 +39,9 @@ kind: Service
metadata:
name: test-app-dotnet-service
spec:
type: LoadBalancer
type: NodePort
ports:
- port: 80
- port: {{ .Values.exposedPort }}
targetPort: {{ .Values.exposedPort }}
selector:
app: test-app-dotnet
16 changes: 9 additions & 7 deletions tests/dotnet/chart/templates/instrumentation.yaml
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
---
apiVersion: newrelic.com/v1alpha1
apiVersion: newrelic.com/v1alpha2
kind: Instrumentation
metadata:
labels:
app.kubernetes.io/name: instrumentation
app.kubernetes.io/created-by: newrelic-agent-operator
name: newrelic-instrumentation
name: newrelic-instrumentation-dotnet
spec:
dotnet:
podLabelSelector:
matchExpressions:
- key: "app.newrelic.instrumentation"
operator: "In"
values: ["newrelic-dotnet-agent"]
agent:
language: dotnet
image: e2e/newrelic-dotnet-init:e2e

3 changes: 2 additions & 1 deletion tests/dotnet/chart/values.yaml
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
scenarioTag: ""
newRelicHost: ""
newRelicHost: ""
exposedPort: 80
2 changes: 1 addition & 1 deletion tests/java/chart/.helmignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@
.project
.idea/
*.tmproj
.vscode/
.vscode/
12 changes: 6 additions & 6 deletions tests/java/chart/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,19 @@ spec:
metadata:
labels:
app: test-app-java
annotations:
instrumentation.newrelic.com/inject-java: "true"
app.newrelic.instrumentation: newrelic-java-agent
spec:
containers:
- name: test-app-java
image: e2e/test-app-java:e2e
imagePullPolicy: Never
ports:
- containerPort: 8080
- containerPort: {{ .Values.exposedPort }}
env:
- name: NEW_RELIC_APP_NAME
value: k8s-e2e-test-app-java
- name: NEW_RELIC_LABELS # labels used by the e2e Github action
# labels used by the e2e Github action
- name: NEW_RELIC_LABELS
value: "testKey:{{ .Values.scenarioTag | default "NOTSET" }}"
- name: NEW_RELIC_SYNC_STARTUP
value: "true"
Expand All @@ -47,7 +47,7 @@ metadata:
spec:
type: NodePort
ports:
- port: 8080
targetPort: 8080
- port: {{ .Values.exposedPort }}
targetPort: {{ .Values.exposedPort }}
selector:
app: test-app-java
15 changes: 9 additions & 6 deletions tests/java/chart/templates/instrumentation.yaml
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
---
apiVersion: newrelic.com/v1alpha1
apiVersion: newrelic.com/v1alpha2
kind: Instrumentation
metadata:
labels:
app.kubernetes.io/name: instrumentation
app.kubernetes.io/created-by: newrelic-agent-operator
name: newrelic-instrumentation
name: newrelic-instrumentation-java
spec:
java:
podLabelSelector:
matchExpressions:
- key: "app.newrelic.instrumentation"
operator: "In"
values: ["newrelic-java-agent"]
agent:
language: java
image: e2e/newrelic-java-init:e2e
3 changes: 2 additions & 1 deletion tests/java/chart/values.yaml
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
scenarioTag: ""
scenarioTag: ""
exposedPort: 8080
11 changes: 5 additions & 6 deletions tests/nodejs/chart/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,18 @@ spec:
metadata:
labels:
app: test-app-nodejs
annotations:
instrumentation.newrelic.com/inject-nodejs: "true"
app.newrelic.instrumentation: newrelic-nodejs-agent
spec:
containers:
- name: test-app-nodejs
image: e2e/test-app-nodejs:e2e
imagePullPolicy: Never
ports:
- containerPort: 8000
- containerPort: {{ .Values.exposedPort }}
env:
- name: NEW_RELIC_APP_NAME
value: k8s-e2e-test-app-nodejs
# labels used by the e2e Github action
- name: NEW_RELIC_LABELS
value: "testKey:{{ .Values.scenarioTag | default "NOTSET" }}"
---
Expand All @@ -34,8 +34,7 @@ metadata:
spec:
type: NodePort
ports:
- name: external
port: 8000
targetPort: 8000
- port: {{ .Values.exposedPort }}
targetPort: {{ .Values.exposedPort }}
selector:
app: test-app-nodejs
15 changes: 9 additions & 6 deletions tests/nodejs/chart/templates/instrumentation.yaml
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
---
apiVersion: newrelic.com/v1alpha1
apiVersion: newrelic.com/v1alpha2
kind: Instrumentation
metadata:
labels:
app.kubernetes.io/name: instrumentation
app.kubernetes.io/created-by: newrelic-agent-operator
name: newrelic-instrumentation
name: newrelic-instrumentation-nodejs
spec:
nodejs:
podLabelSelector:
matchExpressions:
- key: "app.newrelic.instrumentation"
operator: "In"
values: ["newrelic-nodejs-agent"]
agent:
language: nodejs
image: e2e/newrelic-nodejs-init:e2e
# Configure agent for testing using environment variables
env:
Expand Down
3 changes: 2 additions & 1 deletion tests/nodejs/chart/values.yaml
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
scenarioTag: ""
scenarioTag: ""
exposedPort: 8000
9 changes: 5 additions & 4 deletions tests/php/chart/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,20 @@ spec:
metadata:
labels:
app: test-app-php
app.newrelic.instrumentation: newrelic-php-agent
annotations:
instrumentation.newrelic.com/inject-php: "true"
instrumentation.newrelic.com/php-version: "{{ .Values.phpVersion }}"
spec:
containers:
- name: test-app-php
image: e2e/test-app-php:e2e
imagePullPolicy: Never
ports:
- containerPort: 8000
- containerPort: {{ .Values.exposedPort }}
env:
- name: NEW_RELIC_APPNAME
value: k8s-e2e-test-app-php
# labels used by the e2e Github action
- name: NEW_RELIC_LABELS
value: "testKey:{{ .Values.scenarioTag | default "NOTSET" }}"
---
Expand All @@ -35,7 +36,7 @@ metadata:
spec:
type: NodePort
ports:
- port: 8000
targetPort: 8000
- port: {{ .Values.exposedPort }}
targetPort: {{ .Values.exposedPort }}
selector:
app: test-app-php
15 changes: 9 additions & 6 deletions tests/php/chart/templates/instrumentation.yaml
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
---
apiVersion: newrelic.com/v1alpha1
apiVersion: newrelic.com/v1alpha2
kind: Instrumentation
metadata:
labels:
app.kubernetes.io/name: instrumentation
app.kubernetes.io/created-by: newrelic-agent-operator
name: newrelic-instrumentation
name: newrelic-instrumentation-php
spec:
php:
podLabelSelector:
matchExpressions:
- key: "app.newrelic.instrumentation"
operator: "In"
values: ["newrelic-php-agent"]
agent:
language: php
image: e2e/newrelic-php-init:e2e
1 change: 1 addition & 0 deletions tests/php/chart/values.yaml
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
scenarioTag: ""
phpVersion: ""
exposedPort: 8000
2 changes: 2 additions & 0 deletions tests/php/test-specs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ scenarios:
- sleep 5
- kubectl wait --for=condition=Ready -n default --all pods --timeout=2m
- curl --fail-with-body $(minikube service test-app-php-service --url -n default)
- sleep 5
- curl --fail-with-body $(minikube service test-app-php-service --url -n default)
- sleep 5
- curl --fail-with-body $(minikube service test-app-php-service --url -n default)
tests:
nrqls:
Expand Down
2 changes: 1 addition & 1 deletion tests/python/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ARG RUNTIME_VERSION=3.7
ARG RUNTIME_VERSION=3.11
FROM python:$RUNTIME_VERSION

# Install dependencies
Expand Down
Loading

0 comments on commit 3cc7b64

Please sign in to comment.