Skip to content

Commit

Permalink
ci: added pre-commit (#811)
Browse files Browse the repository at this point in the history
This PR introduces a pre-commit config which is used in our ci pipeline.
Furthermore, an additional formatting of all affected resources was
done.

The following config was used as a baseline:
https://github.com/hetznercloud/.github/blob/main/.pre-commit-config.yaml

---------

Co-authored-by: Jonas L. <jooola@users.noreply.github.com>
  • Loading branch information
lukasmetzner and jooola authored Dec 16, 2024
1 parent 9e9d983 commit ffaf6ba
Show file tree
Hide file tree
Showing 46 changed files with 1,204 additions and 1,212 deletions.
18 changes: 18 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,24 @@ env:
GOTOOLCHAIN: local

jobs:
pre-commit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- uses: actions/setup-python@v5
with:
python-version: 3.x

- uses: yokawasa/action-setup-kube-tools@v0.11.2
with:
# helm is needed to generate chart snapshots
setup-tools: |
helm
helm: v3.16.3 # renovate: datasource=github-releases depName=helm/helm

- uses: pre-commit/action@v3.0.1

lint:
runs-on: ubuntu-latest
steps:
Expand Down
47 changes: 0 additions & 47 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -115,50 +115,3 @@ jobs:
if: always()
continue-on-error: true
run: make -C dev down

deploy-manifests:
runs-on: ubuntu-latest

steps:
- uses: yokawasa/action-setup-kube-tools@v0.11.2
with:
setup-tools: |
helm
helm: v3.16.3 # renovate: datasource=github-releases depName=helm/helm

- uses: actions/checkout@v4

- name: Generate manifests from helm chart
run: hack/update-deployment-yamls.sh

- name: Check for diff
run: git diff --exit-code -- deploy/

- name: Show warning
if: failure()
run: echo "::error title=Deployment Manifests outdated::Please run hack/update-deployment-yamls.sh and commit the changes to deploy/"

helm-chart:
runs-on: ubuntu-latest

steps:
- uses: yokawasa/action-setup-kube-tools@v0.11.2
with:
setup-tools: |
helm
helm: v3.16.3 # renovate: datasource=github-releases depName=helm/helm

- uses: actions/checkout@v4

# This step also verifies that the chart builds
- name: Verify Snapshots
run: |
hack/update-helm-snapshots.sh
git diff --exit-code -- chart/.snapshots/
- name: Show warning
if: failure()
run: echo "::error title=Helm Snapshots outdated::Please run hack/update-helm-snapshots.sh and commit the changes to chart/.snapshots/"

- name: Helm Lint
run: helm lint chart/
9 changes: 6 additions & 3 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,20 +32,23 @@ dockers:
- build_flag_templates: [--platform=linux/amd64]
dockerfile: Dockerfile
goarch: amd64
image_templates: ["hetznercloud/hcloud-csi-driver:{{ if not .IsSnapshot }}v{{ end }}{{ .Version }}-amd64"]
image_templates:
- "hetznercloud/hcloud-csi-driver:{{ if not .IsSnapshot }}v{{ end }}{{ .Version }}-amd64"
use: buildx

- build_flag_templates: [--platform=linux/arm64]
dockerfile: Dockerfile
goarch: arm64
image_templates: ["hetznercloud/hcloud-csi-driver:{{ if not .IsSnapshot }}v{{ end }}{{ .Version }}-arm64v8"]
image_templates:
- "hetznercloud/hcloud-csi-driver:{{ if not .IsSnapshot }}v{{ end }}{{ .Version }}-arm64v8"
use: buildx

- build_flag_templates: [--platform=linux/arm/v6]
dockerfile: Dockerfile
goarch: arm
goarm: 6
image_templates: ["hetznercloud/hcloud-csi-driver:{{ if not .IsSnapshot }}v{{ end }}{{ .Version }}-armv6"]
image_templates:
- "hetznercloud/hcloud-csi-driver:{{ if not .IsSnapshot }}v{{ end }}{{ .Version }}-armv6"
use: buildx

docker_manifests:
Expand Down
64 changes: 64 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
---
# See https://pre-commit.com for more information
# See https://pre-commit.com/hooks.html for more hooks
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v5.0.0
hooks:
- id: check-added-large-files
- id: check-case-conflict
- id: check-executables-have-shebangs
- id: check-shebang-scripts-are-executable
- id: check-symlinks
- id: destroyed-symlinks

- id: check-toml
- id: check-json
- id: check-yaml
args: [--allow-multiple-documents]
exclude: ^(deploy/.*|chart/templates/.*)$

- id: check-merge-conflict
- id: end-of-file-fixer
- id: mixed-line-ending
args: [--fix=lf]
- id: trailing-whitespace
exclude: ^(chart/.snapshots/.*|deploy/.*)$

- repo: local
hooks:
- id: update-helm-snapshots
name: update-helm-snapshots
language: system
entry: bash ./hack/update-helm-snapshots.sh
files: ^(charts/.*|hack/update-helm-snapshots.sh$)
pass_filenames: false

- id: update-deployment-yamls
name: update-deployment-yamls
language: system
entry: bash ./hack/update-deployment-yamls.sh
files: ^(charts/.*|hack/update-deployment-yamls.sh$)
pass_filenames: false

- repo: https://github.com/pre-commit/mirrors-prettier
rev: v3.1.0
hooks:
- id: prettier
files: \.(md|ya?ml|json)$
exclude: ^(CHANGELOG.md|chart/templates/.*|chart/.snapshots/.*|deploy/.*)$

- repo: local
hooks:
- id: shfmt
name: shfmt
description: Format shell scripts with shfmt
language: golang
additional_dependencies: [mvdan.cc/sh/v3/cmd/shfmt@v3.7.0]
entry: shfmt -i 2 -ci -sr -kp -w
types: [shell]

- repo: https://github.com/shellcheck-py/shellcheck-py
rev: v0.10.0.1
hooks:
- id: shellcheck
2 changes: 1 addition & 1 deletion chart/.helmignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@
.idea/
*.tmproj

.snapshots
.snapshots
102 changes: 51 additions & 51 deletions chart/.snapshots/default.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,55 +35,55 @@ metadata:
app.kubernetes.io/managed-by: Helm
app.kubernetes.io/component: controller
rules:
# attacher
- apiGroups: [""]
resources: [persistentvolumes]
verbs: [get, list, watch, update, patch]
- apiGroups: [""]
resources: [nodes]
verbs: [get, list, watch]
- apiGroups: [csi.storage.k8s.io]
resources: [csinodeinfos]
verbs: [get, list, watch]
- apiGroups: [storage.k8s.io]
resources: [csinodes]
verbs: [get, list, watch]
- apiGroups: [storage.k8s.io]
resources: [volumeattachments]
verbs: [get, list, watch, update, patch]
- apiGroups: [storage.k8s.io]
resources: [volumeattachments/status]
verbs: [patch]
# provisioner
- apiGroups: [""]
resources: [secrets]
verbs: [get, list]
- apiGroups: [""]
resources: [persistentvolumes]
verbs: [get, list, watch, create, delete, patch]
- apiGroups: [""]
resources: [persistentvolumeclaims, persistentvolumeclaims/status]
verbs: [get, list, watch, update, patch]
- apiGroups: [storage.k8s.io]
resources: [storageclasses]
verbs: [get, list, watch]
- apiGroups: [""]
resources: [events]
verbs: [list, watch, create, update, patch]
- apiGroups: [snapshot.storage.k8s.io]
resources: [volumesnapshots]
verbs: [get, list]
- apiGroups: [snapshot.storage.k8s.io]
resources: [volumesnapshotcontents]
verbs: [get, list]
# resizer
- apiGroups: [""]
resources: [pods]
verbs: [get, list, watch]
# node
- apiGroups: [""]
resources: [events]
verbs: [get, list, watch, create, update, patch]
# attacher
- apiGroups: [""]
resources: [persistentvolumes]
verbs: [get, list, watch, update, patch]
- apiGroups: [""]
resources: [nodes]
verbs: [get, list, watch]
- apiGroups: [csi.storage.k8s.io]
resources: [csinodeinfos]
verbs: [get, list, watch]
- apiGroups: [storage.k8s.io]
resources: [csinodes]
verbs: [get, list, watch]
- apiGroups: [storage.k8s.io]
resources: [volumeattachments]
verbs: [get, list, watch, update, patch]
- apiGroups: [storage.k8s.io]
resources: [volumeattachments/status]
verbs: [patch]
# provisioner
- apiGroups: [""]
resources: [secrets]
verbs: [get, list]
- apiGroups: [""]
resources: [persistentvolumes]
verbs: [get, list, watch, create, delete, patch]
- apiGroups: [""]
resources: [persistentvolumeclaims, persistentvolumeclaims/status]
verbs: [get, list, watch, update, patch]
- apiGroups: [storage.k8s.io]
resources: [storageclasses]
verbs: [get, list, watch]
- apiGroups: [""]
resources: [events]
verbs: [list, watch, create, update, patch]
- apiGroups: [snapshot.storage.k8s.io]
resources: [volumesnapshots]
verbs: [get, list]
- apiGroups: [snapshot.storage.k8s.io]
resources: [volumesnapshotcontents]
verbs: [get, list]
# resizer
- apiGroups: [""]
resources: [pods]
verbs: [get, list, watch]
# node
- apiGroups: [""]
resources: [events]
verbs: [get, list, watch, create, update, patch]
---
# Source: hcloud-csi/templates/controller/clusterrolebinding.yaml
kind: ClusterRoleBinding
Expand Down Expand Up @@ -115,7 +115,7 @@ metadata:
app.kubernetes.io/instance: hcloud-csi
app.kubernetes.io/managed-by: Helm
app.kubernetes.io/component: node
app: hcloud-csi
app: hcloud-csi
spec:
updateStrategy:
type: RollingUpdate
Expand Down Expand Up @@ -243,7 +243,7 @@ metadata:
app.kubernetes.io/instance: hcloud-csi
app.kubernetes.io/managed-by: Helm
app.kubernetes.io/component: controller
app: hcloud-csi-controller
app: hcloud-csi-controller
spec:
replicas: 1
strategy:
Expand Down
Loading

0 comments on commit ffaf6ba

Please sign in to comment.