Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 16 additions & 18 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,16 @@ jobs:
test:
name: Test
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
go: ["1.22"]

steps:
- name: Checkout code
uses: actions/checkout@v6

- name: Set up Go
uses: actions/setup-go@v5
uses: actions/setup-go@v6
with:
go-version: ${{ matrix.go }}
go-version-file: .go-version

- name: Checkout code
uses: actions/checkout@v4

- name: Test
run: make test
Expand All @@ -32,13 +29,14 @@ jobs:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v6

- name: Set up Go
uses: actions/setup-go@v5
uses: actions/setup-go@v6
with:
go-version: '1.22'
go-version-file: .go-version

- name: Checkout code
uses: actions/checkout@v4

- name: Lint
run: make lint
Expand All @@ -50,16 +48,16 @@ jobs:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v6

- name: Set up Go
uses: actions/setup-go@v5
uses: actions/setup-go@v6
with:
go-version: '1.22'

- name: Checkout code
uses: actions/checkout@v4
go-version-file: .go-version

- name: Cache licenses
uses: actions/cache@v4
uses: actions/cache@v5
with:
key: licensei-v2-${{ hashFiles('go.sum') }}
path: |
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
bin/
build/
.idea
.licensei.cache
1 change: 1 addition & 0 deletions .go-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1.26.0
45 changes: 45 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
version: "2"
run:
timeout: 10m
allow-parallel-runners: true

formatters:
enable:
- gci
- gofmt
- gofumpt
- goimports
settings:
gci:
sections:
- standard
- default
- prefix(github.com/cisco-open/operator-tools)
goimports:
local-prefixes:
- github.com/cisco-open/operator-tools
gofmt:
simplify: true
gofumpt:
extra-rules: false

linters:
settings:
misspell:
locale: US
revive:
confidence: 0.9
gocyclo:
min-complexity: 45
enable:
- bodyclose
- errcheck
- ineffassign
- misspell
- nolintlint
- revive
- gocyclo
- unconvert
- unparam
- unused
- whitespace
178 changes: 113 additions & 65 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,28 @@
LICENSEI_VERSION = 0.9.0
GOLANGCI_VERSION = 1.59.0
####
## Dependency versions
####

CONTROLLER_TOOLS_VERSION := 0.21.0

GOLANGCI_LINT_VERSION := 2.12.2

LICENSEI_VERSION := 0.9.0

ENVTEST_K8S_VERSION := 1.35.0

BIN := ${PWD}/bin

export PATH := $(BIN):$(PATH)

GOVERSION := $(shell go env GOVERSION)

GOLANGCI_LINT := $(BIN)/golangci-lint
CONTROLLER_GEN ?= $(BIN)/controller-gen
ENVTEST ?= $(BIN)/setup-envtest
LICENSEI := $(BIN)/licensei

ENVTEST_BIN_DIR := $(BIN)/envtest
ENVTEST_BINARY_ASSETS := $(ENVTEST_BIN_DIR)/bin

# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
ifeq (,$(shell go env GOBIN))
Expand All @@ -8,103 +31,128 @@ else
GOBIN=$(shell go env GOBIN)
endif

BIN := ${PWD}/bin
export PATH := ${BIN}:${PATH}
# Setting SHELL to bash allows bash commands to be executed by recipes.
# Options are set to exit when a recipe line exits non-zero or a piped command fails.
SHELL = /usr/bin/env bash -o pipefail
.SHELLFLAGS = -ec

CONTROLLER_GEN_VERSION = v0.15.0
CONTROLLER_GEN = $(PWD)/bin/controller-gen
##@ General

OS = $(shell uname | tr A-Z a-z)
.DEFAULT_GOAL = help
.PHONY: help
help: ## Display this help.
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z_0-9-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)

ENVTEST_BIN_DIR := ${BIN}/envtest
ENVTEST_K8S_VERSION := 1.24.1
ENVTEST_BINARY_ASSETS := ${ENVTEST_BIN_DIR}/bin
##@ Development

SETUP_ENVTEST := ${BIN}/setup-envtest
.PHONY: generate
generate: codegen docs fmt ## Generate code, documentation, etc.

