Skip to content

Commit

Permalink
TLC on the build and release process
Browse files Browse the repository at this point in the history
  • Loading branch information
cnmcavoy committed Oct 17, 2023
1 parent bb47dcf commit 14338ab
Show file tree
Hide file tree
Showing 15 changed files with 360 additions and 853 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
bin
bin/*
cover.out
.idea
.idea
.tagmanifest
84 changes: 84 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
timeout: 3m

linters-settings:
goconst:
min-len: 3
min-occurrences: 3
gocritic:
enabled-tags:
- diagnostic
- experimental
- opinionated
- performance
- style
disabled-checks:
- dupImport # https://github.com/go-critic/go-critic/issues/845
- ifElseChain
- octalLiteral
- paramTypeCombine
- whyNoLint
- wrapperFunc
- importShadow
- unnamedResult
- unnecessaryBlock
- unnecessaryDefer
settings:
rangeValCopy:
sizeThreshold: 512
hugeParam:
sizeThreshold: 512
gocyclo:
min-complexity: 16
golint:
min-confidence: 0
govet:
check-shadowing: false
lll:
line-length: 300
misspell:
locale: US

issues:
exclude-rules:
# Disable linters that are annoying in tests.
- path: _test\.go
linters: [gochecknoglobals, bodyclose, gocritic, gosec, staticcheck, stylecheck]

linters:
disable-all: true
enable:
- asasalint
- asciicheck
- bidichk
- bodyclose
- contextcheck
- depguard
- dogsled
- dupl
- durationcheck
- errcheck
- execinquery
- exhaustive
- exportloopref
- gochecknoglobals
- gochecknoinits
- gocritic
- godot
- gofmt
- gosec
- gosimple
- govet
- ineffassign
- lll
- misspell
- nolintlint
- prealloc
- revive
- rowserrcheck
- sqlclosecheck
- staticcheck
- stylecheck
- tenv
- typecheck
- unconvert
- unparam
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [0.3.0] - 2023-10-17
### Changed
- Updated dependencies on k8s apis

## [0.2.0] - 2022-03-29
### Changed
- Removed volumeID from prometheus metrics tags
Expand Down
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Build the binary
FROM --platform=$BUILDPLATFORM golang:1.20 as builder
FROM --platform=$BUILDPLATFORM golang:1.21 as builder

ARG BUILDPLATFORM
ARG TARGETARCH
Expand All @@ -20,7 +20,7 @@ COPY pkg/ pkg/
# Build
RUN CGO_ENABLED=0 GOOS=linux GOARCH=$TARGETARCH go build -a -o ccm-csi-plugin cmd/ccm-csi-plugin/main.go

FROM alpine:3.17
FROM alpine:3.18

RUN apk add --no-cache ca-certificates e2fsprogs findmnt

Expand Down
63 changes: 16 additions & 47 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ ARCH = amd64
BUILD_ARGS ?=

DOCKER_BUILD_PLATFORMS = linux/amd64,linux/arm64
DOCKER_BUILDX_BUILDER ?= "mybuilder"
DOCKER_BUILDX_BUILDER ?= "cluster-config-maps"

# default target is build
.DEFAULT_GOAL := all
Expand All @@ -26,12 +26,7 @@ HELM_DIR ?= deploy/charts/cluster-config-maps

OUTPUT_DIR ?= bin

# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
ifeq (,$(shell go env GOBIN))
GOBIN=$(shell go env GOPATH)/bin
else
GOBIN=$(shell go env GOBIN)
endif
RUN_GOLANGCI_LINT := go run github.com/golangci/golangci-lint/cmd/[email protected]

# check if there are any existing `git tag` values
ifeq ($(shell git tag),)
Expand All @@ -42,6 +37,11 @@ else
VERSION ?= $(shell git describe --dirty --always --tags --exclude 'helm*' | sed 's/-/./2' | sed 's/-/./2')
endif

# RELEASE_TAG is tag to promote. Default is promoting to main branch, but can be overriden
# to promote a tag to a specific version.
RELEASE_TAG ?= main
SOURCE_TAG ?= $(VERSION)

# ====================================================================================
# Colors

Expand Down Expand Up @@ -96,30 +96,14 @@ build-%: generate ## Build binary for the specified arch
go build -o '$(OUTPUT_DIR)/ccm-csi-plugin-$*' ./cmd/ccm-csi-plugin/main.go
@$(OK) go build $*

# Check install of golanci-lint
lint.check:
@if ! golangci-lint --version > /dev/null 2>&1; then \
echo -e "\033[0;33mgolangci-lint is not installed: run \`\033[0;32mmake lint.install\033[0m\033[0;33m\` or install it from https://golangci-lint.run\033[0m"; \
exit 1; \
fi

.PHONY: lint-install
lint-install: ## installs golangci-lint to the go bin dir
@if ! golangci-lint --version > /dev/null 2>&1; then \
echo "Installing golangci-lint"; \
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(BIN_DIR) v1.43.0; \
fi

lint: lint.check ## run golangci-lint
@if ! golangci-lint run; then \
echo -e "\033[0;33mgolangci-lint failed: some checks can be fixed with \`\033[0;32mmake fmt\033[0m\033[0;33m\`\033[0m"; \
exit 1; \
fi

fmt: lint.check ## ensure consistent code style
.PHONY: lint
lint: ## run golangci-lint
$(RUN_GOLANGCI_LINT) run

fmt: ## ensure consistent code style
@go mod tidy
@go fmt ./...
@golangci-lint run --fix > /dev/null 2>&1 || true
$(RUN_GOLANGCI_LINT) run --fix > /dev/null 2>&1 || true
@$(OK) Ensured consistent code style

generate: ## Generate code and crds
Expand Down Expand Up @@ -199,31 +183,16 @@ serve-docs:

build.all: docker.build helm.build

docker.build: $(addprefix build-,$(ARCH)) ## Build the docker image
docker.build: docker.buildx.setup ## Build the docker image
@$(INFO) docker build
@docker build . $(BUILD_ARGS) -t $(IMAGE_REGISTRY):$(VERSION)
@docker buildx build --platform $(DOCKER_BUILD_PLATFORMS) -t $(IMAGE_REGISTRY):$(VERSION) $(BUILD_ARGS) --push .
@$(OK) docker build

docker.push:
@$(INFO) docker push
@docker push $(IMAGE_REGISTRY):$(VERSION)
@$(OK) docker push

docker.buildx.setup:
@$(INFO) docker buildx setup
@docker buildx ls 2>/dev/null | grep -q $(DOCKER_BUILDX_BUILDER) || docker buildx create --name $(DOCKER_BUILDX_BUILDER) --driver docker-container --bootstrap --use
@docker buildx ls 2>/dev/null | grep -vq $(DOCKER_BUILDX_BUILDER) || docker buildx create --name $(DOCKER_BUILDX_BUILDER) --driver docker-container --driver-opt network=host --bootstrap --use
@$(OK) docker buildx setup

docker.buildx: docker.buildx.setup
@$(INFO) docker buildx
@docker buildx build --platform $(DOCKER_BUILD_PLATFORMS) -t $(IMAGE_REGISTRY):$(VERSION) $(BUILD_ARGS) --push .
@$(OK) docker buildx

# RELEASE_TAG is tag to promote. Default is promoting to main branch, but can be overriden
# to promote a tag to a specific version.
RELEASE_TAG ?= main
SOURCE_TAG ?= $(VERSION)

docker.promote:
@$(INFO) promoting $(SOURCE_TAG) to $(RELEASE_TAG)
docker manifest inspect $(IMAGE_REGISTRY):$(SOURCE_TAG) > .tagmanifest
Expand Down
1 change: 0 additions & 1 deletion apis/clusterconfigmap/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions deploy/charts/cluster-config-maps/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ apiVersion: v2
name: cluster-config-maps
description: A Helm chart for Kubernetes
type: application
version: 0.2.2
appVersion: 0.2.0
version: 0.3.0
appVersion: 0.3.0
6 changes: 3 additions & 3 deletions deploy/charts/cluster-config-maps/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# cluster-config-maps

![Version: 0.2.1](https://img.shields.io/badge/Version-0.2.1-informational?style=flat-square) ![Type: application](https://img.shields.io/badge/Type-application-informational?style=flat-square) ![AppVersion: 0.2.0](https://img.shields.io/badge/AppVersion-0.2.0-informational?style=flat-square)
![Version: 0.3.0](https://img.shields.io/badge/Version-0.3.0-informational?style=flat-square) ![Type: application](https://img.shields.io/badge/Type-application-informational?style=flat-square) ![AppVersion: 0.3.0](https://img.shields.io/badge/AppVersion-0.3.0-informational?style=flat-square)

A Helm chart for Kubernetes

Expand All @@ -11,8 +11,8 @@ A Helm chart for Kubernetes
| affinity | object | `{}` | |
| fullnameOverride | string | `""` | |
| image.pullPolicy | string | `"IfNotPresent"` | |
| image.repository | string | `"ghcr.io/indeedeng/cluster-config-maps/csi-ccm-plugin"` | |
| image.tag | string | `"dev"` | |
| image.repository | string | `"ghcr.io/indeedeng/cluster-config-maps"` | |
| image.tag | string | `"main"` | |
| imagePullSecrets | list | `[]` | |
| installCRDs | bool | `true` | If set, install and upgrade CRDs through helm chart. |
| maxUnavailable | string | `"15%"` | |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.8.0
creationTimestamp: null
controller-gen.kubebuilder.io/version: v0.13.0
name: clusterconfigmaps.indeed.com
spec:
group: indeed.com
Expand Down Expand Up @@ -48,10 +47,4 @@ spec:
storage: true
subresources:
status: {}
status:
acceptedNames:
kind: ""
plural: ""
conditions: []
storedVersions: []
{{- end }}
2 changes: 1 addition & 1 deletion deploy/charts/cluster-config-maps/templates/daemonset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ spec:
hostNetwork: true
containers:
- name: csi-node-driver-registrar
image: registry.k8s.io/sig-storage/csi-node-driver-registrar:v2.5.0
image: registry.k8s.io/sig-storage/csi-node-driver-registrar:v2.9.0
args:
- "--v=5"
- "--csi-address=$(ADDRESS)"
Expand Down
4 changes: 2 additions & 2 deletions deploy/charts/cluster-config-maps/values.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@

image:
repository: ghcr.io/indeedeng/cluster-config-maps/csi-ccm-plugin
repository: ghcr.io/indeedeng/cluster-config-maps
pullPolicy: IfNotPresent
tag: "dev"
tag: "main"

# -- If set, install and upgrade CRDs through helm chart.
installCRDs: true
Expand Down
9 changes: 1 addition & 8 deletions deploy/crds/indeed.com_clusterconfigmaps.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.8.0
creationTimestamp: null
controller-gen.kubebuilder.io/version: v0.13.0
name: clusterconfigmaps.indeed.com
spec:
group: indeed.com
Expand Down Expand Up @@ -47,9 +46,3 @@ spec:
storage: true
subresources:
status: {}
status:
acceptedNames:
kind: ""
plural: ""
conditions: []
storedVersions: []
Loading

0 comments on commit 14338ab

Please sign in to comment.