diff --git a/.chartreleaser.yaml b/.chartreleaser.yaml new file mode 100644 index 0000000..4bf8576 --- /dev/null +++ b/.chartreleaser.yaml @@ -0,0 +1 @@ +release-name-template: "helm-v{{ .Version }}" diff --git a/.github/workflows/build-helm.yaml b/.github/workflows/build-helm.yaml new file mode 100644 index 0000000..ebbb437 --- /dev/null +++ b/.github/workflows/build-helm.yaml @@ -0,0 +1,52 @@ +name: Build Charts + +on: + push: + branches: [ main ] + paths: + - helm/** + pull_request: + branches: [ master ] + paths: + - helm/** + +jobs: + lint-test: + 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.4.2 + + - name: Set up Python + uses: actions/setup-python@v2 + with: + python-version: 3.7 + + - name: Set up chart-testing + uses: helm/chart-testing-action@v2.0.1 + with: + version: v3.3.0 + + - name: Run chart-testing (list-changed) + id: list-changed + run: | + changed=$(ct list-changed --config helm/ct.yaml) + if [[ -n "$changed" ]]; then + echo "::set-output name=changed::true" + fi + - name: Run chart-testing (lint) + run: ct lint --config helm/ct.yaml --check-version-increment=false + + - name: Create kind cluster + uses: helm/kind-action@v1.1.0 + if: steps.list-changed.outputs.changed == 'true' + + - name: Run chart-testing (install) + run: ct install --config helm/ct.yaml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yaml similarity index 92% rename from .github/workflows/build.yml rename to .github/workflows/build.yaml index e16ff85..c2c9745 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yaml @@ -8,8 +8,15 @@ on: - LICENSE - .gitignore - .editorconfig + - helm/** pull_request: branches: [ master ] + paths-ignore: + - README.md + - LICENSE + - .gitignore + - .editorconfig + - helm/** jobs: lint: diff --git a/.github/workflows/release-helm.yaml b/.github/workflows/release-helm.yaml new file mode 100644 index 0000000..86dd649 --- /dev/null +++ b/.github/workflows/release-helm.yaml @@ -0,0 +1,33 @@ +name: Release Charts + +on: + push: + paths: + - version.yaml + + +jobs: + release: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v2 + with: + fetch-depth: 0 + + - name: Configure Git + run: | + git config user.name "$GITHUB_ACTOR" + git config user.email "$GITHUB_ACTOR@users.noreply.github.com" + - name: Install Helm + uses: azure/setup-helm@v1 + with: + version: v3.4.2 + + - name: Run chart-releaser + uses: helm/chart-releaser-action@v1.2.0 + with: + charts_dir: helm + config: .chartreleaser.yaml + env: + CR_TOKEN: "${{ secrets.GITHUB_TOKEN }}" diff --git a/.github/workflows/release.yml b/.github/workflows/release.yaml similarity index 100% rename from .github/workflows/release.yml rename to .github/workflows/release.yaml diff --git a/helm/hcloud-pricing-exporter/.helmignore b/helm/hcloud-pricing-exporter/.helmignore new file mode 100644 index 0000000..0e8a0eb --- /dev/null +++ b/helm/hcloud-pricing-exporter/.helmignore @@ -0,0 +1,23 @@ +# 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 +*.orig +*~ +# Various IDEs +.project +.idea/ +*.tmproj +.vscode/ diff --git a/helm/hcloud-pricing-exporter/Chart.yaml b/helm/hcloud-pricing-exporter/Chart.yaml new file mode 100644 index 0000000..fc2779c --- /dev/null +++ b/helm/hcloud-pricing-exporter/Chart.yaml @@ -0,0 +1,8 @@ +apiVersion: v2 +name: hcloud-pricing-exporter +description: A prometheus exporter for the current pricing and costs of your HCloud account + +type: application + +version: 0.1.1-r1 +appVersion: 0.1.1 diff --git a/helm/hcloud-pricing-exporter/templates/_helpers.tpl b/helm/hcloud-pricing-exporter/templates/_helpers.tpl new file mode 100644 index 0000000..94ba816 --- /dev/null +++ b/helm/hcloud-pricing-exporter/templates/_helpers.tpl @@ -0,0 +1,51 @@ +{{/* +Expand the name of the chart. +*/}} +{{- define "hcloud-pricing-exporter.name" -}} +{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }} +{{- end }} + +{{/* +Create a default fully qualified app name. +We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec). +If release name contains chart name it will be used as a full name. +*/}} +{{- define "hcloud-pricing-exporter.fullname" -}} +{{- if .Values.fullnameOverride }} +{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }} +{{- else }} +{{- $name := default .Chart.Name .Values.nameOverride }} +{{- if contains $name .Release.Name }} +{{- .Release.Name | trunc 63 | trimSuffix "-" }} +{{- else }} +{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }} +{{- end }} +{{- end }} +{{- end }} + +{{/* +Create chart name and version as used by the chart label. +*/}} +{{- define "hcloud-pricing-exporter.chart" -}} +{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }} +{{- end }} + +{{/* +Common labels +*/}} +{{- define "hcloud-pricing-exporter.labels" -}} +helm.sh/chart: {{ include "hcloud-pricing-exporter.chart" . }} +{{ include "hcloud-pricing-exporter.selectorLabels" . }} +{{- if .Chart.AppVersion }} +app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} +{{- end }} +app.kubernetes.io/managed-by: {{ .Release.Service }} +{{- end }} + +{{/* +Selector labels +*/}} +{{- define "hcloud-pricing-exporter.selectorLabels" -}} +app.kubernetes.io/name: {{ include "hcloud-pricing-exporter.name" . }} +app.kubernetes.io/instance: {{ .Release.Name }} +{{- end }} diff --git a/helm/hcloud-pricing-exporter/templates/deployment.yaml b/helm/hcloud-pricing-exporter/templates/deployment.yaml new file mode 100644 index 0000000..604d6c5 --- /dev/null +++ b/helm/hcloud-pricing-exporter/templates/deployment.yaml @@ -0,0 +1,67 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: {{ include "hcloud-pricing-exporter.fullname" . }} + labels: + {{- include "hcloud-pricing-exporter.labels" . | nindent 4 }} +spec: + replicas: {{ .Values.replicaCount }} + selector: + matchLabels: + {{- include "hcloud-pricing-exporter.selectorLabels" . | nindent 6 }} + template: + metadata: + {{- with .Values.podAnnotations }} + annotations: + {{- toYaml . | nindent 8 }} + {{- end }} + labels: + {{- include "hcloud-pricing-exporter.selectorLabels" . | nindent 8 }} + spec: + {{- with .Values.imagePullSecrets }} + imagePullSecrets: + {{- toYaml . | nindent 8 }} + {{- end }} + containers: + - name: {{ .Chart.Name }} + image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}" + imagePullPolicy: {{ .Values.image.pullPolicy }} + env: + - name: HCLOUD_TOKEN + {{- if .Values.secret.create }} + valueFrom: + secretKeyRef: + name: {{ include "hcloud-pricing-exporter.fullname" . }} + key: token + {{- else }} + valueFrom: + secretKeyRef: + name: {{ .Values.secret.reference.name }} + key: {{ .Values.secret.reference.key }} + {{- end }} + ports: + - name: http + containerPort: 8080 + protocol: TCP + livenessProbe: + httpGet: + path: / + port: http + readinessProbe: + httpGet: + path: / + port: http + resources: + {{- toYaml .Values.resources | nindent 12 }} + {{- with .Values.nodeSelector }} + nodeSelector: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.affinity }} + affinity: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.tolerations }} + tolerations: + {{- toYaml . | nindent 8 }} + {{- end }} diff --git a/helm/hcloud-pricing-exporter/templates/ingress.yaml b/helm/hcloud-pricing-exporter/templates/ingress.yaml new file mode 100644 index 0000000..657b1ce --- /dev/null +++ b/helm/hcloud-pricing-exporter/templates/ingress.yaml @@ -0,0 +1,41 @@ +{{- if .Values.ingress.enabled -}} +{{- $fullName := include "hcloud-pricing-exporter.fullname" . -}} +{{- $svcPort := .Values.service.port -}} +{{- if semverCompare ">=1.14-0" .Capabilities.KubeVersion.GitVersion -}} +apiVersion: networking.k8s.io/v1beta1 +{{- else -}} +apiVersion: extensions/v1beta1 +{{- end }} +kind: Ingress +metadata: + name: {{ $fullName }} + labels: + {{- include "hcloud-pricing-exporter.labels" . | nindent 4 }} + {{- with .Values.ingress.annotations }} + annotations: + {{- toYaml . | nindent 4 }} + {{- end }} +spec: + {{- if .Values.ingress.tls }} + tls: + {{- range .Values.ingress.tls }} + - hosts: + {{- range .hosts }} + - {{ . | quote }} + {{- end }} + secretName: {{ .secretName }} + {{- end }} + {{- end }} + rules: + {{- range .Values.ingress.hosts }} + - host: {{ .host | quote }} + http: + paths: + {{- range .paths }} + - path: {{ .path }} + backend: + serviceName: {{ $fullName }} + servicePort: {{ $svcPort }} + {{- end }} + {{- end }} + {{- end }} diff --git a/helm/hcloud-pricing-exporter/templates/secret.yaml b/helm/hcloud-pricing-exporter/templates/secret.yaml new file mode 100644 index 0000000..f89bec1 --- /dev/null +++ b/helm/hcloud-pricing-exporter/templates/secret.yaml @@ -0,0 +1,9 @@ +{{- if .Values.secret.create }} +apiVersion: v1 +kind: Secret +metadata: + name: {{ include "hcloud-pricing-exporter.fullname" . }} +type: Opaque +data: + token: {{ required "An token to access the HCloud API is required" .Values.secret.token | b64enc }} +{{- end }} diff --git a/helm/hcloud-pricing-exporter/templates/service.yaml b/helm/hcloud-pricing-exporter/templates/service.yaml new file mode 100644 index 0000000..6a2ceaa --- /dev/null +++ b/helm/hcloud-pricing-exporter/templates/service.yaml @@ -0,0 +1,15 @@ +apiVersion: v1 +kind: Service +metadata: + name: {{ include "hcloud-pricing-exporter.fullname" . }} + labels: + {{- include "hcloud-pricing-exporter.labels" . | nindent 4 }} +spec: + type: {{ .Values.service.type }} + ports: + - port: {{ .Values.service.port }} + targetPort: http + protocol: TCP + name: http + selector: + {{- include "hcloud-pricing-exporter.selectorLabels" . | nindent 4 }} diff --git a/helm/hcloud-pricing-exporter/templates/servicemonitor.yaml b/helm/hcloud-pricing-exporter/templates/servicemonitor.yaml new file mode 100644 index 0000000..e1687f4 --- /dev/null +++ b/helm/hcloud-pricing-exporter/templates/servicemonitor.yaml @@ -0,0 +1,27 @@ +{{ if .Values.serviceMonitor.create }} +apiVersion: monitoring.coreos.com/v1 +kind: ServiceMonitor +metadata: + name: {{ include "hcloud-pricing-exporter.fullname" . }} + labels: + {{- include "hcloud-pricing-exporter.labels" . | nindent 4 }} + {{- if .Values.serviceMonitor.labels }} + {{- toYaml .Values.serviceMonitor.labels | nindent 4 }} + {{- end }} +spec: + endpoints: + - honorLabels: true + targetPort: http + {{- with .Values.serviceMonitor.interval }} + interval: {{ . }} + {{- end }} + {{- with .Values.serviceMonitor.scrapeTimeout }} + scrapeTimeout: {{ . }} + {{- end }} + namespaceSelector: + matchNames: + - "{{ .Release.Namespace }}" + selector: + matchLabels: + {{- include "hcloud-pricing-exporter.selectorLabels" . | nindent 6 }} +{{- end }} diff --git a/helm/hcloud-pricing-exporter/values.yaml b/helm/hcloud-pricing-exporter/values.yaml new file mode 100644 index 0000000..ccc74d1 --- /dev/null +++ b/helm/hcloud-pricing-exporter/values.yaml @@ -0,0 +1,44 @@ +replicaCount: 1 + +image: + repository: jangraefen/hcloud-pricing-exporter + pullPolicy: IfNotPresent + tag: "" + +imagePullSecrets: [ ] +nameOverride: "" +fullnameOverride: "" + +podAnnotations: { } + +service: + type: ClusterIP + port: 8080 + +ingress: + enabled: false + annotations: { } + hosts: + - host: chart-example.local + tls: [ ] + +secret: + create: true + token: + reference: + name: + key: + +serviceMonitor: + create: false + interval: + labels: + scrapeTimeout: + +resources: { } + +nodeSelector: { } + +tolerations: [ ] + +affinity: { } diff --git a/version.yaml b/version.yaml new file mode 100644 index 0000000..fcc52ae --- /dev/null +++ b/version.yaml @@ -0,0 +1,2 @@ +version: 0.1.1 +helmRevision: r1