# Generate code
generate: bin/controller-gen
.PHONY: codegen
codegen: controller-gen ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.
$(CONTROLLER_GEN) object:headerFile=./hack/boilerplate.go.txt paths=./pkg/secret/...
$(CONTROLLER_GEN) object:headerFile=./hack/boilerplate.go.txt paths=./pkg/volume/...
$(CONTROLLER_GEN) object:headerFile=./hack/boilerplate.go.txt paths=./pkg/prometheus/...
$(CONTROLLER_GEN) object:headerFile=./hack/boilerplate.go.txt paths=./pkg/types/...
$(CONTROLLER_GEN) object:headerFile=./hack/boilerplate.go.txt paths=./pkg/typeoverride/...
$(CONTROLLER_GEN) object:headerFile=./hack/boilerplate.go.txt paths=./pkg/helm/...

bin/controller-gen:
@ if ! test -x bin/controller-gen; then \
set -ex ;\
GOBIN=$(PWD)/bin go install sigs.k8s.io/controller-tools/cmd/controller-gen@${CONTROLLER_GEN_VERSION} ;\
fi

.PHONY: docs
docs: ## Generate type documentation.
go run cmd/docs.go

bin/licensei: bin/licensei-${LICENSEI_VERSION}
@ln -sf licensei-${LICENSEI_VERSION} bin/licensei
bin/licensei-${LICENSEI_VERSION}:
@mkdir -p bin
curl -sfL https://git.io/licensei | bash -s v${LICENSEI_VERSION}
@mv bin/licensei $@
.PHONY: fmt
fmt: ## Run go fmt against code.
go fmt ./...

.PHONY: license-cache
license-cache: bin/licensei ## Generate license cache
bin/licensei cache
.PHONY: vet
vet: ## Run go vet against code.
go vet ./...

.PHONY: license-check
license-check: bin/licensei ## Run license check
bin/licensei check
bin/licensei header
.PHONY: tidy
tidy: ## Tidy Go modules.
find . -iname "go.mod" -not -path "./.devcontainer/*" | xargs -L1 sh -c 'cd $$(dirname $$0); go mod tidy'

.PHONY: test
test: ${ENVTEST_BINARY_ASSETS}
KUBEBUILDER_ASSETS=${ENVTEST_BINARY_ASSETS} go test ./...

.PHONY: check
check: test lint check-diff ## Run tests and linters

bin/golangci-lint: bin/golangci-lint-${GOLANGCI_VERSION}
@ln -sf golangci-lint-${GOLANGCI_VERSION} bin/golangci-lint
bin/golangci-lint-${GOLANGCI_VERSION}:
@mkdir -p bin
curl -sfL curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | bash -s -- -b ./bin/ v${GOLANGCI_VERSION}
@mv bin/golangci-lint $@
test: fmt vet envtest ## Run verifications and tests.
KUBEBUILDER_ASSETS="$(ENVTEST_BINARY_ASSETS)" go test -v ./... -coverprofile cover.out

.PHONY: lint
lint: export CGO_ENABLED = 1
lint: bin/golangci-lint ## Run linter
bin/golangci-lint run ${LINTER_FLAGS}
lint: ${GOLANGCI_LINT} ## Run golangci-lint.
${GOLANGCI_LINT} run ${LINTER_FLAGS}

.PHONY: fix
fix: export CGO_ENABLED = 1
fix: bin/golangci-lint ## Fix lint violations
bin/golangci-lint run --fix
.PHONY: lint-fix
lint-fix: export CGO_ENABLED = 1
lint-fix: ${GOLANGCI_LINT} ## Run golangci-lint and perform fixes.
${GOLANGCI_LINT} run --fix

.PHONY: check
check: test lint check-diff ## Run tests and linters.

check-diff: generate-type-docs
go mod tidy
$(MAKE) generate docs
.PHONY: check-diff
check-diff: tidy generate ## Verify that generated files are up to date.
git diff --exit-code

generate-type-docs:
go run cmd/docs.go
.PHONY: license-cache
license-cache: ${LICENSEI} ## Generate license cache.
${LICENSEI} cache

.PHONY: license-check
license-check: ${LICENSEI} .licensei.cache ## Run license check.
${LICENSEI} check
${LICENSEI} header

${ENVTEST_BINARY_ASSETS}: ${ENVTEST_BINARY_ASSETS}_${ENVTEST_K8S_VERSION}
ln -sf $(notdir $<) $@
##@ Build Dependencies

${ENVTEST_BINARY_ASSETS}_${ENVTEST_K8S_VERSION}: | ${SETUP_ENVTEST} ${ENVTEST_BIN_DIR}
ln -sf $$(${SETUP_ENVTEST} --bin-dir ${ENVTEST_BIN_DIR} use ${ENVTEST_K8S_VERSION} -p path) $@
${GOLANGCI_LINT}: ${GOLANGCI_LINT}_${GOLANGCI_LINT_VERSION}_${GOVERSION} | ${BIN}
ln -snf $(notdir $<) $@

