Skip to content

Commit a38a8a3

Browse files
authored
chore: add pre-commit setup (#714)
Ensure files are kept formatted using pre-commit. Some manual changes were done to improve further the changes made by prettier or linting error by shellcheck.
1 parent c43e711 commit a38a8a3

15 files changed

+146
-71
lines changed

.github/workflows/ci.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,17 @@ on:
77
pull_request:
88

99
jobs:
10+
pre-commit:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v4
14+
15+
- uses: actions/setup-python@v5
16+
with:
17+
python-version: 3.x
18+
19+
- uses: pre-commit/[email protected]
20+
1021
test:
1122
name: Unit Tests
1223
runs-on: ubuntu-latest

.goreleaser.yml

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,24 +20,29 @@ builds:
2020
- arm
2121
binary: hcloud-cloud-controller-manager
2222
ldflags:
23-
- "-s -w -X github.com/hetznercloud/hcloud-cloud-controller-manager/hcloud.providerVersion={{ if not .IsSnapshot }}v{{ end }}{{ .Version }}"
23+
- -s
24+
- -w
25+
- -X github.com/hetznercloud/hcloud-cloud-controller-manager/hcloud.providerVersion={{ if not .IsSnapshot }}v{{ end }}{{ .Version }}
2426

2527
dockers:
2628
- build_flag_templates: [--platform=linux/amd64]
2729
dockerfile: Dockerfile
2830
goarch: amd64
29-
image_templates: ["hetznercloud/hcloud-cloud-controller-manager:{{ if not .IsSnapshot }}v{{ end }}{{ .Version }}-amd64"]
31+
image_templates:
32+
- hetznercloud/hcloud-cloud-controller-manager:{{ if not .IsSnapshot }}v{{ end }}{{ .Version }}-amd64
3033
use: buildx
3134
- build_flag_templates: [--platform=linux/arm64]
3235
dockerfile: Dockerfile
3336
goarch: arm64
34-
image_templates: ["hetznercloud/hcloud-cloud-controller-manager:{{ if not .IsSnapshot }}v{{ end }}{{ .Version }}-arm64v8"]
37+
image_templates:
38+
- hetznercloud/hcloud-cloud-controller-manager:{{ if not .IsSnapshot }}v{{ end }}{{ .Version }}-arm64v8
3539
use: buildx
3640
- build_flag_templates: [--platform=linux/arm/v6]
3741
dockerfile: Dockerfile
3842
goarch: arm
3943
goarm: 6
40-
image_templates: ["hetznercloud/hcloud-cloud-controller-manager:{{ if not .IsSnapshot }}v{{ end }}{{ .Version }}-armv6"]
44+
image_templates:
45+
- hetznercloud/hcloud-cloud-controller-manager:{{ if not .IsSnapshot }}v{{ end }}{{ .Version }}-armv6
4146
use: buildx
4247

4348
docker_manifests:
@@ -50,8 +55,8 @@ docker_manifests:
5055
release:
5156
ids: [""]
5257
extra_files:
53-
- glob: "./deploy/ccm*.yaml"
54-
- glob: "./hcloud-cloud-controller-manager-*.tgz"
58+
- glob: ./deploy/ccm*.yaml
59+
- glob: ./hcloud-cloud-controller-manager-*.tgz
5560

5661
publishers:
5762
- name: helm-chart-repo

.pre-commit-config.yaml

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
---
2+
# See https://pre-commit.com for more information
3+
# See https://pre-commit.com/hooks.html for more hooks
4+
repos:
5+
- repo: https://github.com/pre-commit/pre-commit-hooks
6+
rev: v4.6.0
7+
hooks:
8+
- id: check-added-large-files
9+
- id: check-case-conflict
10+
- id: check-executables-have-shebangs
11+
- id: check-shebang-scripts-are-executable
12+
- id: check-symlinks
13+
- id: destroyed-symlinks
14+
15+
- id: check-json
16+
- id: check-yaml
17+
exclude: ^(deploy/.*|chart/templates/.*)$
18+
19+
- id: check-merge-conflict
20+
- id: end-of-file-fixer
21+
- id: mixed-line-ending
22+
args: [--fix=lf]
23+
- id: trailing-whitespace
24+
25+
- repo: local
26+
hooks:
27+
- id: prettier
28+
name: prettier
29+
entry: prettier --write --ignore-unknown
30+
language: node
31+
types: [text]
32+
require_serial: false
33+
additional_dependencies: [[email protected]]
34+
files: \.(md|ya?ml)$
35+
exclude: ^(CHANGELOG.md|chart/templates/.*)$
36+
37+
- repo: local
38+
hooks:
39+
- id: shfmt
40+
name: shfmt
41+
description: Format shell scripts with shfmt
42+
language: golang
43+
additional_dependencies: [mvdan.cc/sh/v3/cmd/[email protected]]
44+
entry: shfmt -i 2 -ci -sr -kp -w
45+
types: [shell]
46+
47+
- repo: https://github.com/shellcheck-py/shellcheck-py
48+
rev: v0.10.0.1
49+
hooks:
50+
- id: shellcheck

README.md

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -76,53 +76,53 @@ documentation](https://kubernetes.io/docs/reference/setup-tools/kubeadm/kubeadm/
7676

7777
2. Now the control plane can be initialized:
7878

79-
```sh
80-
sudo kubeadm init --pod-network-cidr=10.244.0.0/16
81-
```
79+
```sh
80+
sudo kubeadm init --pod-network-cidr=10.244.0.0/16
81+
```
8282

8383
3. Configure kubectl to connect to the kube-apiserver:
8484

85-
```sh
86-
mkdir -p $HOME/.kube
87-
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
88-
sudo chown $(id -u):$(id -g) $HOME/.kube/config
89-
```
85+
```sh
86+
mkdir -p $HOME/.kube
87+
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
88+
sudo chown $(id -u):$(id -g) $HOME/.kube/config
89+
```
9090

9191
4. Deploy the flannel CNI plugin:
9292

93-
```sh
94-
kubectl apply -f https://github.com/flannel-io/flannel/releases/latest/download/kube-flannel.yml
95-
```
93+
```sh
94+
kubectl apply -f https://github.com/flannel-io/flannel/releases/latest/download/kube-flannel.yml
95+
```
9696

9797
5. Patch the flannel deployment to tolerate the `uninitialized` taint:
9898

99-
```sh
100-
kubectl -n kube-system patch ds kube-flannel-ds --type json -p '[{"op":"add","path":"/spec/template/spec/tolerations/-","value":{"key":"node.cloudprovider.kubernetes.io/uninitialized","value":"true","effect":"NoSchedule"}}]'
101-
```
99+
```sh
100+
kubectl -n kube-system patch ds kube-flannel-ds --type json -p '[{"op":"add","path":"/spec/template/spec/tolerations/-","value":{"key":"node.cloudprovider.kubernetes.io/uninitialized","value":"true","effect":"NoSchedule"}}]'
101+
```
102102

103103
6. Create a secret containing your Hetzner Cloud API token.
104104

105-
```sh
106-
kubectl -n kube-system create secret generic hcloud --from-literal=token=<hcloud API token>
107-
```
105+
```sh
106+
kubectl -n kube-system create secret generic hcloud --from-literal=token=<hcloud API token>
107+
```
108108

109109
7. Deploy `hcloud-cloud-controller-manager`
110110

111-
**Using Helm (recommended):**
111+
**Using Helm (recommended):**
112112

113-
```
114-
helm repo add hcloud https://charts.hetzner.cloud
115-
helm repo update hcloud
116-
helm install hccm hcloud/hcloud-cloud-controller-manager -n kube-system
117-
```
113+
```
114+
helm repo add hcloud https://charts.hetzner.cloud
115+
helm repo update hcloud
116+
helm install hccm hcloud/hcloud-cloud-controller-manager -n kube-system
117+
```
118118
119-
See the [Helm chart README](./chart/README.md) for more info.
119+
See the [Helm chart README](./chart/README.md) for more info.
120120
121-
**Legacy installation method**:
121+
**Legacy installation method**:
122122
123-
```sh
124-
kubectl apply -f https://github.com/hetznercloud/hcloud-cloud-controller-manager/releases/latest/download/ccm.yaml
125-
```
123+
```sh
124+
kubectl apply -f https://github.com/hetznercloud/hcloud-cloud-controller-manager/releases/latest/download/ccm.yaml
125+
```
126126

127127
[kubeadm-config]: https://kubernetes.io/docs/reference/config-api/kubeadm-config.v1beta4/#kubeadm-k8s-io-v1beta4-NodeRegistrationOptions
128128

@@ -179,7 +179,7 @@ Current Kubernetes Releases: https://kubernetes.io/releases/
179179
### With Networks support
180180

181181
| Kubernetes | Cloud Controller Manager | Deployment File |
182-
|------------|-------------------------:|------------------------------------------------------------------------------------------------------------:|
182+
| ---------- | -----------------------: | ----------------------------------------------------------------------------------------------------------: |
183183
| 1.30 | latest | https://github.com/hetznercloud/hcloud-cloud-controller-manager/releases/latest/download/ccm-networks.yaml |
184184
| 1.29 | latest | https://github.com/hetznercloud/hcloud-cloud-controller-manager/releases/latest/download/ccm-networks.yaml |
185185
| 1.28 | latest | https://github.com/hetznercloud/hcloud-cloud-controller-manager/releases/latest/download/ccm-networks.yaml |
@@ -192,7 +192,7 @@ Current Kubernetes Releases: https://kubernetes.io/releases/
192192
### Without Networks support
193193

194194
| Kubernetes | Cloud Controller Manager | Deployment File |
195-
|------------|-------------------------:|---------------------------------------------------------------------------------------------------:|
195+
| ---------- | -----------------------: | -------------------------------------------------------------------------------------------------: |
196196
| 1.30 | latest | https://github.com/hetznercloud/hcloud-cloud-controller-manager/releases/latest/download/ccm.yaml |
197197
| 1.29 | latest | https://github.com/hetznercloud/hcloud-cloud-controller-manager/releases/latest/download/ccm.yaml |
198198
| 1.28 | latest | https://github.com/hetznercloud/hcloud-cloud-controller-manager/releases/latest/download/ccm.yaml |

chart/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,5 +57,5 @@ You can choose between different deployment options. By default the chart will d
5757
If you want to change the replica count you can adjust the value `replicaCount` inside the helm values.
5858
If you have more than 1 replica leader election will be turned on automatically.
5959

60-
If you want to deploy hccm as a DaemonSet you can set `kind` to `DaemonSet` inside the values.
60+
If you want to deploy hccm as a DaemonSet you can set `kind` to `DaemonSet` inside the values.
6161
To adjust on which nodes the DaemonSet should be deployed you can use the `nodeSelector` and `additionalTolerations` values.

chart/templates/daemonset.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,9 @@ spec:
4545
{{- if gt (len .Values.additionalTolerations) 0 }}
4646
{{ toYaml .Values.additionalTolerations | nindent 8 }}
4747
{{- end }}
48-
48+
4949
{{- if gt (len .Values.nodeSelector) 0 }}
50-
nodeSelector:
50+
nodeSelector:
5151
{{ toYaml .Values.nodeSelector | nindent 8 }}
5252
{{- end }}
5353

chart/templates/deployment.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,9 @@ spec:
4646
{{- if gt (len .Values.additionalTolerations) 0 }}
4747
{{ toYaml .Values.additionalTolerations | nindent 8 }}
4848
{{- end }}
49-
49+
5050
{{- if gt (len .Values.nodeSelector) 0 }}
51-
nodeSelector:
51+
nodeSelector:
5252
{{ toYaml .Values.nodeSelector | nindent 8 }}
5353
{{- end }}
5454

chart/values.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ env:
6060

6161
image:
6262
repository: docker.io/hetznercloud/hcloud-cloud-controller-manager
63-
tag: 'v{{ $.Chart.Version }}'
63+
tag: "v{{ $.Chart.Version }}"
6464

6565
monitoring:
6666
# When enabled, the hccm Pod will serve metrics on port :8233
@@ -79,7 +79,6 @@ monitoring:
7979
spec:
8080
podMetricsEndpoints:
8181
- port: metrics
82-
8382

8483
nameOverride: ~
8584

@@ -103,12 +102,13 @@ resources:
103102

104103
selectorLabels:
105104
app.kubernetes.io/name: '{{ include "hcloud-cloud-controller-manager.name" $ }}'
106-
app.kubernetes.io/instance: '{{ $.Release.Name }}'
105+
app.kubernetes.io/instance: "{{ $.Release.Name }}"
107106

108107
additionalTolerations: []
109108

109+
# nodeSelector:
110+
# node-role.kubernetes.io/control-plane: ""
110111
nodeSelector: {}
111-
# node-role.kubernetes.io/control-plane: ""
112112

113113
# Set the affinity for pods. (Only works with kind=Deployment)
114114
affinity: {}

deploy/kustomization.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
apiVersion: kustomize.config.k8s.io/v1beta1
22
kind: Kustomization
33
resources:
4-
# Toggle between ccm and ccm-networks for skaffold testing
5-
- ccm.yaml
6-
#- ccm-networks.yaml
4+
# Toggle between ccm and ccm-networks for skaffold testing
5+
- ccm.yaml
6+
# - ccm-networks.yaml

docs/deploy_with_networks.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@ If you would like to use the version without using our Networks feature, you can
66
We assume, that you have knowledge about Kubernetes and the Hetzner Cloud.
77

88
## How to deploy
9-
1. Create a new Network via `hcloud-cli` (`hcloud network create --name my-network --ip-range=10.0.0.0/8`)or the [Hetzner Cloud Console](https://console.hetzner.cloud)
10-
2. Add each Node of the Cluster to the Hetzner Cloud Network
11-
3. Download the latest deployment file with networks support from [Github](https://github.com/hetznercloud/hcloud-cloud-controller-manager/releases/latest) to your local machine
12-
4. Change the `--cluster-cidr=` flag in the deployment file to fit your pod range. Default is `10.244.0.0/16`.
13-
5. Create a new secret containing a Hetzner Cloud API Token and the name or the ID of the Network you want to use `kubectl -n kube-system create secret generic hcloud --from-literal=token=<hcloud API token> --from-literal=network=<hcloud Network_ID_or_Name>`
14-
6. Deploy the deployment file `kubectl -n kube-system apply -f path/to/your/deployment.yaml`
15-
7. (Recommended) Deploy a CNI (like Cilium `kubectl create -f https://raw.githubusercontent.com/cilium/cilium/v1.5/examples/kubernetes/<kubernetes-version>/cilium.yaml` - please replace `<kubernetes-version>` with your version like `1.15`)
169

10+
1. Create a new Network via `hcloud-cli` (`hcloud network create --name my-network --ip-range=10.0.0.0/8`)or the [Hetzner Cloud Console](https://console.hetzner.cloud)
11+
2. Add each Node of the Cluster to the Hetzner Cloud Network
12+
3. Download the latest deployment file with networks support from [Github](https://github.com/hetznercloud/hcloud-cloud-controller-manager/releases/latest) to your local machine
13+
4. Change the `--cluster-cidr=` flag in the deployment file to fit your pod range. Default is `10.244.0.0/16`.
14+
5. Create a new secret containing a Hetzner Cloud API Token and the name or the ID of the Network you want to use `kubectl -n kube-system create secret generic hcloud --from-literal=token=<hcloud API token> --from-literal=network=<hcloud Network_ID_or_Name>`
15+
6. Deploy the deployment file `kubectl -n kube-system apply -f path/to/your/deployment.yaml`
16+
7. (Recommended) Deploy a CNI (like Cilium `kubectl create -f https://raw.githubusercontent.com/cilium/cilium/v1.5/examples/kubernetes/<kubernetes-version>/cilium.yaml` - please replace `<kubernetes-version>` with your version like `1.15`)
1717

1818
When deploying Cilium, make sure that you have set `tunnel: disabled` and `nativeRoutingCIDR` to your clusters subnet CIDR. If you are using Cilium < 1.9.0 you also have to set `blacklist-conflicting-routes: false`.
1919

@@ -23,7 +23,7 @@ After this, you should be able to see the correct routes in the [Hetzner Cloud C
2323

2424
The `cluster-cidr` Range must be **within the Hetzner Cloud Network Range**, but **must not overlap with any created subnets**. By default, Kubernetes assigns a `/24` (254 addresses) per Node. Changing the range later on is possible, but requires some work. You should assign a range that is large enough to fit enough nodes. For example, if you plan to use a cluster with 10 nodes, you need to assign at least a `/20` (16 x `/24`) to the `cluster-cidr` flag.
2525

26-
The `service-cidr` Range can be within the Hetzner Cloud Network Range, as long as it does not overlap with any other Subnets.
26+
The `service-cidr` Range can be within the Hetzner Cloud Network Range, as long as it does not overlap with any other Subnets.
2727

2828
Some example values:
2929

0 commit comments

Comments
 (0)