Skip to content

Commit 2d38279

Browse files
committed
update makefile help and docs for local development
Rearrange make targets to separate basic from advanced targets. Add some more developer documentation to help new contributors. Modify 'make deploy' for easier local development. Modify Kustomize resource definitions to make it easier to create a local-specific kustomize.yaml file for an individual development environment. Add a script to help deploy a locally-built COSI controller without risk of accidentally committing changes to git. Add local controller dev workflow to developer doc. Signed-off-by: Blaine Gardner <[email protected]>
1 parent 970caee commit 2d38279

File tree

8 files changed

+152
-92
lines changed

8 files changed

+152
-92
lines changed

Makefile

Lines changed: 79 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
SHELL = /usr/bin/env bash
1818

1919
.PHONY: help
20-
help: ## Display this help.
21-
@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)
20+
help: ## Display this help
21+
@awk 'BEGIN {FS = " *:.*## *"; printf "\nUsage:\n make \033[36m<target>\033[0m [\033[32mVAR\033[0m=val]\n"} /^##.*:##/ { gsub(/^## /,"",$$1) ; printf " \033[32m%s\033[0m (\"%s\")\n └ %s\n", $$1, ENVIRON[$$1], $$2} /^[.a-zA-Z_0-9-]+:.*?##/ { printf " \033[36m%-18s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)
2222

2323
# If GOARCH is not set in the env, find it
2424
GOARCH ?= $(shell go env GOARCH)
@@ -27,66 +27,33 @@ GOARCH ?= $(shell go env GOARCH)
2727
# ==== ARGS =====
2828
#
2929

30-
# Container build tool compatible with `docker` API
30+
##@ Environment args
31+
32+
## DOCKER :## Container build tool compatible with `docker` API
3133
DOCKER ?= docker
3234

33-
# Tool compatible with `kubectl` API
35+
## KUBECTL :## Tool compatible with `kubectl` API
3436
KUBECTL ?= kubectl
3537

36-
# Platform for 'build'
38+
## PLATFORM :## Platform for builds
3739
PLATFORM ?= linux/$(GOARCH)
3840

39-
# Additional args for 'build'
41+
## BUILD_ARGS :## Additional args for builds
4042
BUILD_ARGS ?=
4143

42-
# Image tag for controller image build
44+
## CONTROLLER_TAG :## Image tag for controller image build and deploy
4345
CONTROLLER_TAG ?= cosi-controller:latest
4446

45-
# Image tag for sidecar image build
47+
## SIDECAR_TAG :## Image tag for sidecar image build
4648
SIDECAR_TAG ?= cosi-provisioner-sidecar:latest
4749