${SETUP_ENVTEST}: IMPORT_PATH := sigs.k8s.io/controller-runtime/tools/setup-envtest
${SETUP_ENVTEST}: VERSION := latest
${SETUP_ENVTEST}: | ${BIN}
GOBIN=${BIN} go install ${IMPORT_PATH}@${VERSION}
${GOLANGCI_LINT}_${GOLANGCI_LINT_VERSION}_${GOVERSION}: IMPORT_PATH := github.com/golangci/golangci-lint/v2/cmd/golangci-lint
${GOLANGCI_LINT}_${GOLANGCI_LINT_VERSION}_${GOVERSION}: VERSION := v${GOLANGCI_LINT_VERSION}
${GOLANGCI_LINT}_${GOLANGCI_LINT_VERSION}_${GOVERSION}: | ${BIN}
${go_install_binary}

${ENVTEST_BIN_DIR}: | ${BIN}
.PHONY: controller-gen
controller-gen: $(CONTROLLER_GEN) ## Download controller-gen locally if necessary. If wrong version is installed, it will be overwritten.
$(CONTROLLER_GEN): | $(BIN)
test -s $(BIN)/controller-gen && $(BIN)/controller-gen --version | grep -q v$(CONTROLLER_TOOLS_VERSION) || \
GOBIN=$(BIN) go install sigs.k8s.io/controller-tools/cmd/controller-gen@v$(CONTROLLER_TOOLS_VERSION)

.PHONY: envtest
envtest: $(ENVTEST_BINARY_ASSETS) ## Download envtest-setup and Kubernetes binary assets locally if necessary.
$(ENVTEST): | $(BIN)
test -s $(BIN)/setup-envtest || GOBIN=$(BIN) go install sigs.k8s.io/controller-runtime/tools/setup-envtest@latest

$(ENVTEST_BINARY_ASSETS): $(ENVTEST_BINARY_ASSETS)_$(ENVTEST_K8S_VERSION)
ln -snf $(notdir $<) $@

$(ENVTEST_BINARY_ASSETS)_$(ENVTEST_K8S_VERSION): | $(ENVTEST) $(ENVTEST_BIN_DIR)
ln -snf $$($(ENVTEST) --bin-dir $(ENVTEST_BIN_DIR) use $(ENVTEST_K8S_VERSION) -p path) $@

$(ENVTEST_BIN_DIR): | $(BIN)
mkdir -p $@

${LICENSEI}: ${LICENSEI}_${LICENSEI_VERSION}_${GOVERSION} | ${BIN}
ln -snf $(notdir $<) $@

${LICENSEI}_${LICENSEI_VERSION}_${GOVERSION}: IMPORT_PATH := github.com/goph/licensei/cmd/licensei
${LICENSEI}_${LICENSEI_VERSION}_${GOVERSION}: VERSION := v${LICENSEI_VERSION}
${LICENSEI}_${LICENSEI_VERSION}_${GOVERSION}: | ${BIN}
${go_install_binary}

.licensei.cache: ${LICENSEI}
ifndef GITHUB_TOKEN
@>&2 echo "WARNING: building licensei cache without Github token, rate limiting might occur."
@>&2 echo "(Hint: If too many licenses are missing, try specifying a Github token via the environment variable GITHUB_TOKEN.)"
endif
${LICENSEI} cache

${BIN}:
mkdir -p $@

define go_install_binary
find ${BIN} -name '$(notdir ${IMPORT_PATH})_*' -exec rm {} +
GOBIN=${BIN} go install ${IMPORT_PATH}@${VERSION}
mv ${BIN}/$(notdir ${IMPORT_PATH}) ${BIN}/$(notdir ${IMPORT_PATH})_${VERSION}
mv ${BIN}/$(notdir ${IMPORT_PATH}) $@
endef
1 change: 1 addition & 0 deletions docs/types/secret_types.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
SecretLoader facilitates loading the secrets from an operator.
Leverages core types from kubernetes/api/core/v1


## Configuration
## Secret

Expand Down
6 changes: 6 additions & 0 deletions docs/types/volume_types.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ PersistentVolumeClaim defines the Spec and the Source at the same time. The PVC

## PersistentVolumeClaim

### annotations (map[string]string, optional) {#persistentvolumeclaim-annotations}


### labels (map[string]string, optional) {#persistentvolumeclaim-labels}


### spec (corev1.PersistentVolumeClaimSpec, optional) {#persistentvolumeclaim-spec}


Expand Down
Loading