Skip to content

Commit

Permalink
[helm] Add a loki canary test to the helm chart (#7229)
Browse files Browse the repository at this point in the history
**What this PR does / why we need it**:

Add a helm chart test that utilizes the Loki canary to confirm the Loki
cluster is functioning correctly.

**Which issue(s) this PR fixes**:
Fixes #7228

Co-authored-by: Karsten Jeschkies <[email protected]>
  • Loading branch information
trevorwhitney and jeschkies authored Oct 25, 2022
1 parent 9bc6e85 commit 6c53113
Show file tree
Hide file tree
Showing 25 changed files with 515 additions and 99 deletions.
30 changes: 30 additions & 0 deletions .drone/drone.jsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,36 @@ local manifest_ecr(apps, archs) = pipeline('manifest-ecr') {
},
],
},
pipeline('helm-test-image') {
workspace: {
base: '/src',
path: 'loki',
},
steps: [
{
name: 'test-image',
image: 'plugins/docker',
when: onPRs + onPath('production/helm/loki/src/helm-test/**'),
settings: {
repo: 'grafana/loki-helm-test',
dockerfile: 'production/helm/loki/src/helm-test/Dockerfile',
dry_run: true,
},
},
{
name: 'push-image',
image: 'plugins/docker',
when: onTagOrMain + onPath('production/helm/loki/src/helm-test/**'),
settings: {
repo: 'grafana/loki-helm-test',
dockerfile: 'production/helm/loki/src/helm-test/Dockerfile',
username: { from_secret: docker_username_secret.name },
password: { from_secret: docker_password_secret.name },
dry_run: false,
},
},
],
},
pipeline('check') {
workspace: {
base: '/src',
Expand Down
45 changes: 40 additions & 5 deletions .drone/drone.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,46 @@ workspace:
path: loki
---
kind: pipeline
name: helm-test-image
steps:
- image: plugins/docker
name: test-image
settings:
dockerfile: production/helm/loki/src/helm-test/Dockerfile
dry_run: true
repo: grafana/loki-helm-test
when:
event:
- pull_request
paths:
- production/helm/loki/src/helm-test/**
- image: plugins/docker
name: push-image
settings:
dockerfile: production/helm/loki/src/helm-test/Dockerfile
dry_run: false
password:
from_secret: docker_password
repo: grafana/loki-helm-test
username:
from_secret: docker_username
when:
event:
- push
- tag
paths:
- production/helm/loki/src/helm-test/**
trigger:
ref:
- refs/heads/main
- refs/heads/k???
- refs/tags/v*
- refs/pull/*/head
workspace:
base: /src
path: loki
---
kind: pipeline
name: check
steps:
- commands:
Expand Down Expand Up @@ -1535,8 +1575,3 @@ get:
path: infra/data/ci/packages-publish/gpg
kind: secret
name: gpg_private_key
---
kind: signature
hmac: 8738700b68f651859a25c2c9bd9f70efb8092aa1eca2ad35238a85ec19f9fe31

...
101 changes: 90 additions & 11 deletions .github/workflows/helm-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,96 @@ name: helm-ci
on:
pull_request:
paths:
- 'production/helm/**'
- "production/helm/**"

env:
CT_CONFIGFILE: production/helm/ct.yaml

jobs:
call-lint:
uses: grafana/helm-charts/.github/workflows/linter.yml@main
with:
filter_regex_include: .*production/helm/.*

call-lint-test:
uses: grafana/helm-charts/.github/workflows/lint-test.yaml@main
with:
ct_configfile: production/helm/ct.yaml
ct_check_version_increment: false
helm_version: v3.8.2
name: Lint Helm Chart
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@v2

- name: Check Docs
run: |
docker run --rm --volume "$(pwd):/helm-docs" -u "$(id -u)" jnorwood/helm-docs:v1.8.1
if ! git diff --exit-code; then
echo "Documentation not up to date. Please run helm-docs and commit changes!" >&2
exit 1
fi
- name: Lint Code Base
uses: docker://github/super-linter:v3.12.0
env:
FILTER_REGEX_EXCLUDE: .*(README\.md|Chart\.yaml|NOTES.txt).*
FILTER_REGEX_INCLUDE: .*production/helm/.*
VALIDATE_ALL_CODEBASE: false
VALIDATE_KUBERNETES_KUBEVAL: false
VALIDATE_YAML: false
VALIDATE_GO: false
DEFAULT_BRANCH: main
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
call-test:
name: Test Helm Chart
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 0

- name: Set up Helm
uses: azure/setup-helm@v1
with:
version: v3.8.2

# Python is required because `ct lint` runs Yamale (https://github.com/23andMe/Yamale) and
# yamllint (https://github.com/adrienverge/yamllint) which require Python
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: 3.7

- name: Set up chart-testing
uses: helm/[email protected]

- name: Run chart-testing (list-changed)
id: list-changed
run: |
changed=$(ct list-changed --config "${CT_CONFIGFILE}")
if [[ -n "$changed" ]]; then
echo "::set-output name=changed::true"
fi
- name: Run chart-testing (lint)
run: ct lint --config "${CT_CONFIGFILE}" --check-version-increment=false

- name: Create kind cluster
uses: helm/[email protected]
if: steps.list-changed.outputs.changed == 'true'

- name: Install prometheus operator
id: install-prometheus
if: steps.list-changed.outputs.changed == 'true'
run: |
kubectl create namespace prometheus
helm install prometheus prometheus-community/kube-prometheus-stack \
--namespace prometheus \
--set grafana.enabled=false \
--set prometheus.prometheusSpec.serviceMonitorSelector.matchLabels.release=prometheus
kubectl --namespace prometheus get pods -l "release=prometheus"
kubectl --namespace prometheus get services -l "release=prometheus"
- name: Run chart-testing (install)
run: |
changed=$(ct list-changed --config "${CT_CONFIGFILE}")
if [[ "$changed" == "charts/enterprise-metrics" ]]; then
# Do not run `ct install` for enterprise-metrics
exit 0
fi
ct install --config "${CT_CONFIGFILE}"
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ cmd/loki/loki-debug
clients/cmd/promtail/promtail-debug
clients/cmd/docker-driver/docker-driver
cmd/loki-canary/loki-canary
cmd/loki-canary-test/loki-canary-test
clients/cmd/fluent-bit/out_grafana_loki.so
clients/cmd/fluent-bit/out_grafana_loki.h
cmd/migrate/migrate
Expand Down
16 changes: 15 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,16 @@ loki-canary: cmd/loki-canary/loki-canary
cmd/loki-canary/loki-canary:
CGO_ENABLED=0 go build $(GO_FLAGS) -o $@ ./$(@D)

###############
# Helm-Test #
###############
.PHONY: production/helm/loki/src/helm-test/helm-test
helm-test: production/helm/loki/src/helm-test/helm-test

# Package Helm tests but do not run them.
production/helm/loki/src/helm-test/helm-test:
CGO_ENABLED=0 go test $(GO_FLAGS) --tags=helm_test -c -o $@ ./$(@D)

#################
# Loki-QueryTee #
#################
Expand Down Expand Up @@ -485,7 +495,7 @@ push-bigtable-backup: bigtable-backup
# Images #
##########

images: promtail-image loki-image loki-canary-image docker-driver fluent-bit-image fluentd-image
images: promtail-image loki-image loki-canary-image helm-test-image docker-driver fluent-bit-image fluentd-image

# push(app, optional tag)
# pushes the app, optionally tagging it differently before
Expand Down Expand Up @@ -534,6 +544,10 @@ loki-canary-image-cross:
$(SUDO) $(BUILD_OCI) -t $(IMAGE_PREFIX)/loki-canary:$(IMAGE_TAG) -f cmd/loki-canary/Dockerfile.cross .
loki-canary-push: loki-canary-image-cross
$(SUDO) $(PUSH_OCI) $(IMAGE_PREFIX)/loki-canary:$(IMAGE_TAG)
helm-test-image:
$(SUDO) docker build -t $(IMAGE_PREFIX)/loki-helm-test:$(IMAGE_TAG) -f production/helm/loki/src/helm-test/Dockerfile .
helm-test-push: helm-test-image
$(SUDO) $(PUSH_OCI) $(IMAGE_PREFIX)/loki-helm-test:$(IMAGE_TAG)

# loki-querytee
loki-querytee-image:
Expand Down
21 changes: 15 additions & 6 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -79,18 +79,23 @@
config = { allowUnfree = true; };
};
in
with pkgs; {
{
# The default package for 'nix build'. This makes sense if the
# flake provides only one package or there is a clear "main"
# package.
defaultPackage = loki;
defaultPackage = pkgs.loki;

packages = { inherit loki; };
packages = with pkgs; {
inherit
loki
loki-helm-test
loki-helm-test-docker;
};

apps = {
lint = {
type = "app";
program = "${
program = with pkgs; "${
(writeShellScriptBin "lint.sh" ''
${nixpkgs-fmt}/bin/nixpkgs-fmt --check ${self}/flake.nix ${self}/nix/*.nix
${statix}/bin/statix check ${self}
Expand All @@ -114,10 +119,14 @@
type = "app";
program = with pkgs; "${loki.overrideAttrs(old: rec { doCheck = false; })}/bin/loki-canary";
};
loki-helm-test = {
type = "app";
program = with pkgs; "${loki-helm-test}/bin/helm-test";
};
};

devShell = mkShell {
nativeBuildInputs = [
devShell = pkgs.mkShell {
nativeBuildInputs = with pkgs; [
gcc
go
systemd
Expand Down
72 changes: 40 additions & 32 deletions nix/default.nix
Original file line number Diff line number Diff line change
@@ -1,45 +1,53 @@
{ self, nixpkgs, system }:
let buildVars = import ./build-vars.nix;
in {
overlay = final: prev: rec {
loki =
let
# self.rev is only set on a clean git tree
gitRevision = if (self ? rev) then self.rev else "dirty";
shortGitRevsion = with prev.lib;
if (self ? rev) then
(strings.concatStrings
(lists.take 8 (strings.stringToCharacters gitRevision)))
else
"dirty";
in
{
overlay = final: prev:
let
# self.rev is only set on a clean git tree
gitRevision = if (self ? rev) then self.rev else "dirty";
shortGitRevsion = with prev.lib;
if (self ? rev) then
(strings.concatStrings
(lists.take 8 (strings.stringToCharacters gitRevision)))
else
"dirty";

# the image tag script is hard coded to take only 7 characters
imageTagVersion = with prev.lib;
if (self ? rev) then
(strings.concatStrings
(lists.take 8 (strings.stringToCharacters gitRevision)))
else
"dirty";
# the image tag script is hard coded to take only 7 characters
imageTagVersion = with prev.lib;
if (self ? rev) then
(strings.concatStrings
(lists.take 8 (strings.stringToCharacters gitRevision)))
else
"dirty";

imageTag =
if (self ? rev) then
"${buildVars.gitBranch}-${imageTagVersion}"
else
"${buildVars.gitBranch}-${imageTagVersion}-WIP";
in
prev.callPackage ./loki.nix {
imageTag =
if (self ? rev) then
"${buildVars.gitBranch}-${imageTagVersion}"
else
"${buildVars.gitBranch}-${imageTagVersion}-WIP";

loki-helm-test = prev.callPackage ../production/helm/loki/src/helm-test {
inherit (prev) pkgs lib buildGoModule dockerTools;
rev = gitRevision;
};
in
{
inherit (loki-helm-test) loki-helm-test loki-helm-test-docker;

loki = prev.callPackage ./loki.nix {
inherit imageTag;
inherit (buildVars) gitBranch;
version = shortGitRevsion;
pkgs = prev;
};

faillint = prev.callPackage ./faillint.nix {
inherit (prev) lib buildGoModule fetchFromGitHub;
};
faillint = prev.callPackage ./faillint.nix {
inherit (prev) lib buildGoModule fetchFromGitHub;
};

chart-releaser = prev.callPackage ./chart-releaser.nix {
inherit (prev) pkgs lib buildGoModule fetchFromGitHub;
chart-releaser = prev.callPackage ./chart-releaser.nix {
inherit (prev) pkgs lib buildGoModule fetchFromGitHub;
};
};
};
}
1 change: 1 addition & 0 deletions production/helm/ct.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ chart-dirs:
chart-repos:
- grafana=https://grafana.github.io/helm-charts
- minio=https://charts.min.io
- prometheus-community=https://prometheus-community.github.io/helm-charts
helm-extra-args: --timeout 600s
check-version-increment: false
validate-maintainers: false
2 changes: 1 addition & 1 deletion production/helm/loki/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ name: loki
description: Helm chart for Grafana Loki in simple, scalable mode
type: application
appVersion: 2.6.1
version: 3.2.2
version: 3.3.0
home: https://grafana.github.io/helm-charts
sources:
- https://github.com/grafana/loki
Expand Down
Loading

0 comments on commit 6c53113

Please sign in to comment.