48-
##@ Development
49-
50-
.PHONY: generate
51-
generate: crds controller/Dockerfile sidecar/Dockerfile ## Generate files
52-
53-
.PHONY: crds
54-
crds: controller-gen
55-
cd ./client && $(CONTROLLER_GEN) rbac:roleName=manager-role crd paths="./apis/objectstorage/..."
56-
57-
%/Dockerfile: hack/Dockerfile.in hack/gen-dockerfile.sh
58-
hack/gen-dockerfile.sh $* > "$@"
59-
60-
.PHONY: codegen
61-
codegen: codegen.client codegen.proto ## Generate code
62-
63-
.PHONY: codegen.client codegen.proto
64-
codegen.client: controller-gen
65-
cd ./client && $(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./apis/objectstorage/..."
66-
codegen.proto:
67-
$(MAKE) -C proto codegen
68-
69-
.PHONY: fmt
70-
fmt: fmt.client fmt.controller fmt.sidecar ## Format code
71-
fmt.%: FORCE
72-
cd $* && go fmt ./...
73-
74-
.PHONY: vet
75-
vet: vet.client vet.controller vet.sidecar ## Vet code
76-
vet.%: FORCE
77-
cd $* && go vet ./...
50+
export
7851

79-
.PHONY: test
80-
test: .test.proto test.client test.controller test.sidecar ## Run all unit tests including vet and fmt
81-
test.%: fmt.% vet.% FORCE
82-
cd $* && go test ./...
83-
.PHONY: .test.proto
84-
.test.proto: # gRPC proto has a special unit test
85-
$(MAKE) -C proto check
52+
##@ Core (Basic)
8653

87-
.PHONY: test-e2e
88-
test-e2e: chainsaw # Run e2e tests against the K8s cluster specified in ~/.kube/config. It requires both controller and driver deployed. If you need to create a cluster beforehand, consider using 'cluster' and 'deploy' targets.
89-
$(CHAINSAW) test --values ./test/e2e/values.yaml
54+
.PHONY: all
55+
.NOTPARALLEL: all # all generators must run before build
56+
all: prebuild build ## Build all container images, plus their prerequisites (faster with 'make -j')
9057

9158
.PHONY: lint
9259
lint: golangci-lint.client golangci-lint.controller golangci-lint.sidecar spell-lint dockerfiles-lint ## Run all linters (suggest `make -k`)
@@ -102,22 +69,29 @@ lint-fix: golangci-lint-fix.client golangci-lint-fix.controller golangci-lint-fi
10269
golangci-lint-fix.%: golangci-lint
10370
cd $* && $(GOLANGCI_LINT) run $(GOLANGCI_LINT_RUN_OPTS) --config $(CURDIR)/.golangci.yaml --new --fix
10471

105-
.PHONY: vendor
106-
vendor: tidy.client tidy.proto ## Update go vendor dir
107-
go mod tidy
108-
go mod vendor
109-
tidy.%: FORCE
110-
cd $* && go mod tidy
72+
.PHONY: test
73+
test: .test.proto test.client test.controller test.sidecar ## Run all unit tests including vet and fmt
74+
test.%: fmt.% vet.% FORCE
75+
cd $* && go test ./...
76+
.PHONY: .test.proto
77+
.test.proto: # gRPC proto has a special unit test
78+
$(MAKE) -C proto check
79+
80+
.PHONY: clean
81+
clean: ## Clean build environment
82+
$(MAKE) -C proto clean
11183

112-
##@ Build
84+
.PHONY: clobber
85+
clobber: ## Clean build environment and cached tools
86+
$(MAKE) -C proto clobber
87+
rm -rf $(TOOLBIN)
88+
rm -rf $(CURDIR)/.cache
11389

114-
.PHONY: all
115-
.NOTPARALLEL: all # all generators must run before build
116-
all: prebuild build ## Build all container images, plus their prerequisites (faster with 'make -j')
90+
##@ Development (Advanced)
11791

11892
.PHONY: prebuild .gen .doc-vendor
11993
.gen: generate codegen # can be done in parallel with 'make -j'
120-
.doc-vendor: build-docs vendor # can be done in parallel
94+
.doc-vendor: docs vendor # can be done in parallel
12195
.NOTPARALLEL: prebuild # codegen must be finished before fmt
12296
prebuild: .gen fmt .doc-vendor ## Run all pre-build prerequisite steps (faster with 'make -j')
12397

@@ -130,8 +104,37 @@ build.controller: controller/Dockerfile ## Build only the controller container i
130104
build.sidecar: sidecar/Dockerfile ## Build only the sidecar container image
131105
$(DOCKER) build --file sidecar/Dockerfile --platform $(PLATFORM) $(BUILD_ARGS) --tag $(SIDECAR_TAG) .
132106

133-
.PHONY: build-docs
134-
build-docs: generate crd-ref-docs mdbook
107+
.PHONY: generate
108+
generate: crds controller/Dockerfile sidecar/Dockerfile ## Generate files
109+
110+
.PHONY: crds
111+
crds: controller-gen
112+
cd ./client && $(CONTROLLER_GEN) rbac:roleName=manager-role crd paths="./apis/objectstorage/..."
113+
114+
%/Dockerfile: hack/Dockerfile.in hack/gen-dockerfile.sh
115+
hack/gen-dockerfile.sh $* > "$@"
116+
117+
.PHONY: codegen
118+
codegen: codegen.client codegen.proto ## Generate code
119+
120+
.PHONY: codegen.client codegen.proto
121+
codegen.client: controller-gen
122+
cd ./client && $(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./apis/objectstorage/..."
123+
codegen.proto:
124+
$(MAKE) -C proto codegen
125+
126+
.PHONY: fmt
127+
fmt: fmt.client fmt.controller fmt.sidecar
128+
fmt.%: FORCE
129+
cd $* && go fmt ./...
130+
131+
.PHONY: vet
132+
vet: vet.client vet.controller vet.sidecar
133+
vet.%: FORCE
134+
cd $* && go vet ./...
135+
136+
.PHONY: docs
137+
docs: generate crd-ref-docs mdbook ## Build docs
135138
$(CRD_REF_DOCS) \
136139
--config=./docs/.crd-ref-docs.yaml \
137140
--source-path=./client/apis \
@@ -141,21 +144,21 @@ build-docs: generate crd-ref-docs mdbook
141144

142145
MDBOOK_PORT ?= 3000
143146

144-
.PHONY: serve-docs
145-
serve-docs: generate mdbook build-docs
147+
.PHONY: docs.serve
148+
docs.serve: generate mdbook docs ## Serve locally built docs
146149
cd docs; $(MDBOOK) serve --port $(MDBOOK_PORT)
147150

148-
.PHONY: clean
149-
clean: ## Clean build environment
150-
$(MAKE) -C proto clean
151+
.PHONY: vendor
152+
vendor: tidy.client tidy.proto ## Update go vendor dir
153+
go mod tidy
154+
go mod vendor
155+
tidy.%: FORCE
156+
cd $* && go mod tidy
151157

152-
.PHONY: clobber
153-
clobber: ## Clean build environment and cached tools
154-
$(MAKE) -C proto clobber
155-
rm -rf $(TOOLBIN)
156-
rm -rf $(CURDIR)/.cache
158+
.PHONY: test-e2e
159+
test-e2e: chainsaw ## Run e2e tests against the local K8s cluster (requires both controller and driver deployed)
157160

158-
##@ Deployment
161+
##@ Deployment (Advanced)
159162

160163
.PHONY: cluster
161164
cluster: kind ctlptl ## Create Kind cluster and local registry
@@ -166,12 +169,12 @@ cluster-reset: kind ctlptl ## Delete Kind cluster
166169
PATH=$(TOOLBIN):$(PATH) $(CTLPTL) delete -f ctlptl.yaml
167170

168171
.PHONY: deploy
169-
deploy: kustomize ## Deploy controller to the K8s cluster specified in ~/.kube/config
170-
$(KUSTOMIZE) build . | $(KUBECTL) apply -f -
172+
deploy: kustomize ## Deploy controller (CONTROLLER_TAG) to the local K8s cluster
173+
./hack/dev-kustomize.sh && $(KUSTOMIZE) build $(CURDIR)/.cache | $(KUBECTL) apply -f -
171174

172175
.PHONY: undeploy
173-
undeploy: kustomize ## Undeploy controller from the K8s cluster specified in ~/.kube/config
174-
$(KUSTOMIZE) build . | $(KUBECTL) delete --ignore-not-found=true -f -
176+
undeploy: kustomize ## Undeploy controller (CONTROLLER_TAG) from the local K8s cluster
177+
./hack/dev-kustomize.sh && $(KUSTOMIZE) build $(CURDIR)/.cache | $(KUBECTL) delete --ignore-not-found=true -f -
175178

176179
#
177180
# ===== Tools =====

README.md

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,16 +35,12 @@ Participation in the Kubernetes community is governed by the [Kubernetes Code of
3535

3636
## Developer Guide
3737

38-
Before contributing a Pull Request, ensure a [GitHub
39-
issue](https://github.com/kubernetes-sigs/container-object-storage-interface/issues) exists corresponding to the change.
40-
4138
All API definitions and behavior must follow the [`v1alpha2` KEP PR](https://github.com/kubernetes/enhancements/pull/4599).
4239
Minor deviation from the KEP is acceptable in order to fix bugs.
4340

4441
`v1alpha2` is currently pre-release.
4542
Changes may break compatibility up until `v1alpha2` is released with a semver tag.
4643
After the first `v1alpha2` semver release (e.g., 0.3.0), all changes must be backwards compatible.
4744

48-
### Build and Test
49-
50-
See `make help` for assistance
45+
Before making a COSI contribution, please read and follow the
46+
[core developer guide](https://container-object-storage-interface.sigs.k8s.io/developing/core.html).
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
apiVersion: kustomize.config.k8s.io/v1beta1
3+
kind: Kustomization
4+
resources:
5+
- objectstorage.k8s.io_bucketaccessclasses.yaml
6+
- objectstorage.k8s.io_bucketaccesses.yaml
7+
- objectstorage.k8s.io_bucketclaims.yaml
8+
- objectstorage.k8s.io_bucketclasses.yaml
9+
- objectstorage.k8s.io_buckets.yaml

controller/resources/deployment.yaml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,4 @@ spec:
2323
containers:
2424
- name: objectstorage-controller
2525
image: gcr.io/k8s-staging-sig-storage/objectstorage-controller:v20251003-controllerv0.2.0-rc1-145-ge3bc25e
26-
args:
27-
- "--v=5"
26+
args: []

docs/src/developing/core.md

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,26 @@ With “core” COSI we refer to the common set of API and controllers that are
44

55
Before your first contribution, you should follow [the Kubernetes Contributor Guide](https://www.kubernetes.dev/docs/guide/#contributor-guide).
66

7-
To further understand the COSI architecture, please refer to [KEP-1979: Object Storage Support](https://github.com/kubernetes/enhancements/tree/master/keps/sig-storage/1979-object-storage-support).
7+
To further understand the COSI architecture, please refer to [KEP-1979: Object Storage
8+
Support](https://github.com/kubernetes/enhancements/tree/master/keps/sig-storage/1979-object-storage-support).
9+
10+
Before contributing a Pull Request, ensure a [GitHub issue](https://github.com/kubernetes-sigs/container-object-storage-interface/issues) exists corresponding to the change.
11+
12+
## Local code development
13+
14+
For new contributors, use `make help`, and use **Core** targets as needed.
15+
These targets ensure changes build successfully, pass basic checks, and are ready for end-to-end tests run in COSI's automated CI.
16+
17+
Other more advanced targets are available and also described in `make help` output.
18+
19+
Some specific workflows are documented below.
20+
21+
### Building and deploying COSI controller changes locally
22+
23+
```sh
24+
export CONTROLLER_TAG="$MY_REPO"/cosi-controller:latest # replace MY_REPO with desired dev repo
25+
make -j prebuild
26+
make build.controller
27+
docker push "$CONTROLLER_TAG"
28+
make deploy
29+
```

hack/dev-kustomize.sh

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#!/usr/bin/env bash
2+
set -o errexit
3+
set -o nounset
4+
set -o xtrace
5+
6+
#
7+
# generate a kustomization file for local development use
8+
# use the Makefile's CONTROLLER_TAG as the image used for dev deployment
9+
#
10+
11+
# store generated file(s) in cache dir not checked into git
12+
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
13+
ROOT="$SCRIPT_DIR"/..
14+
CACHE_DIR="$ROOT"/.cache
15+
mkdir -p "$CACHE_DIR"
16+
17+
# copy root kustomization.yaml file to cache dir, and...
18+
# replace './' in root kustomization.yaml with '../' for usage from cache dir
19+
DEV_KUSTOMIZE_FILE="$CACHE_DIR"/kustomization.yaml
20+
sed -e 's|\./|../|g' "$ROOT"/kustomization.yaml > "$DEV_KUSTOMIZE_FILE"
21+
22+
# process Makefile's CONTROLLER_TAG into name and tag components
23+
# e.g., CONTROLLER_TAG="localhost:5000/cosi-controller:latest"
24+
NEW_NAME="${CONTROLLER_TAG%:*}" # e.g., "localhost:5000/cosi-controller"
25+
NEW_TAG="${CONTROLLER_TAG##*:}" # e.g., "latest"
26+
27+
# replace the default controller image with one for local dev
28+
cat <<EOF >> "$DEV_KUSTOMIZE_FILE"
29+
30+
images:
31+
- name: gcr.io/k8s-staging-sig-storage/objectstorage-controller
32+
newName: "$NEW_NAME"
33+
newTag: "$NEW_TAG"
34+
EOF

kustomization.yaml

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,6 @@ commonAnnotations:
99
api-approved.kubernetes.io: https://github.com/kubernetes/enhancements/tree/master/keps/sig-storage/1979-object-storage-support
1010

1111
resources:
12-
- client/config/crd/objectstorage.k8s.io_bucketaccesses.yaml
13-
- client/config/crd/objectstorage.k8s.io_bucketaccessclasses.yaml
14-
- client/config/crd/objectstorage.k8s.io_bucketclasses.yaml
15-
- client/config/crd/objectstorage.k8s.io_bucketclaims.yaml
16-
- client/config/crd/objectstorage.k8s.io_buckets.yaml
17-
- controller
12+
# ensure all resources begin with './'
13+
- ./client/config/crd
14+
- ./controller

netlify.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Netlify build instructions
22
[build]
3-
command = "make build-docs"
3+
command = "make docs"
44
publish = "docs/book"
55

66
[build.environment]

0 commit comments

Comments
 (0)