From e0ac2e8b80fff3817721b96beaf25785de2ac912 Mon Sep 17 00:00:00 2001 From: Amir Mofasser Date: Thu, 17 Oct 2024 10:12:19 +0200 Subject: [PATCH] Allow passing `volumes` & `volumeMounts` in values (#95) * Allow passing `volumes` & `volumeMounts` in values * Format YAML * Updates to CI --- .github/workflows/go.yaml | 84 +++++++------- .github/workflows/release.yaml | 104 +++++++++--------- Makefile | 43 ++------ charts/node-cert-exporter/Chart.yaml | 8 +- .../templates/daemonset.yaml | 15 ++- charts/node-cert-exporter/values.yaml | 15 ++- 6 files changed, 121 insertions(+), 148 deletions(-) diff --git a/.github/workflows/go.yaml b/.github/workflows/go.yaml index d141111..88ad229 100644 --- a/.github/workflows/go.yaml +++ b/.github/workflows/go.yaml @@ -2,66 +2,56 @@ name: Go on: push: - branches: [ master ] + branches: [master] pull_request: - branches: [ master ] + branches: [master] jobs: - verify: + staticcheck: runs-on: ubuntu-22.04 steps: - - uses: actions/checkout@v4 + - uses: actions/checkout@v4 - - name: Set up Go - uses: actions/setup-go@v4 - with: - go-version: '>=1.21.0' + - name: Set up Go + uses: actions/setup-go@v5 + with: + go-version: 1.21 - - name: Check Formating - run: make checkfmt - - name: Format Code - run: make fmt - - name: Go Vet - run: make vet - - name: Go Race - run: make race - - name: Gocyclo - run: make gocyclo - - name: Lint - run: make lint - - name: Ineffassign - run: make ineffassign - - name: Misspell - run: make misspell - - name: Helm Lint - run: make helm_lint + - name: Lint + run: make lint + - name: Go Vet + run: make vet + - name: Helm Lint + run: make helm_lint test: runs-on: ubuntu-22.04 steps: - - uses: actions/checkout@v4 + - uses: actions/checkout@v4 + + - name: Set up Go + uses: actions/setup-go@v5 + with: + go-version: 1.21 + + - name: Test + run: make test + - name: Race + run: make race + - name: Benchmark + run: make benchmark + - name: Coverage + run: make coverage - - name: Set up Go - uses: actions/setup-go@v4 - with: - go-version: '>=1.21.0' - - - name: Test - run: make test - - name: Benchmark - run: make benchmark - - name: Coverage - run: make coverage - build: runs-on: ubuntu-22.04 steps: - - uses: actions/checkout@v4 + - uses: actions/checkout@v4 + + - name: Set up Go + uses: actions/setup-go@v5 + with: + go-version: ">=1.21.0" - - name: Set up Go - uses: actions/setup-go@v4 - with: - go-version: '>=1.21.0' - - - name: Compile - run: make + - name: Compile + run: make diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 3aaa605..a23103f 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -3,9 +3,9 @@ name: Release on: push: tags: - - "v*" + - "v*" branches: - - "master" + - "master" env: REGISTRY: ghcr.io @@ -15,60 +15,60 @@ jobs: helm: runs-on: ubuntu-22.04 steps: - - uses: actions/checkout@v4 - 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.0 - - - name: Run chart-releaser - uses: helm/chart-releaser-action@v1.2.0 - env: - CR_TOKEN: "${{ secrets.GITHUB_TOKEN }}" - + - uses: actions/checkout@v4 + 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@v3 + with: + version: v3.13.3 + + - name: Run chart-releaser + uses: helm/chart-releaser-action@v1.6.0 + env: + CR_TOKEN: "${{ secrets.GITHUB_TOKEN }}" + releases: if: startsWith(github.ref, 'refs/tags/v') runs-on: ubuntu-22.04 steps: - - uses: actions/checkout@v4 - - - name: Set up Go - uses: actions/setup-go@v4 - with: - go-version: '>=1.21.0' - - - name: Build Binaries - run: | - # Linux - GOOS=linux GOARCH=amd64 BUILDPATH=./bin/node-cert-exporter-linux-amd64 make - GOOS=linux GOARCH=arm BUILDPATH=./bin/node-cert-exporter-linux-arm make - GOOS=linux GOARCH=arm64 BUILDPATH=./bin/node-cert-exporter-linux-arm64 make - GOOS=linux GOARCH=386 BUILDPATH=./bin/node-cert-exporter-linux-386 make - # Windows - GOOS=windows GOARCH=amd64 BUILDPATH=./bin/node-cert-exporter-windows-amd64.exe make - GOOS=windows GOARCH=arm BUILDPATH=./bin/node-cert-exporter-windows-arm.exe make - GOOS=windows GOARCH=386 BUILDPATH=./bin/node-cert-exporter-windows-386.exe make - # Darwin - GOOS=darwin GOARCH=amd64 BUILDPATH=./bin/node-cert-exporter-darwin-amd64 make - GOOS=darwin GOARCH=arm64 BUILDPATH=./bin/node-cert-exporter-darwin-arm64 make - # Freebsd - GOOS=freebsd GOARCH=amd64 BUILDPATH=./bin/node-cert-exporter-freebsd-amd64 make - GOOS=freebsd GOARCH=386 BUILDPATH=./bin/node-cert-exporter-freebsd-386 make - GOOS=freebsd GOARCH=arm BUILDPATH=./bin/node-cert-exporter-freebsd-arm make - - - name: Create Release - uses: ncipollo/release-action@v1 - with: - draft: true - artifacts: "./bin/*" + - uses: actions/checkout@v4 + + - name: Set up Go + uses: actions/setup-go@v5 + with: + go-version: ">=1.21.0" + + - name: Build Binaries + run: | + # Linux + GOOS=linux GOARCH=amd64 BUILDPATH=./bin/node-cert-exporter-linux-amd64 make + GOOS=linux GOARCH=arm BUILDPATH=./bin/node-cert-exporter-linux-arm make + GOOS=linux GOARCH=arm64 BUILDPATH=./bin/node-cert-exporter-linux-arm64 make + GOOS=linux GOARCH=386 BUILDPATH=./bin/node-cert-exporter-linux-386 make + # Windows + GOOS=windows GOARCH=amd64 BUILDPATH=./bin/node-cert-exporter-windows-amd64.exe make + GOOS=windows GOARCH=arm BUILDPATH=./bin/node-cert-exporter-windows-arm.exe make + GOOS=windows GOARCH=386 BUILDPATH=./bin/node-cert-exporter-windows-386.exe make + # Darwin + GOOS=darwin GOARCH=amd64 BUILDPATH=./bin/node-cert-exporter-darwin-amd64 make + GOOS=darwin GOARCH=arm64 BUILDPATH=./bin/node-cert-exporter-darwin-arm64 make + # Freebsd + GOOS=freebsd GOARCH=amd64 BUILDPATH=./bin/node-cert-exporter-freebsd-amd64 make + GOOS=freebsd GOARCH=386 BUILDPATH=./bin/node-cert-exporter-freebsd-386 make + GOOS=freebsd GOARCH=arm BUILDPATH=./bin/node-cert-exporter-freebsd-arm make + + - name: Create Release + uses: ncipollo/release-action@v1 + with: + draft: true + artifacts: "./bin/*" packages: if: startsWith(github.ref, 'refs/tags/v') diff --git a/Makefile b/Makefile index 07a3764..1c9f719 100644 --- a/Makefile +++ b/Makefile @@ -47,45 +47,18 @@ $(INTDIR): @mkdir -p $@ $(TBIN)/%: | $(TBIN) ; $(info $(M) building $(PACKAGE)) $Q tmp=$$(mktemp -d); \ - env GO111MODULE=off GOPATH=$$tmp GOBIN=$(TBIN) $(GO) get $(PACKAGE) \ + env GOBIN=$(TBIN) $(GO) install $(PACKAGE) \ || ret=$$?; \ - rm -rf $$tmp ; exit $$ret + #rm -rf $$tmp ; exit $$ret -GOLINT = $(TBIN)/golint -$(BIN)/golint: PACKAGE=golang.org/x/lint/golint - -GOCYCLO = $(TBIN)/gocyclo -$(TBIN)/gocyclo: PACKAGE=github.com/fzipp/gocyclo/cmd/gocyclo - -INEFFASSIGN = $(TBIN)/ineffassign -$(TBIN)/ineffassign: PACKAGE=github.com/gordonklaus/ineffassign - -MISSPELL = $(TBIN)/misspell -$(TBIN)/misspell: PACKAGE=github.com/client9/misspell/cmd/misspell - -GOLINT = $(TBIN)/golint -$(TBIN)/golint: PACKAGE=golang.org/x/lint/golint - -GOCOV = $(TBIN)/gocov -$(TBIN)/gocov: PACKAGE=github.com/axw/gocov/... +GOCILINT = $(TBIN)/golangci-lint +$(TBIN)/golangci-lint: PACKAGE=github.com/golangci/golangci-lint/cmd/golangci-lint@v1.57.2 # Tests .PHONY: lint -lint: | $(GOLINT) ; $(info $(M) running golint) @ ## Runs the golint command - $Q $(GOLINT) -set_exit_status $(PKGS) - -.PHONY: gocyclo -gocyclo: | $(GOCYCLO) ; $(info $(M) running gocyclo) @ ## Calculates cyclomatic complexities of functions in Go source code - $Q $(GOCYCLO) -over 25 . - -.PHONY: ineffassign -ineffassign: | $(INEFFASSIGN) ; $(info $(M) running ineffassign) @ ## Detects ineffectual assignments in Go code - $Q $(INEFFASSIGN) ./... - -.PHONY: misspell -misspell: | $(MISSPELL) ; $(info $(M) running misspell) @ ## Finds commonly misspelled English words - $Q $(MISSPELL) . +lint: | $(GOCILINT) ; $(info $(M) running golangci-lint) @ ## Runs static code analysis using golangci-lint + $Q $(GOCILINT) run --timeout=5m .PHONY: test test: ; $(info $(M) running go test) @ ## Runs unit tests @@ -117,7 +90,7 @@ checkfmt: ; $(info $(M) running checkfmt) @ ## Checks if code is formatted with @test "$(shell $(SRC_FILES) gofmt -l)" = "" \ || { echo "Code not formatted, please run 'make fmt'"; exit 2; } -.PHONY: checkfmt +.PHONY: integration-test integration-test: | $(INTDIR) docker_build ; $(info $(M) running integration tests) @ ## Run integration tests mkdir -p ${INTDIR}/ssl openssl req -new -newkey rsa:1024 -days 365 -nodes -x509 \ @@ -169,4 +142,4 @@ version: ## Print version information clean: ; $(info $(M) cleaning) @ ## Cleanup everything @rm -rfv $(BIN) @rm -rfv $(TBIN) - @rm -rfv $(CURDIR)/test \ No newline at end of file + @rm -rfv $(CURDIR)/test diff --git a/charts/node-cert-exporter/Chart.yaml b/charts/node-cert-exporter/Chart.yaml index 04bcf70..22d5b1b 100644 --- a/charts/node-cert-exporter/Chart.yaml +++ b/charts/node-cert-exporter/Chart.yaml @@ -3,8 +3,8 @@ name: node-cert-exporter description: A Helm chart for node-cert-exporter - An SSL certificate Prometheus exporter home: https://github.com/amimof/node-cert-exporter maintainers: -- name: amimof - url: https://github.com/amimof + - name: amimof + url: https://github.com/amimof # A chart can be either an 'application' or a 'library' chart. # # Application charts are a collection of templates that can be packaged into versioned archives @@ -18,11 +18,11 @@ type: application # This is the chart version. This version number should be incremented each time you make changes # to the chart and its templates, including the app version. # Versions are expected to follow Semantic Versioning (https://semver.org/) -version: 1.1.6 +version: 1.1.7 # This is the version number of the application being deployed. This version number should be # incremented each time you make changes to the application. Versions are not expected to # follow Semantic Versioning. They should reflect the version the application is using. appVersion: "1.1.6" sources: -- https://github.com/amimof/node-cert-exporter \ No newline at end of file + - https://github.com/amimof/node-cert-exporter diff --git a/charts/node-cert-exporter/templates/daemonset.yaml b/charts/node-cert-exporter/templates/daemonset.yaml index 65dd2a6..acc5d89 100644 --- a/charts/node-cert-exporter/templates/daemonset.yaml +++ b/charts/node-cert-exporter/templates/daemonset.yaml @@ -42,18 +42,17 @@ spec: protocol: TCP resources: {{- toYaml .Values.resources | nindent 12 }} + {{- with .Values.volumeMounts }} volumeMounts: - - mountPath: /host/etc - name: etc - readOnly: true + {{- toYaml . | nindent 12 }} + {{- end }} {{- with .Values.tolerations }} tolerations: {{- toYaml . | nindent 8 }} {{- end }} + {{- with .Values.volumes }} volumes: - - hostPath: - path: /etc - type: "" - name: etc + {{- toYaml . | nindent 8 }} + {{- end }} updateStrategy: - type: RollingUpdate \ No newline at end of file + type: RollingUpdate diff --git a/charts/node-cert-exporter/values.yaml b/charts/node-cert-exporter/values.yaml index ef6ba64..679e22e 100644 --- a/charts/node-cert-exporter/values.yaml +++ b/charts/node-cert-exporter/values.yaml @@ -12,8 +12,8 @@ paths: - /host/etc/kubernetes/pki/ podAnnotations: - prometheus.io/scrape: 'true' - prometheus.io/port: '9117' + prometheus.io/scrape: "true" + prometheus.io/port: "9117" tolerations: # Allow running on masters: @@ -30,3 +30,14 @@ resources: requests: cpu: 100m memory: 128Mi + +volumes: + - hostPath: + path: /etc + type: "" + name: etc + +volumeMounts: + - mountPath: /host/etc + name: etc + readOnly: true