Skip to content

Commit 1154aff

Browse files
authored
Chart Refactoring (#93)
* Move the chart to the charts folder * Use helm-docs to generate docs for the chart * Use chart release action to automate chart releasing process * Delete deploy folder to only maintain a single installation option (chart) Other changes: * Add Makefile * Bump min go version to 1.21 * Bump golangci-lint 1.55.2
1 parent 256f99a commit 1154aff

27 files changed

+273
-255
lines changed

.github/workflows/chart.yml

+27-38
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,35 @@
1-
name: chart
2-
3-
env:
4-
CHARTMUSEUM_URL: "https://charts.flant.com/api/common/github/charts"
5-
CHART_DIR: "helm/charts/k8s-image-availability-exporter"
1+
name: Release Charts
62

73
on:
84
push:
9-
tags:
10-
- v*
11-
branches:
12-
- master
13-
pull_request:
145
branches:
15-
- master
16-
17-
defaults:
18-
run:
19-
shell: "bash -l -eo pipefail {0}"
6+
- main
7+
paths:
8+
- 'charts/**'
209

2110
jobs:
22-
tests:
23-
runs-on: ubuntu-latest
24-
steps:
25-
- uses: actions/[email protected]
26-
- uses: werf/actions/[email protected]
27-
- name: Werf lint chart
28-
run: cd "$CHART_DIR" && werf helm lint
29-
- name: Werf render chart
30-
run: cd "$CHART_DIR" && werf helm template .
31-
publish-charts:
11+
chart-release:
3212
runs-on: ubuntu-latest
33-
if: "github.event_name == 'push' && github.ref == 'refs/heads/master'"
34-
needs: tests
3513
steps:
36-
- uses: actions/[email protected]
37-
- uses: werf/actions/[email protected]
38-
- name: Package werf charts
39-
run: |
40-
mkdir -p .packages
41-
werf helm package "$CHART_DIR" -d .packages
42-
- name: Publish packaged werf charts
43-
run: |
44-
while read package; do
45-
curl -sSL --post301 --data-binary "@.packages/$package" --user "${{ secrets.CHARTMUSEUM_BASIC_AUTH_USER }}:${{ secrets.CHARTMUSEUM_BASIC_AUTH_PASS }}" "$CHARTMUSEUM_URL"
46-
done < <(find .packages -mindepth 1 -maxdepth 1 -type f -name '*.tgz' -exec sh -c 'basename "$0"' '{}' \;)
14+
- name: Checkout
15+
uses: actions/checkout@v2
16+
with:
17+
fetch-depth: 0
18+
19+
- name: Configure Git
20+
run: |
21+
git config user.name "$GITHUB_ACTOR"
22+
git config user.email "[email protected]"
23+
24+
- name: Install Helm
25+
uses: azure/setup-helm@v1
26+
with:
27+
version: v3.7.1
28+
29+
- name: Run chart-releaser
30+
uses: helm/[email protected]
31+
with:
32+
charts_dir: charts
33+
config: charts/cr.yaml
34+
env:
35+
CR_TOKEN: "${{ secrets.GITHUB_TOKEN }}"

.github/workflows/ci.yml

+27-6
Original file line numberDiff line numberDiff line change
@@ -13,35 +13,54 @@ env:
1313
IMAGE_NAME: k8s-image-availability-exporter/k8s-image-availability-exporter
1414
jobs:
1515
test:
16+
name: Test
1617
runs-on: ubuntu-latest
18+
1719
steps:
1820
- uses: actions/setup-go@v5
1921
with:
20-
go-version: '1.19'
22+
go-version: '1.21'
2123

2224
- uses: actions/[email protected]
2325

2426
- name: Test With Coverage
2527
run: go test -v -race -coverprofile=coverage.txt -covermode=atomic ./...
28+
2629
- name: Upload coverage to Codecov
2730
uses: codecov/[email protected]
2831
with:
2932
files: coverage.txt
3033

31-
- name: golangci-lint
32-
uses: golangci/[email protected]
34+
lint:
35+
name: Lint
36+
runs-on: ubuntu-latest
37+
38+
steps:
39+
- uses: actions/[email protected]
40+
41+
- uses: actions/setup-go@v5
3342
with:
34-
args: --timeout=5m
35-
# since go test already does it in a previous step
36-
skip-pkg-cache: true
43+
go-version: '1.21'
44+
45+
- name: Download golangci-lint
46+
run: make bin/golangci-lint
47+
48+
- name: Lint
49+
run: make lint
50+
3751
build:
52+
name: Build
53+
3854
runs-on: ubuntu-latest
3955
needs: test
56+
4057
permissions:
4158
contents: read
4259
packages: write
60+
4361
steps:
4462
- uses: actions/[email protected]
63+
4564
# Login against a Docker registry except on PR
4665
# https://github.com/docker/login-action
4766
- name: Log into registry ${{ env.REGISTRY }}
@@ -51,13 +70,15 @@ jobs:
5170
registry: ${{ env.REGISTRY }}
5271
username: ${{ secrets.DECKHOUSE_REGISTRY_USER }}
5372
password: ${{ secrets.DECKHOUSE_REGISTRY_PASSWORD }}
73+
5474
# Extract metadata (tags, labels) for Docker
5575
# https://github.com/docker/metadata-action
5676
- name: Extract Docker metadata
5777
id: meta
5878
uses: docker/[email protected]
5979
with:
6080
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
81+
6182
# Build and push Docker image with Buildx (don't push on PR)
6283
# https://github.com/docker/build-push-action
6384
- name: Build and push Docker image

.golangci.yml

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
run:
2+
timeout: 10m
3+
4+
linters:
5+
disable-all: true
6+
enable:
7+
- govet
8+
- revive
9+
- promlinter
10+
- gofmt

Makefile

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
export PATH := $(abspath bin/protoc/bin/):$(abspath bin/):${PATH}
2+
export SHELL := env PATH=$(PATH) /bin/sh
3+
4+
GOOS?=$(shell go env GOOS)
5+
GOARCH?=$(shell go env GOARCH)
6+
GOLANGCI_VERSION = 1.55.2
7+
HELM_DOCS_VERSION = 1.11.0
8+
9+
ifeq ($(GOARCH),arm)
10+
ARCH=armv7
11+
else
12+
ARCH=$(GOARCH)
13+
endif
14+
15+
COMMIT=$(shell git rev-parse --verify HEAD)
16+
17+
###########
18+
# BUILDING
19+
###########
20+
bin/k8s-image-availability-exporter:
21+
GOOS=$(GOOS) GOARCH=$(GOARCH) CGO_ENABLED=0 go build -mod=readonly -o bin/k8s-image-availability-exporter
22+
23+
build: bin/k8s-image-availability-exporter
24+
25+
###########
26+
# LINTING
27+
###########
28+
bin/golangci-lint: bin/golangci-lint-${GOLANGCI_VERSION}
29+
@ln -sf golangci-lint-${GOLANGCI_VERSION} bin/golangci-lint
30+
31+
bin/golangci-lint-${GOLANGCI_VERSION}:
32+
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | BINARY=golangci-lint bash -s -- v${GOLANGCI_VERSION}
33+
@mv bin/golangci-lint $@
34+
35+
###########
36+
# HELM
37+
###########
38+
39+
bin/helm-docs: bin/helm-docs-${HELM_DOCS_VERSION}
40+
@ln -sf helm-docs-${HELM_DOCS_VERSION} bin/helm-docs
41+
bin/helm-docs-${HELM_DOCS_VERSION}:
42+
@mkdir -p bin
43+
curl -L https://github.com/norwoodj/helm-docs/releases/download/v${HELM_DOCS_VERSION}/helm-docs_${HELM_DOCS_VERSION}_$(shell uname)_x86_64.tar.gz | tar -zOxf - helm-docs > ./bin/helm-docs-${HELM_DOCS_VERSION} && chmod +x ./bin/helm-docs-${HELM_DOCS_VERSION}
44+
45+
.PHONY: lint fix
46+
lint: bin/golangci-lint
47+
bin/golangci-lint run
48+
49+
fix: bin/golangci-lint
50+
bin/golangci-lint run --fix
51+
52+
.PHONY: docs
53+
docs: bin/helm-docs
54+
bin/helm-docs -s file -c charts/ -t README.md.gotmpl
55+
56+
###########
57+
# TESTING
58+
###########
59+
test:
60+
go test -race -cover -v ./...

README.md

+25-9
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,17 @@ Receiving alerts when container images related to running Kubernetes controllers
1414

1515
## Deploying
1616

17-
After cloning this repo:
17+
### Container image
1818

19-
`kubectl apply -f deploy/`
19+
Ready-to-use container images are available in the Deckhouse registry:
20+
21+
```bash
22+
docker pull registry.deckhouse.io/k8s-image-availability-exporter/k8s-image-availability-exporter:latest
23+
```
24+
25+
### Helm Chart
26+
27+
The helm chart is available on [artifacthub](https://artifacthub.io/packages/helm/k8s-image-availability-exporter/k8s-image-availability-exporter). Follow instructions on the page to install it.
2028

2129
### Prometheus integration
2230

@@ -195,13 +203,21 @@ spec:
195203
196204
### Command-line options
197205
198-
* `--bind-address` — IP address and port to bind to.
199-
* Default: `:8080`
200-
* `--check-interval` — interval for checking absent images. In Go `time` format.
201-
* Default: `5m`
202-
* `--ignored-images` — comma-separated list of images to ignore while checking absent images.
203-
* `--skip-registry-cert-verification` — whether to skip registries' certificate verification.
204-
* `--namespace` — inspect specific namespace instead of whole k8s cluster.
206+
```
207+
Usage of k8s-image-availability-exporter:
208+
-bind-address string
209+
address:port to bind /metrics endpoint to (default ":8080")
210+
-check-interval duration
211+
image re-check interval (default 1m0s)
212+
-default-registry string
213+
default registry to use in absence of a fully qualified image name, defaults to "index.docker.io"
214+
-ignored-images string
215+
tilde-separated image regexes to ignore, each image will be checked against this list of regexes
216+
-namespace-label string
217+
namespace label for checks
218+
-skip-registry-cert-verification
219+
whether to skip registries' certificate verification
220+
```
205221

206222
## Metrics
207223

charts/cr.yaml

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
owner: deckhouse
2+
git-base-url: https://api.github.com/
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
apiVersion: v1
22
appVersion: "v0.5.1"
3-
description: Application for monitoring the cluster workloads image presence in docker registry.
3+
description: Application for monitoring the cluster workloads image presence in a container registry.
44
name: k8s-image-availability-exporter
5-
version: "0.5.1"
5+
version: "0.6.0"
6+
kubeVersion: ">=1.14.0-0"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# k8s-image-availability-exporter
2+
3+
![Version: 0.6.0](https://img.shields.io/badge/Version-0.6.0-informational?style=flat-square) ![AppVersion: v0.5.1](https://img.shields.io/badge/AppVersion-v0.5.1-informational?style=flat-square)
4+
5+
Application for monitoring the cluster workloads image presence in a container registry.
6+
7+
## Requirements
8+
9+
Kubernetes: `>=1.14.0-0`
10+
11+
## Introduction
12+
13+
This chart bootstraps a [k8s-image-availability-exporter](https://github.com/flant/k8s-image-availability-exporter) deployment on a [Kubernetes](http://kubernetes.io) cluster using the [Helm](https://helm.sh) package manager.
14+
15+
## Values
16+
17+
| Key | Type | Default | Description |
18+
|-----|------|---------|-------------|
19+
| k8sImageAvailabilityExporter.image.repository | string | `"registry.deckhouse.io/k8s-image-availability-exporter/k8s-image-availability-exporter"` | Repository to use for the k8s-image-availability-exporter deployment |
20+
| k8sImageAvailabilityExporter.image.tag | string | `""` | Image tag override for the default value (chart appVersion) |
21+
| k8sImageAvailabilityExporter.image.pullPolicy | string | `"IfNotPresent"` | Image pull policy to use for the k8s-image-availability-exporter deployment |
22+
| k8sImageAvailabilityExporter.replicas | int | `1` | Number of instances to deploy for a k8s-image-availability-exporter deployment |
23+
| k8sImageAvailabilityExporter.resources | object | `{}` | Resource limits for k8s-image-availability-exporter |
24+
| k8sImageAvailabilityExporter.args | list | `["--bind-address=:8080"]` | Command line arguments for the exporter |
25+
| serviceMonitor.enabled | bool | `false` | Create [Prometheus Operator](https://github.com/coreos/prometheus-operator) serviceMonitor resource |
26+
| serviceMonitor.interval | string | `"15s"` | Scrape interval for serviceMonitor |
27+
| prometheusRule.enabled | bool | `false` | Create [Prometheus Operator](https://github.com/coreos/prometheus-operator) prometheusRule resource |
28+
| prometheusRule.defaultGroupsEnabled | bool | `true` | Setup default alerts (works only if prometheusRule.enabled is set to true) |
29+
| prometheusRule.additionalGroups | list | `[]` | Additional PrometheusRule groups |
30+
31+
Specify each parameter using the `--set key=value[,key=value]` argument to `helm install`. For example,
32+
33+
```bash
34+
helm install my-release k8s-image-availability-exporter --set k8sImageAvailabilityExporter.replicas=2
35+
```
36+
37+
Alternatively, one or more YAML files that specify the values for the above parameters can be provided while installing the chart. For example,
38+
39+
```bash
40+
helm install my-release k8s-image-availability-exporter -f values1.yaml,values2.yaml
41+
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
{{ template "chart.header" . }}
2+
3+
{{ template "chart.badgesSection" . }}
4+
5+
{{ template "chart.description" . }}
6+
7+
{{ template "chart.requirementsSection" . }}
8+
9+
{{ template "chart.deprecationWarning" . }}
10+
11+
## Introduction
12+
13+
This chart bootstraps a [k8s-image-availability-exporter](https://github.com/flant/k8s-image-availability-exporter) deployment on a [Kubernetes](http://kubernetes.io) cluster using the [Helm](https://helm.sh) package manager.
14+
15+
{{ template "chart.homepageLine" . }}
16+
17+
{{ template "chart.maintainersSection" . }}
18+
19+
{{ template "chart.valuesSection" . }}
20+
21+
Specify each parameter using the `--set key=value[,key=value]` argument to `helm install`. For example,
22+
23+
```bash
24+
helm install my-release k8s-image-availability-exporter --set k8sImageAvailabilityExporter.replicas=2
25+
```
26+
27+
Alternatively, one or more YAML files that specify the values for the above parameters can be provided while installing the chart. For example,
28+
29+
```bash
30+
helm install my-release k8s-image-availability-exporter -f values1.yaml,values2.yaml
31+
```

helm/charts/k8s-image-availability-exporter/templates/deployment.yaml charts/k8s-image-availability-exporter/templates/deployment.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ spec:
3737
ports:
3838
- containerPort: 8080
3939
name: http
40-
image: {{ .Values.k8sImageAvailabilityExporter.image.repository }}:{{ .Values.k8sImageAvailabilityExporter.image.tag }}
40+
image: {{ .Values.k8sImageAvailabilityExporter.image.repository }}:{{ .Values.image.tag | default (printf "v%s" .Chart.AppVersion) }}"
4141
imagePullPolicy: {{ .Values.k8sImageAvailabilityExporter.image.imagePullPolicy }}
4242
livenessProbe:
4343
httpGet:
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
k8sImageAvailabilityExporter:
2+
image:
3+
# -- Repository to use for the k8s-image-availability-exporter deployment
4+
repository: registry.deckhouse.io/k8s-image-availability-exporter/k8s-image-availability-exporter
5+
# -- Image tag override for the default value (chart appVersion)
6+
tag: ""
7+
# -- Image pull policy to use for the k8s-image-availability-exporter deployment
8+
pullPolicy: IfNotPresent
9+
# -- Number of instances to deploy for a k8s-image-availability-exporter deployment
10+
replicas: 1
11+
# -- Resource limits for k8s-image-availability-exporter
12+
resources: {}
13+
# -- Command line arguments for the exporter
14+
args:
15+
- --bind-address=:8080
16+
17+
serviceMonitor:
18+
# -- Create [Prometheus Operator](https://github.com/coreos/prometheus-operator) serviceMonitor resource
19+
enabled: false
20+
# -- Scrape interval for serviceMonitor
21+
interval: 15s
22+
23+
prometheusRule:
24+
# -- Create [Prometheus Operator](https://github.com/coreos/prometheus-operator) prometheusRule resource
25+
enabled: false
26+
# -- Setup default alerts (works only if prometheusRule.enabled is set to true)
27+
defaultGroupsEnabled: true
28+
# -- Additional PrometheusRule groups
29+
additionalGroups: []

0 commit comments

Comments
 (0)