Skip to content

Commit

Permalink
feat: run integration tests (#73)
Browse files Browse the repository at this point in the history
* feat: run integration tests

* fix: clean up values.yaml

* fix: default chart version

* fix: argocd sync settings

* fix: name too long

* fix: name too long

* fix: wait for...

* fix: integration tests container

* fix: image pull secrets

* fix: EXAMPLE_HASURA_PROJECTIONS_URL

* fix: ENABLE_EVENT_PUBLISHING & ENABLE_SYNC_SEND_TO_DENORMALIZER false for preview

* fix: 202

* fix: full integration

* fix: full integration - broker url

* fix: status check - 200

* fix: status check - 200

* fix: promote integration tests for releases as well
  • Loading branch information
patrickleet authored Nov 6, 2022
1 parent 6b5132a commit 5e597bb
Show file tree
Hide file tree
Showing 11 changed files with 51 additions and 92 deletions.
12 changes: 12 additions & 0 deletions .github/workflows/pr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,18 @@ jobs:
cache-from: type=registry,ref=ghcr.io/${{ env.REPO }}:buildcache
cache-to: type=registry,ref=ghcr.io/${{ env.REPO }}:buildcache,mode=max

- name: Build and push integration tests docker image
uses: docker/build-push-action@v3
with:
context: .
file: ./jest.integration.Dockerfile
push: true
tags: |
ghcr.io/${{ env.REPO }}-integration-tests:pr-${{ github.event.pull_request.number }}-${{ github.sha }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=registry,ref=ghcr.io/${{ env.REPO }}-integration-tests:buildcache
cache-to: type=registry,ref=ghcr.io/${{ env.REPO }}-integration-tests:buildcache,mode=max

- name: Setup Helm
uses: azure/setup-helm@v3

Expand Down
12 changes: 12 additions & 0 deletions .github/workflows/publish-and-promote.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,18 @@ jobs:
cache-from: type=registry,ref=ghcr.io/${{ env.REPO }}:buildcache
cache-to: type=registry,ref=ghcr.io/${{ env.REPO }}:buildcache,mode=max

- name: Build and push integration tests docker image
uses: docker/build-push-action@v3
with:
context: .
file: ./jest.integration.Dockerfile
push: true
tags: |
ghcr.io/${{ env.REPO }}-integration-tests:${{ github.ref_name }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=registry,ref=ghcr.io/${{ env.REPO }}-integration-tests:buildcache
cache-to: type=registry,ref=ghcr.io/${{ env.REPO }}-integration-tests:buildcache,mode=max

promote:
needs: publish
runs-on: ubuntu-latest
Expand Down
4 changes: 2 additions & 2 deletions __tests__/integration/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ describe("todo model integration tests", () => {
}
);

expect(initializeTodoResponse.status).toBe(201);
expect(initializeTodoResponse.status).toBe(200);
expect(initializeTodoResponse.data.id).toBeDefined();
expect(initializeTodoResponse.data.todo).toBe("integration tests");

Expand All @@ -123,6 +123,6 @@ describe("todo model integration tests", () => {
}
);

expect(completeTodoResponse.status).toBe(201);
expect(completeTodoResponse.status).toBe(200);
});
});
2 changes: 1 addition & 1 deletion helm/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ apiVersion: v1
description: A Helm chart for Kubernetes
icon: https://raw.githubusercontent.com/jenkins-x/jenkins-x-platform/d273e09/images/nodejs.png
name: example-todo-model-service
version: 0.1.0-SNAPSHOT
version: 0.0.0-dev
4 changes: 4 additions & 0 deletions helm/templates/integration-tests-role.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
{{- if .Values.local }}
{{- else }}
{{- if .Values.runIntegrationTests }}
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
name: {{ .Values.service.name }}-integration-tests
annotations:
argocd.argoproj.io/sync-wave: "-1"
rules:
- apiGroups:
- ""
Expand All @@ -26,4 +29,5 @@ rules:
- get
- list
- watch
{{- end }}
{{- end }}
4 changes: 4 additions & 0 deletions helm/templates/integration-tests-rolebinding.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
{{- if .Values.local }}
{{- else }}
{{- if .Values.runIntegrationTests }}
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: {{ .Values.service.name }}-integration-tests
annotations:
argocd.argoproj.io/sync-wave: "-1"
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: Role
Expand All @@ -12,3 +15,4 @@ subjects:
- kind: ServiceAccount
name: {{ .Values.service.name }}-integration-tests
{{- end }}
{{- end }}
8 changes: 8 additions & 0 deletions helm/templates/integration-tests-sa.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
{{- if .Values.local }}
{{- else }}
{{- if .Values.runIntegrationTests }}
apiVersion: v1
kind: ServiceAccount
metadata:
name: {{ .Values.service.name }}-integration-tests
annotations:
argocd.argoproj.io/sync-wave: "-1"
{{- if .Values.imagePullSecrets }}
imagePullSecrets:
- name: {{ .Values.imagePullSecrets }}
{{- end }}
{{- end }}
{{- end }}
11 changes: 2 additions & 9 deletions helm/templates/integration-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
apiVersion: batch/v1
kind: Job
metadata:
name: {{ .Values.service.name }}-integration-tests-{{ lower .Values.image.tag }}
name: {{ .Values.service.name }}-itest-{{ .Values.image.tag | substr 0 11 | lower }}
labels:
chart: "{{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}"
annotations:
argocd.argoproj.io/sync-wave: "2"
argocd.argoproj.io/hook: PostSync
spec:
template:
metadata:
Expand All @@ -17,13 +17,6 @@ spec:
spec:
serviceAccountName: {{ .Values.service.name }}-integration-tests
initContainers:
- name: wait-for-resources
image: bitnami/kubectl:1.24
command: [
'sh',
'-c',
"kubectl wait --for=condition=ready pod --selector=cluster-name={{ .Values.sourced.psql.name }} --timeout=600s -n {{ .Release.Namespace }}; REVISION=`kubectl get revisions -n {{ .Release.Namespace }} | grep example-hasura-0 | tail -1 | awk '$1 {print$1}-deployment'`; kubectl rollout status -n {{ .Release.Namespace }} deployment $REVISION-deployment"
]
- name: wait-for-new-revision
image: bitnami/kubectl:1.24
command: ['sh', '-c', "REVISION=`kubectl get revisions -n {{ .Release.Namespace }} | tail -1 | awk '$1 {print$1}-deployment'`; kubectl rollout status -n {{ .Release.Namespace }} deployment $REVISION-deployment"]
Expand Down
2 changes: 1 addition & 1 deletion helm/templates/ksvc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ metadata:
{{ toYaml .Values.service.labels | indent 4 }}
{{- end }}
annotations:
argocd.argoproj.io/sync-wave: "1"
argocd.argoproj.io/sync-wave: "0"
spec:
template:
metadata:
Expand Down
81 changes: 2 additions & 79 deletions helm/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,67 +8,28 @@ podAnnotations: {}
podsLabels: {}
# Add labels to the deployment
deploymentLabels: {}

