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

Feature: add Helm chart install mode #98

Merged
merged 16 commits into from
Sep 13, 2023
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
36 changes: 36 additions & 0 deletions .github/workflows/chart-test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
---
name: Chart Testing
on: [push]
jobs:
kind:
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.7.2

- uses: actions/setup-python@v2
with:
python-version: 3.7

- name: Run chart-testing (list-changed)
id: list-changed
run: |
changed=$(ct list-changed --target-branch ${{ github.ref_name }})
if [[ -n "$changed" ]]; then
echo "changed=true" >> $GITHUB_OUTPUT
fi

- name: Create kind cluster
uses: helm/kind-action@v1.2.0
if: steps.list-changed.outputs.changed == 'true'

- name: Run chart-testing (install)
if: steps.list-changed.outputs.changed == 'true'
run: ct install --target-branch ${{ github.ref_name }} --charts ./charts/
33 changes: 32 additions & 1 deletion .github/workflows/e2e-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ jobs:
GO_BUILDER_IMG=golang:1.18
tags: |
ghcr.io/grafana/k6-operator:${{ github.sha }}
kind:

kind-kustomize:
needs: ["docker"]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
Expand All @@ -55,3 +57,32 @@ jobs:
kubectl wait --for=condition=complete --timeout=180s job/k6-sample-initializer
kubectl delete configmap crocodile-stress-test
kubectl delete -f e2e/test.yaml

kind-helm:
needs: ["docker"]
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.7.2

- name: Create kind cluster
uses: helm/kind-action@v1.2.0

- name: Testing
run: |
helm install k6-operator ./charts/ -f ./charts/values.yaml --set manager.image.tag=${{github.sha}}
kubectl create configmap crocodile-stress-test --from-file e2e/test.js
kubectl apply -f e2e/test.yaml
sleep 30
kubectl get namespaces
kubectl get jobs -A
kubectl wait --for=condition=complete --timeout=180s job/k6-sample-1
kubectl delete configmap crocodile-stress-test
kubectl delete -f e2e/test.yaml
26 changes: 26 additions & 0 deletions .github/workflows/helmlint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
---
yorugac marked this conversation as resolved.
Show resolved Hide resolved
name: Helm Lint
on: [push]
jobs:
lintAllTheThings:
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.7.2

- uses: actions/setup-python@v2
with:
python-version: 3.7

- name: Set up chart-testing
uses: helm/chart-testing-action@v2.2.0

