Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Helm: Integration testing #641

Merged
merged 3 commits into from
Jun 12, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 37 additions & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@ workflows:
test-build-deploy:
jobs:
- test
- test-helm
- build
- lint
- publish:
requires:
- test
- test-helm
- build
- lint
filters:
Expand All @@ -18,6 +20,7 @@ workflows:
- publish-master:
requires:
- test
- test-helm
- build
- lint
filters:
Expand All @@ -26,6 +29,7 @@ workflows:
- publish-helm:
requires:
- test
- test-helm
- build
- lint
filters:
Expand Down Expand Up @@ -148,6 +152,38 @@ jobs:
docker login -u "$DOCKER_USER" -p "$DOCKER_PASS" &&
make push-latest

test-helm:
environment:
CT_VERSION: 2.3.3
machine:
image: ubuntu-1604:201903-01
steps:
- checkout
- run:
name: Install k3s
command: |
curl -sfL https://get.k3s.io | sh -
mkdir -p ~/.kube
cp /etc/rancher/k3s/k3s.yaml ~/.kube/config
- run:
name: Install Helm
command: |
curl -L https://git.io/get_helm.sh | bash
kubectl apply -f tools/helm.yaml
helm init --service-account helm --wait
- run:
name: Install Chart Testing tool
command: |
pip install yamale yamllint
curl -Lo ct.tgz https://github.com/helm/chart-testing/releases/download/v${CT_VERSION}/chart-testing_${CT_VERSION}_linux_amd64.tar.gz
sudo tar -C /usr/local/bin -xvf ct.tgz
sudo mv /usr/local/bin/etc /etc/ct/
- run:
name: Run Chart Tests
command: |
ct lint --chart-dirs=production/helm --check-version-increment=false --validate-maintainers=false
ct install --build-id=${CIRCLE_BUILD_NUM} --charts production/helm/loki-stack

publish-helm:
<<: *defaults
steps:
Expand Down Expand Up @@ -187,4 +223,4 @@ jobs:
name: "Release"
command: |
docker login -u "$DOCKER_USER" -p "$DOCKER_PASS" &&
make VERSION=${CIRCLE_TAG} release-perform
make VERSION=${CIRCLE_TAG} release-perform
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ template "loki-stack.fullname" . }}-test
labels:
app: {{ template "loki-stack.name" . }}
chart: {{ template "loki-stack.chart" . }}
release: {{ .Release.Name }}
heritage: {{ .Release.Service }}
data:
test.sh: |
#!/usr/bin/env bash

LOKI_URI="http://${LOKI_SERVICE}:${LOKI_PORT}"

function setup() {
apk add -u curl jq
until (curl -s ${LOKI_URI}/api/prom/label/app/values | jq -e '.values[] | select(. == "loki")'); do
sleep 1
done
}

@test "Has labels" {
curl -s ${LOKI_URI}/api/prom/label | \
jq -e '.values[] | select(. == "app")'
}

@test "Query log entry" {
curl -sG ${LOKI_URI}/api/prom/query?limit=10 --data-urlencode 'query={app="loki"}' | \
jq -e '.streams[].entries | length >= 1'
}

@test "Push log entry" {
local timestamp=$(date -Iseconds -u | sed 's/UTC/.000000000+00:00/')
local data=$(jq -n --arg timestamp "${timestamp}" '{"streams": [{"labels": "{app=\"loki-test\"}", "entries": [{"ts": $timestamp, "line": "foobar"}]}]}')

curl -s -X POST -H "Content-Type: application/json" ${LOKI_URI}/api/prom/push -d "${data}"

curl -sG ${LOKI_URI}/api/prom/query?limit=1 --data-urlencode 'query={app="loki-test"}' | \
jq -e '.streams[].entries[].line == "foobar"'
}

30 changes: 30 additions & 0 deletions production/helm/loki-stack/templates/tests/loki-test-pod.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
apiVersion: v1
kind: Pod
metadata:
annotations:
"helm.sh/hook": test-success
labels:
app: {{ template "loki-stack.name" . }}
chart: {{ template "loki-stack.chart" . }}
release: {{ .Release.Name }}
heritage: {{ .Release.Service }}
name: {{ template "loki-stack.fullname" . }}-test
spec:
containers:
- name: test
image: bats/bats:v1.1.0
args:
- /var/lib/loki/test.sh
env:
- name: LOKI_SERVICE
value: {{ template "loki.serviceName" . }}
- name: LOKI_PORT
value: "{{ .Values.loki.service.port }}"
volumeMounts:
- name: tests
mountPath: /var/lib/loki
restartPolicy: Never
volumes:
- name: tests
configMap:
name: {{ template "loki-stack.fullname" . }}-test
4 changes: 2 additions & 2 deletions production/helm/loki/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@ podLabels: {}

## Pod Annotations
podAnnotations:
prometheus.io/scrape: "true"
prometheus.io/port: "http-metrics"
prometheus.io/scrape: "true"
prometheus.io/port: "http-metrics"

podManagementPolicy: OrderedReady

Expand Down
9 changes: 4 additions & 5 deletions production/helm/promtail/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ image:
livenessProbe: {}

loki:
serviceName: "" # Defaults to "${RELEASE}-loki" if not set
serviceName: "" # Defaults to "${RELEASE}-loki" if not set
servicePort: 3100
serviceScheme: http
# user: user
Expand All @@ -32,9 +32,9 @@ pipelineStages:
## Pod Labels
podLabels: {}

podAnnotations:
prometheus.io/scrape: "true"
prometheus.io/port: "http-metrics"
podAnnotations:
prometheus.io/scrape: "true"
prometheus.io/port: "http-metrics"

# This should match config.server.http_listen_port
port: 3101
Expand Down Expand Up @@ -127,4 +127,3 @@ config:
target_config:
# Period to resync directories being watched and files being tailed
sync_period: 10s