image:
repository: ghcr.io/cloudnativeentrepreneur/example-todo-model-service
tag: latest
pullPolicy: IfNotPresent

# define environment variables here as a map of key: value
env:

runIntegrationTests: false
runIntegrationTests: true
# enable this flag to use knative serve to deploy the app
knativeDeploy: true
knative:
minScale: 1
maxScale: 1
concurrencyTarget: 100

local: false
localKnativeSubscriber: http://host.docker.internal:5002
localKnativeDlqSubscriber: http://host.docker.internal:3999

# HorizontalPodAutoscaler
hpa:
enabled: false
minReplicas: 2
maxReplicas: 6
cpuTargetAverageUtilization: 80
memoryTargetAverageUtilization: 80
# Add labels to the HPA
labels: {}

# Canary deployments
# If enabled, Istio and Flagger need to be installed in the cluster
canary:
enabled: false
progressDeadlineSeconds: 60
analysis:
interval: "1m"
threshold: 5
maxWeight: 60
stepWeight: 20
# WARNING: Canary deployments will fail and rollback if there is no traffic that will generate the below specified metrics.
metrics:
latency:
threshold: 500
interval: "1m"
# The host is using Istio Gateway or the underlying ingress mechanism
# This value is defaulted from the environments jx-requirements.yml ingress configuration
host: ""
# Add labels to the canary
labels: {}
# Add labels to the canary gateway
gatewayLabels: {}

service:
name: example-todo-model-service
type: ClusterIP
internalPort: 5002
externalPort: 80
annotations: {}
# Add labels to the service
labels: {}
resources:
limits:
Expand All @@ -88,47 +49,9 @@ readinessProbe:
periodSeconds: 1
successThreshold: 1
timeoutSeconds: 1

sourced:
psql:
name: example-sourced-db-postgresql
hostname: example-sourced-db-postgresql
# custom ingress annotations on this service
ingress:
annotations: {}
# defaults to nginx if no other ingress class annotation specified
classAnnotation: ""
# Add labels to the ingress
labels: {}

# ingress path type
pathType: ImplementationSpecific

serviceAccount:
enabled: true
name: ""
annotations: {}
# iam.gke.io/gcp-service-account: my-sa-in-gke
# Add labels to the SA
labels: {}
# my-custom-label: value

# values we use from the `jx-requirements.yml` file if we are using helmfile and helm 3
jxRequirements:
ingress:
# shared ingress annotations on all services
annotations: {}
# kubernetes.io/ingress.class: nginx

apiVersion: "networking.k8s.io/v1"

# the domain for hosts
domain: ""
externalDNS: false
namespaceSubDomain: -jx.
serviceType: ""
tls:
email: ""
enabled: false
production: false
secretName: ""
imagePullSecrets: ghcr
3 changes: 3 additions & 0 deletions preview/helm/templates/app.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ spec:
values: |
image:
tag: {{ .Values.tag }}
env:
EXAMPLE_HASURA_PROJECTIONS_URL: http://example-hasura-projections-service.example-prod-env.svc.cluster.local
TODO_EVENTS_BROKER_URL: "http://broker-ingress.knative-eventing.svc.cluster.local/example-prod-env/todo-events"
destination:
namespace: {{ .Values.repository.name }}-{{ .Values.pr }}-preview
server: https://kubernetes.default.svc
Expand Down

0 comments on commit 5e597bb

Please sign in to comment.