Skip to content

Commit e384ae4

Browse files
authored
Initial working setup
1 parent c5841af commit e384ae4

93 files changed

Lines changed: 6556 additions & 1046 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/lint.yml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
name: Lint
2+
3+
on:
4+
push:
5+
pull_request:
6+
7+
jobs:
8+
golangci-lint:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- name: Clone the code
12+
uses: actions/checkout@v4
13+
14+
- name: Setup Go
15+
uses: actions/setup-go@v5
16+
with:
17+
go-version-file: go.mod
18+
19+
- name: Run linter
20+
uses: golangci/golangci-lint-action@v7
21+
with:
22+
version: v2.3.0
23+
24+
buf-lint:
25+
runs-on: ubuntu-latest
26+
steps:
27+
- name: Clone the code
28+
uses: actions/checkout@v4
29+
30+
- name: Install the `buf` CLI
31+
uses: bufbuild/buf-setup-action@v1
32+
33+
- name: Run buf lint
34+
uses: bufbuild/buf-lint-action@v1

.github/workflows/test-chart.yml

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
name: Test Chart
2+
3+
on:
4+
push:
5+
pull_request:
6+
7+
jobs:
8+
test-chart:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- name: Clone the code
12+
uses: actions/checkout@v4
13+
14+
- name: Setup Go
15+
uses: actions/setup-go@v5
16+
with:
17+
go-version-file: go.mod
18+
19+
- name: Install the latest version of kind
20+
run: |
21+
curl -Lo ./kind https://kind.sigs.k8s.io/dl/latest/kind-linux-amd64
22+
chmod +x ./kind
23+
sudo mv ./kind /usr/local/bin/kind
24+
25+
- name: Verify kind installation
26+
run: kind version
27+
28+
- name: Create kind cluster
29+
run: kind create cluster
30+
31+
- name: Prepare nodedrain
32+
run: |
33+
go mod tidy
34+
make docker-build IMG_NAME_CONTROLLER=nodedrain IMG_TAG=v0.1.0
35+
kind load docker-image IMG_NAME_CONTROLLER=nodedrain IMG_TAG=v0.1.0
36+
37+
- name: Install Helm
38+
run: |
39+
curl https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3 | bash
40+
41+
- name: Verify Helm installation
42+
run: helm version
43+
44+
- name: Lint Helm Chart
45+
run: |
46+
helm lint ./dist/chart
47+
48+
- name: Install cert-manager via Helm
49+
run: |
50+
helm repo add jetstack https://charts.jetstack.io
51+
helm repo update
52+
helm install cert-manager jetstack/cert-manager --namespace cert-manager --create-namespace --set installCRDs=true
53+
54+
- name: Wait for cert-manager to be ready
55+
run: |
56+
kubectl wait --namespace cert-manager --for=condition=available --timeout=300s deployment/cert-manager
57+
kubectl wait --namespace cert-manager --for=condition=available --timeout=300s deployment/cert-manager-cainjector
58+
kubectl wait --namespace cert-manager --for=condition=available --timeout=300s deployment/cert-manager-webhook
59+
# TODO: Uncomment if Prometheus is enabled
60+
# - name: Install Prometheus Operator CRDs
61+
# run: |
62+
# helm repo add prometheus-community https://prometheus-community.github.io/helm-charts
63+
# helm repo update
64+
# helm install prometheus-crds prometheus-community/prometheus-operator-crds
65+
#
66+
# - name: Install Prometheus via Helm
67+
# run: |
68+
# helm repo add prometheus-community https://prometheus-community.github.io/helm-charts
69+
# helm repo update
70+
# helm install prometheus prometheus-community/prometheus --namespace monitoring --create-namespace
71+
#
72+
# - name: Wait for Prometheus to be ready
73+
# run: |
74+
# kubectl wait --namespace monitoring --for=condition=available --timeout=300s deployment/prometheus-server
75+
76+
- name: Install Helm chart for project
77+
run: |
78+
helm install my-release ./dist/chart --create-namespace --namespace nodedrain-system
79+
80+
- name: Check Helm release status
81+
run: |
82+
helm status my-release --namespace nodedrain-system
83+
84+
# TODO: Uncomment if prometheus.enabled is set to true to confirm that the ServiceMonitor gets created
85+
# - name: Check Presence of ServiceMonitor
86+
# run: |
87+
# kubectl wait --namespace nodedrain-system --for=jsonpath='{.kind}'=ServiceMonitor servicemonitor/nodedrain-controller-manager-metrics-monitor

.github/workflows/test-e2e.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
name: E2E Tests
2+
3+
on:
4+
push:
5+
pull_request:
6+
7+
jobs:
8+
test-e2e:
9+
name: Run on Ubuntu
10+
runs-on: ubuntu-latest
11+
steps:
12+
- name: Clone the code
13+
uses: actions/checkout@v4
14+
15+
- name: Setup Go
16+
uses: actions/setup-go@v5
17+
with:
18+
go-version-file: go.mod
19+
20+
- name: Install the latest version of kind
21+
run: |
22+
curl -Lo ./kind https://kind.sigs.k8s.io/dl/latest/kind-linux-amd64
23+
chmod +x ./kind
24+
sudo mv ./kind /usr/local/bin/kind
25+
26+
- name: Verify kind installation
27+
run: kind version
28+
29+
- name: Running Test e2e
30+
run: |
31+
go mod tidy
32+
make test-e2e

