From 9d77bb3b7021742cf9aa80398ee2f51e1eeea9a9 Mon Sep 17 00:00:00 2001 From: Steven Sheehy Date: Thu, 11 Apr 2019 22:33:31 -0500 Subject: [PATCH 1/3] Helm chart integration testing Signed-off-by: Steven Sheehy --- .circleci/config.yml | 36 ++++++++++++++++ .../templates/tests/loki-test-configmap.yaml | 42 +++++++++++++++++++ .../templates/tests/loki-test-pod.yaml | 30 +++++++++++++ production/helm/loki/values.yaml | 4 +- production/helm/promtail/values.yaml | 9 ++-- 5 files changed, 114 insertions(+), 7 deletions(-) create mode 100644 production/helm/loki-stack/templates/tests/loki-test-configmap.yaml create mode 100644 production/helm/loki-stack/templates/tests/loki-test-pod.yaml diff --git a/.circleci/config.yml b/.circleci/config.yml index 234f3aaa3fcb..72c80bec1c7c 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -5,11 +5,13 @@ workflows: test-build-deploy: jobs: - test + - test-helm - build - lint - publish: requires: - test + - test-helm - build - lint filters: @@ -18,6 +20,7 @@ workflows: - publish-master: requires: - test + - test-helm - build - lint filters: @@ -26,6 +29,7 @@ workflows: - publish-helm: requires: - test + - test-helm - build - lint filters: @@ -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 --validate-maintainers=false + ct install --build-id=${CIRCLE_BUILD_NUM} --charts production/helm/loki-stack --upgrade + publish-helm: <<: *defaults steps: diff --git a/production/helm/loki-stack/templates/tests/loki-test-configmap.yaml b/production/helm/loki-stack/templates/tests/loki-test-configmap.yaml new file mode 100644 index 000000000000..205fd774c795 --- /dev/null +++ b/production/helm/loki-stack/templates/tests/loki-test-configmap.yaml @@ -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"' + } + diff --git a/production/helm/loki-stack/templates/tests/loki-test-pod.yaml b/production/helm/loki-stack/templates/tests/loki-test-pod.yaml new file mode 100644 index 000000000000..a153a05df929 --- /dev/null +++ b/production/helm/loki-stack/templates/tests/loki-test-pod.yaml @@ -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 diff --git a/production/helm/loki/values.yaml b/production/helm/loki/values.yaml index 7ac6129ae690..c6725a5f8b9b 100644 --- a/production/helm/loki/values.yaml +++ b/production/helm/loki/values.yaml @@ -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 diff --git a/production/helm/promtail/values.yaml b/production/helm/promtail/values.yaml index 9848bf364031..ae75dfccaba9 100644 --- a/production/helm/promtail/values.yaml +++ b/production/helm/promtail/values.yaml @@ -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 @@ -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 @@ -127,4 +127,3 @@ config: target_config: # Period to resync directories being watched and files being tailed sync_period: 10s - From 22ff505bc066179175a4cb45a497f7d28c2dad21 Mon Sep 17 00:00:00 2001 From: Steven Sheehy Date: Wed, 12 Jun 2019 13:15:15 -0500 Subject: [PATCH 2/3] Don't check helm version on every push Signed-off-by: Steven Sheehy --- .circleci/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 72c80bec1c7c..d1a4e16349f7 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -181,7 +181,7 @@ jobs: - run: name: Run Chart Tests command: | - ct lint --chart-dirs=production/helm --validate-maintainers=false + 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 --upgrade publish-helm: From ae798934180de4e75eb79cdb4fff54a16078f441 Mon Sep 17 00:00:00 2001 From: Steven Sheehy Date: Wed, 12 Jun 2019 14:12:52 -0500 Subject: [PATCH 3/3] Remove chart upgrade testing Signed-off-by: Steven Sheehy --- .circleci/config.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index d1a4e16349f7..63e9dcd55dae 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -182,7 +182,7 @@ jobs: 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 --upgrade + ct install --build-id=${CIRCLE_BUILD_NUM} --charts production/helm/loki-stack publish-helm: <<: *defaults @@ -223,4 +223,4 @@ jobs: name: "Release" command: | docker login -u "$DOCKER_USER" -p "$DOCKER_PASS" && - make VERSION=${CIRCLE_TAG} release-perform \ No newline at end of file + make VERSION=${CIRCLE_TAG} release-perform