- name: Run chart-testing (lint)
run: ct lint --target-branch ${{ github.ref_name }} --charts ./charts/
3 changes: 3 additions & 0 deletions .github/workflows/yamllint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,6 @@ jobs:
- uses: actions/checkout@v1
- name: yaml-lint
uses: ibiqlik/action-yamllint@v3
with:
file_or_dir: config/**/*.yaml e2e/*.yaml
config_file: .yamllint.yaml
1 change: 1 addition & 0 deletions .yamllint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
extends: default
ignore: |
/config/crd/bases/*
/charts/*
rules:
line-length: disable
comments:
Expand Down
47 changes: 42 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ BUNDLE_METADATA_OPTS ?= $(BUNDLE_CHANNELS) $(BUNDLE_DEFAULT_CHANNEL)
# Image to use for building Go
GO_BUILDER_IMG ?= "golang:1.18"
# Image URL to use all building/pushing image targets
IMG ?= ghcr.io/grafana/k6-operator:latest
IMG_NAME ?= ghcr.io/grafana/k6-operator
IMG_TAG ?= latest
knmsk marked this conversation as resolved.
Show resolved Hide resolved
# Default dockerfile to build
DOCKERFILE ?= "Dockerfile.controller"
# Produce CRDs that work back to Kubernetes 1.11 (no version conversion)
Expand All @@ -36,6 +37,7 @@ GOOS=$(shell go env GOOS)
GOARCH=$(shell go env GOARCH)
KUBEBUILDER_ASSETS_ROOT=/tmp
KUBEBUILDER_ASSETS=$(KUBEBUILDER_ASSETS_ROOT)/kubebuilder/bin

test: generate fmt vet manifests
export KUBEBUILDER_ASSETS=$(KUBEBUILDER_ASSETS); setup-envtest use --use-env -p env $(ENVTEST_K8S_VERSION); go test ./... -coverprofile cover.out

Expand Down Expand Up @@ -77,7 +79,7 @@ uninstall: manifests kustomize

# Deploy controller in the configured Kubernetes cluster in ~/.kube/config
deploy: manifests kustomize
cd config/manager && $(KUSTOMIZE) edit set image controller=${IMG}
cd config/manager && $(KUSTOMIZE) edit set image controller=${IMG_NAME}:${IMG_TAG}
$(KUSTOMIZE) build config/default | kubectl apply -f -

# Delete operator from a cluster
Expand All @@ -102,11 +104,11 @@ generate: controller-gen

# Build the docker image
docker-build: test
docker build . -t ${IMG} -f ${DOCKERFILE} --build-arg GO_BUILDER_IMG=${GO_BUILDER_IMG}
docker build . -t ${IMG_NAME}:${IMG_TAG} -f ${DOCKERFILE} --build-arg GO_BUILDER_IMG=${GO_BUILDER_IMG}

# Push the docker image
docker-push:
docker push ${IMG}
docker push ${IMG_NAME}:${IMG_TAG}

# find or download controller-gen
# download controller-gen if necessary
Expand Down Expand Up @@ -144,11 +146,46 @@ endif
.PHONY: bundle
bundle: manifests
operator-sdk generate kustomize manifests -q
cd config/manager && $(KUSTOMIZE) edit set image controller=$(IMG)
cd config/manager && $(KUSTOMIZE) edit set image controller=${IMG_NAME}:${IMG_TAG}
$(KUSTOMIZE) build config/manifests | operator-sdk generate bundle -q --overwrite --version $(VERSION) $(BUNDLE_METADATA_OPTS)
operator-sdk bundle validate ./bundle

# Build the bundle image.
.PHONY: bundle-build
bundle-build:
docker build -f bundle.Dockerfile -t $(BUNDLE_IMG) .

# ===============================================================
# This section is only about the HELM deployment of the operator
# ===============================================================

e2e-helm: deploy-helm
kubectl create configmap crocodile-stress-test --from-file e2e/test.js
kubectl apply -f e2e/test.yaml

# Deploy controller in the configured Kubernetes cluster in ~/.kube/config
deploy-helm: manifests helm
$(HELM) upgrade --install --wait k6-operator ./charts -f ./charts/values.yaml --set manager.image.name=$(IMG_NAME) --set manager.image.tag=$(IMG_TAG)

helm-template: manifests helm
$(HELM) template k6-operator ./charts -f ./charts/values.yaml --set manager.image.name=$(IMG_NAME) --set manager.image.tag=$(IMG_TAG)

# Delete operator from a cluster
delete-helm: manifests helm
$(HELM) uninstall k6-operator

helm:
ifeq (, $(shell which helm))
@{ \
set -e ;\
HELM_GEN_TMP_DIR=$$(mktemp -d) ;\
cd $$HELM_GEN_TMP_DIR ;\
curl -fsSL -o get_helm.sh https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3
chmod 700 get_helm.sh ;\
./get_helm.sh ;\
rm -rf $$HELM_GEN_TMP_DIR ;\
}
HELM=$(shell which helm)
else
HELM=$(shell which helm)
endif
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -326,8 +326,8 @@ spec:
In other words, `file` option must be the correct entrypoint for `k6 run`.

### Using extensions
By default, the operator will use `grafana/k6:latest` as the container image for the test jobs.
If you want to use [extensions](https://k6.io/docs/extensions/get-started/explore/) built with [xk6](https://github.com/grafana/xk6) you'll need to create your own image and override the `image` property on the `K6` kubernetes resource.
By default, the operator will use `grafana/k6:latest` as the container image for the test jobs.
If you want to use [extensions](https://k6.io/docs/extensions/get-started/explore/) built with [xk6](https://github.com/grafana/xk6) you'll need to create your own image and override the `image` property on the `K6` kubernetes resource.

For example, create a `Dockerfile` with the following content:

Expand All @@ -346,7 +346,7 @@ RUN xk6 build \
FROM grafana/k6:latest
COPY --from=builder /k6 /usr/bin/k6
```
Build the image based on this `Dockerfile` by executing:
Build the image based on this `Dockerfile` by executing:
```bash
docker build -t k6-extended:local .
```
Expand Down Expand Up @@ -503,7 +503,7 @@ make delete
#### Run e2e Tests

- [install kind and create a k8s cluster](https://kind.sigs.k8s.io/docs/user/quick-start/) (or create your own dev cluster)
- `make e2e`
- `make e2e` for kustomize and `make e2e-helm` for helm
- validate tests have been run
- `make e2e-cleanup`

Expand Down
1 change: 1 addition & 0 deletions charts/.helmdocsignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
examples/
22 changes: 22 additions & 0 deletions charts/.helmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Patterns to ignore when building packages.
# This supports shell glob matching, relative path matching, and
# negation (prefixed with !). Only one pattern per line.
.DS_Store
# Common VCS dirs
.git/
.gitignore
.bzr/
.bzrignore
.hg/
.hgignore
.svn/
# Common backup files
*.swp
*.bak
*.tmp
*~
# Various IDEs
.project
.idea/
*.tmproj
.vscode/
21 changes: 21 additions & 0 deletions charts/.yamllint
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
---
extends: default

ignore: |
templates/*.yaml
repository-metadata.yaml

rules:
document-start: disable
braces:
max-spaces-inside: 1
level: error
brackets:
max-spaces-inside: 1
level: error
empty-lines:
max: 1
indentation:
spaces: 2
line-length:
max: 200
20 changes: 20 additions & 0 deletions charts/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
apiVersion: v1
appVersion: "0.0.10"
description: A Helm chart to install the k6 operator
name: k6-operator
version: 0.0.1
kubeVersion: ">=1.16.0-0"
home: https://k6.io
sources:
- https://github.com/grafana/k6-operator
keywords:
- load-testing
- smoke-testing
- stress-testing
- soak-testing
- kubernetes
yorugac marked this conversation as resolved.
Show resolved Hide resolved
- distributed-testing
maintainers:
- name: yorugac
email: yorugac@gmail.com
icon: https://raw.githubusercontent.com/grafana/k6-docs/main/static/images/icon.png
57 changes: 57 additions & 0 deletions charts/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# k6-operator

![Version: 0.0.1](https://img.shields.io/badge/Version-0.0.1-informational?style=flat-square) ![AppVersion: 0.0.6](https://img.shields.io/badge/AppVersion-0.0.6-informational?style=flat-square)

A Helm chart to install the k6 operator

**Homepage:** <https://k6.io>

## Maintainers

| Name | Email | Url |
| ---- | ------ | --- |
| yorugac | <yorugac@gmail.com> | |

## Source Code

* <https://github.com/grafana/k6-operator>

## Requirements

Kubernetes: `>=1.16.0-0`

## Values

| Key | Type | Default | Description |
|-----|------|---------|-------------|
| affinity | object | `{}` | Affinity to be applied on all containers |
| authProxy.enabled | bool | `true` | enables the protection of /metrics endpoint. (https://github.com/brancz/kube-rbac-proxy) |
| authProxy.image.name | string | `"gcr.io/kubebuilder/kube-rbac-proxy"` | rbac-proxy image name |
| authProxy.image.pullPolicy | string | `"IfNotPresent"` | pull policy for the image can be Always, Never, IfNotPresent (default: IfNotPresent) |
| authProxy.image.tag | string | `"v0.5.0"` | rbac-proxy image tag |
| authProxy.livenessProbe | object | `{}` | Liveness probe in Probe format |
| authProxy.readinessProbe | object | `{}` | Readiness probe in Probe format |
| authProxy.resources | object | `{}` | rbac-proxy resource limitation/request |
| controlPlane | string | `"controller-manager"` | |
| customAnnotations | object | `{}` | Custom Annotations to be applied on all resources |
| customLabels | object | `{}` | Custom Label to be applied on all resources |
| manager.env | object | `{}` | EEnvironment variables to be applied on the controller |
| manager.image.name | string | `"ghcr.io/grafana/operator"` | controller-manager image name |
| manager.image.pullPolicy | string | `"Always"` | pull policy for the image possible values Always, Never, IfNotPresent (default: Always) |
| manager.image.tag | string | `"latest"` | controller-manager image tag |
| manager.livenessProbe | object | `{}` | Liveness probe in Probe format |
| manager.readinessProbe | object | `{}` | Readiness probe in Probe format |
| manager.resources | object | `{"limits":{"cpu":"100m","memory":"100Mi"},"requests":{"cpu":"100m","memory":"50Mi"}}` | controller-manager Resources definition |
| manager.resources.limits.cpu | string | `"100m"` | controller-manager CPU limit (Max) |
| manager.resources.limits.memory | string | `"100Mi"` | controller-manager Memory limit (Max) |
| manager.resources.requests.cpu | string | `"100m"` | controller-manager CPU request (Min) |
| manager.resources.requests.memory | string | `"50Mi"` | controller-manager Memory request (Min) |
| manager.serviceAccount.create | bool | `true` | create the service account (default: true) |
| manager.serviceAccount.name | string | `"k6-operator-controller"` | kubernetes service account for the k6 manager |
| namespace.create | bool | `true` | create the namespace (default: true) |
| nodeSelector | object | `{}` | Node Selector to be applied on all containers |
| prometheus.enabled | bool | `false` | enables the prometheus metrics scraping (default: false) |
| tolerations | object | `{}` | Tolerations to be applied on all containers |

----------------------------------------------
Autogenerated from chart metadata using [helm-docs v1.11.0](https://github.com/norwoodj/helm-docs/releases/v1.11.0)
17 changes: 17 additions & 0 deletions charts/README.md.gotmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{{ template "chart.header" . }}

{{ template "chart.versionBadge" . }}{{ template "chart.typeBadge" . }}{{ template "chart.appVersionBadge" . }}

{{ template "chart.description" . }}

{{ template "chart.homepageLine" . }}

{{ template "chart.maintainersSection" . }}

{{ template "chart.sourcesSection" . }}

{{ template "chart.requirementsSection" . }}

{{ template "chart.valuesSection" . }}

{{ template "helm-docs.versionFooter" . }}
Loading
Loading