.github/workflows/test.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
name: Tests
2+
3+
on:
4+
push:
5+
pull_request:
6+
7+
jobs:
8+
test:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- name: Clone the code
12+
uses: actions/checkout@v4
13+
14+
- name: Setup Go
15+
uses: actions/setup-go@v5
16+
with:
17+
go-version-file: go.mod
18+
19+
- name: Running Tests
20+
run: |
21+
go mod tidy
22+
make test

.gitignore

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
# Binaries for programs and plugins
32
*.exe
43
*.exe~
@@ -8,14 +7,16 @@
87
bin/*
98
Dockerfile.cross
109

11-
# Test binary, build with `go test -c`
10+
# Test binary, built with `go test -c`
1211
*.test
1312

1413
# Output of the go coverage tool, specifically when used with LiteIDE
1514
*.out
1615

17-
# Kubernetes Generated files - skip generated files, except for vendored files
16+
# Go workspace file
17+
go.work
1818

19+
# Kubernetes Generated files - skip generated files, except for vendored files
1920
!vendor/**/zz_generated.*
2021

2122
# editor and IDE paraphernalia

.golangci.yml

Lines changed: 30 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,15 @@
1+
version: "2"
12
run:
2-
timeout: 5m
33
allow-parallel-runners: true
4-
5-
issues:
6-
# don't skip warning about doc comments
7-
# don't exclude the default set of lint
8-
exclude-use-default: false
9-
# restore some of the defaults
10-
# (fill in the rest as needed)
11-
exclude-rules:
12-
- path: "api/*"
13-
linters:
14-
- lll
15-
- path: "internal/*"
16-
linters:
17-
- dupl
18-
- lll
194
linters:
20-
disable-all: true
5+
default: none
216
enable:
7+
- copyloopvar
228
- dupl
239
- errcheck
24-
- exportloopref
2510
- ginkgolinter
2611
- goconst
2712
- gocyclo
28-
- gofmt
29-
- goimports
30-
- gosimple
3113
- govet
3214
- ineffassign
3315
- lll
@@ -36,12 +18,34 @@ linters:
3618
- prealloc
3719
- revive
3820
- staticcheck
39-
- typecheck
4021
- unconvert
4122
- unparam
4223
- unused
43-
44-
linters-settings:
45-
revive:
24+
settings:
25+
revive:
26+
rules:
27+
- name: comment-spacings
28+
exclusions:
29+
generated: lax
4630
rules:
47-
- name: comment-spacings
31+
- linters:
32+
- lll
33+
path: api/*
34+
- linters:
35+
- dupl
36+
- lll
37+
path: internal/*
38+
paths:
39+
- third_party$
40+
- builtin$
41+
- examples$
42+
formatters:
43+
enable:
44+
- gofmt
45+
- goimports
46+
exclusions:
47+
generated: lax
48+
paths:
49+
- third_party$
50+
- builtin$
51+
- examples$

Dockerfile

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Build the manager binary
2-
FROM golang:1.23.2 AS builder
2+
FROM golang:1.24.5 AS builder
33
ARG TARGETOS
44
ARG TARGETARCH
55

@@ -21,11 +21,24 @@ COPY internal/ internal/
2121
# was called. For example, if we call make docker-build in a local env which has the Apple Silicon M1 SO
2222
# the docker BUILDPLATFORM arg will be linux/arm64 when for Apple x86 it will be linux/amd64. Therefore,
2323
# by leaving it empty we can ensure that the container and binary shipped on it will have the same platform.
24-
RUN CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} go build -a -o manager cmd/main.go
24+
RUN --mount=type=cache,target=/root/.cache \
25+
CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} go build -o manager cmd/main.go
26+
27+
28+
FROM builder AS builder-plugin
29+
COPY examples/ examples/
30+
RUN --mount=type=cache,target=/root/.cache \
31+
CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} go build -o example-plugin.so examples/plugin/example-plugin.go
32+
33+
FROM alpine:3.22.1 AS example-plugin
34+
WORKDIR /
35+
COPY --from=builder-plugin /workspace/example-plugin.so .
36+
USER 65532:65532
37+
CMD ["cp", "-v", "/example-plugin.so", "/plugins/example-plugin.so"]
2538

2639
# Use distroless as minimal base image to package the manager binary
2740
# Refer to https://github.com/GoogleContainerTools/distroless for more details
28-
FROM gcr.io/distroless/static:nonroot
41+
FROM gcr.io/distroless/static:debug-nonroot AS controller
2942
WORKDIR /
3043
COPY --from=builder /workspace/manager .
3144
USER 65532:65532

0 commit comments

Comments
 (0)