-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* wip drop dapper * added tests, validate * fix kubebuilder assets * debug * fix maybe * export global * export global 2 * fix goreleaser * dev doc section improved * crd and docs * drop dapper * drop unused tmpl * added help * typos, and added `build-crds` target to default
- Loading branch information
Showing
25 changed files
with
203 additions
and
368 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,3 +7,4 @@ | |
.vscode/ | ||
__debug* | ||
*-kubeconfig.yaml | ||
.envtest |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,103 @@ | ||
TARGETS := $(shell ls ops) | ||
.dapper: | ||
@echo Downloading dapper | ||
@curl -sL https://releases.rancher.com/dapper/latest/dapper-$$(uname -s)-$$(uname -m) > .dapper.tmp | ||
@@chmod +x .dapper.tmp | ||
@./.dapper.tmp -v | ||
@mv .dapper.tmp .dapper | ||
|
||
$(TARGETS): .dapper | ||
./.dapper $@ | ||
REPO ?= rancher | ||
VERSION ?= $(shell git describe --tags --always --dirty --match="v[0-9]*") | ||
|
||
.DEFAULT_GOAL := default | ||
## Dependencies | ||
|
||
.PHONY: $(TARGETS) | ||
GOLANGCI_LINT_VERSION := v1.63.4 | ||
CONTROLLER_TOOLS_VERSION ?= v0.14.0 | ||
GINKGO_VERSION ?= v2.21.0 | ||
ENVTEST_VERSION ?= latest | ||
ENVTEST_K8S_VERSION := 1.31.0 | ||
|
||
GOLANGCI_LINT ?= go run github.com/golangci/golangci-lint/cmd/golangci-lint@$(GOLANGCI_LINT_VERSION) | ||
CONTROLLER_GEN ?= go run sigs.k8s.io/controller-tools/cmd/controller-gen@$(CONTROLLER_TOOLS_VERSION) | ||
GINKGO ?= go run github.com/onsi/ginkgo/v2/ginkgo@$(GINKGO_VERSION) | ||
|
||
ENVTEST ?= go run sigs.k8s.io/controller-runtime/tools/setup-envtest@$(ENVTEST_VERSION) | ||
ENVTEST_DIR ?= $(shell pwd)/.envtest | ||
export KUBEBUILDER_ASSETS ?= $(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(ENVTEST_DIR) -p path) | ||
|
||
|
||
.PHONY: all | ||
all: version build-crds build package ## Run 'make' or 'make all' to run 'version', 'build-crds', 'build' and 'package' | ||
|
||
.PHONY: version | ||
version: ## Print the current version | ||
@echo $(VERSION) | ||
|
||
.PHONY: build | ||
build: ## Build the the K3k binaries (k3k, k3k-kubelet and k3kcli) | ||
@VERSION=$(VERSION) ./scripts/build | ||
|
||
.PHONY: package | ||
package: package-k3k package-k3k-kubelet ## Package the k3k and k3k-kubelet Docker images | ||
|
||
.PHONY: package-% | ||
package-%: | ||
docker build -f package/Dockerfile.$* \ | ||
-t $(REPO)/$*:$(VERSION) \ | ||
-t $(REPO)/$*:latest \ | ||
-t $(REPO)/$*:dev . | ||
|
||
.PHONY: push | ||
push: push-k3k push-k3k-kubelet ## Push the K3k images to the registry | ||
|
||
.PHONY: push-% | ||
push-%: | ||
docker push $(REPO)/$*:$(VERSION) | ||
docker push $(REPO)/$*:latest | ||
docker push $(REPO)/$*:dev | ||
|
||
|
||
.PHONY: test | ||
test: ## Run all the tests | ||
$(GINKGO) -v -r | ||
|
||
.PHONY: test-unit | ||
test-unit: ## Run the unit tests (skips the e2e) | ||
$(GINKGO) -v -r --skip-file=tests/* | ||
|
||
.PHONY: test-controller | ||
test-controller: ## Run the controller tests (pkg/controller) | ||
$(GINKGO) -v -r pkg/controller | ||
|
||
.PHONY: test-e2e | ||
test-e2e: ## Run the e2e tests | ||
$(GINKGO) -v -r tests | ||
|
||
.PHONY: build-crds | ||
build-crds: ## Build the CRDs specs | ||
@# This will return non-zero until all of our objects in ./pkg/apis can generate valid crds. | ||
@# allowDangerousTypes is needed for struct that use floats | ||
$(CONTROLLER_GEN) crd:generateEmbeddedObjectMeta=true,allowDangerousTypes=false \ | ||
paths=./pkg/apis/... \ | ||
output:crd:dir=./charts/k3k/crds | ||
|
||
.PHONY: docs | ||
docs: ## Build the CRDs docs | ||
$(MAKE) -C docs/crds | ||
|
||
.PHONY: lint | ||
lint: ## Find any linting issues in the project | ||
$(GOLANGCI_LINT) run --timeout=5m | ||
|
||
.PHONY: validate | ||
validate: build-crds docs ## Validate the project checking for any dependency or doc mismatch | ||
go mod tidy | ||
git --no-pager diff go.mod go.sum | ||
test -z "$(shell git status --porcelain)" | ||
|
||
|
||
.PHONY: install | ||
install: ## Install K3k with Helm on the targeted Kubernetes cluster | ||
helm upgrade --install --namespace k3k-system --create-namespace \ | ||
--set image.repository=$(REPO)/k3k \ | ||
--set image.tag=$(VERSION) \ | ||
--set sharedAgent.image.repository=$(REPO)/k3k-kubelet \ | ||
--set sharedAgent.image.tag=$(VERSION) \ | ||
k3k ./charts/k3k/ | ||
|
||
.PHONY: help | ||
help: ## Show this help. | ||
@egrep -h '\s##\s' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m %-30s\033[0m %s\n", $$1, $$2}' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,93 @@ | ||
# Development | ||
|
||
## Tests | ||
|
||
To run the tests we use [Ginkgo](https://onsi.github.io/ginkgo/), and [`envtest`](https://book.kubebuilder.io/reference/envtest) for testing the controllers. | ||
## Prerequisites | ||
|
||
To start developing K3k you will need: | ||
|
||
- Go | ||
- Docker | ||
- Helm | ||
- A running Kubernetes cluster | ||
|
||
|
||
### TLDR | ||
|
||
```shell | ||
#!/bin/bash | ||
|
||
set -euo pipefail | ||
|
||
# These environment variables configure the image repository and tag. | ||
export REPO=ghcr.io/myuser | ||
export VERSION=dev-$(date -u '+%Y%m%d%H%M') | ||
|
||
make | ||
make push | ||
make install | ||
``` | ||
|
||
### Makefile | ||
|
||
To see all the available Make commands you can run `make help`, i.e: | ||
|
||
``` | ||
-> % make help | ||
all Run 'make' or 'make all' to run 'version', 'build-crds', 'build' and 'package' | ||
version Print the current version | ||
build Build the the K3k binaries (k3k, k3k-kubelet and k3kcli) | ||
package Package the k3k and k3k-kubelet Docker images | ||
push Push the K3k images to the registry | ||
test Run all the tests | ||
test-unit Run the unit tests (skips the e2e) | ||
test-controller Run the controller tests (pkg/controller) | ||
test-e2e Run the e2e tests | ||
build-crds Build the CRDs specs | ||
docs Build the CRDs docs | ||
lint Find any linting issues in the project | ||
validate Validate the project checking for any dependency or doc mismatch | ||
install Install K3k with Helm on the targeted Kubernetes cluster | ||
help Show this help. | ||
``` | ||
|
||
### Build | ||
|
||
To build the needed binaries (`k3k`, `k3k-kubelet` and the `k3kcli`) and package the images you can simply run `make`. | ||
|
||
By default the `rancher` repository will be used, but you can customize this to your registry with the `REPO` env var: | ||
|
||
Install the required binaries from `envtest` with [`setup-envtest`](https://pkg.go.dev/sigs.k8s.io/controller-runtime/tools/setup-envtest), and then put them in the default path `/usr/local/kubebuilder/bin`: | ||
``` | ||
REPO=ghcr.io/userorg make | ||
``` | ||
|
||
To customize the tag you can also explicitly set the VERSION: | ||
|
||
``` | ||
ENVTEST_BIN=$(setup-envtest use -p path) | ||
sudo mkdir -p /usr/local/kubebuilder/bin | ||
sudo cp $ENVTEST_BIN/* /usr/local/kubebuilder/bin | ||
VERSION=dev-$(date -u '+%Y%m%d%H%M') make | ||
``` | ||
|
||
then run `ginkgo run ./...`. | ||
|
||
### Push | ||
|
||
You will need to push the built images to your registry, and you can use the `make push` command to do this. | ||
|
||
|
||
### Install | ||
|
||
Once you have your images available you can install K3k with the `make install` command. This will use `helm` to install the release. | ||
|
||
|
||
## Tests | ||
|
||
To run the tests you can just run `make test`, or one of the other available "sub-tests" targets (`test-unit`, `test-controller`, `test-e2e`). | ||
|
||
We use [Ginkgo](https://onsi.github.io/ginkgo/), and [`envtest`](https://book.kubebuilder.io/reference/envtest) for testing the controllers. | ||
|
||
The required binaries for `envtest` are installed with [`setup-envtest`](https://pkg.go.dev/sigs.k8s.io/controller-runtime/tools/setup-envtest), in the `.envtest` folder. | ||
|
||
|
||
## CRDs and Docs | ||
|
||
We are using Kubebuilder and `controller-gen` to build the needed CRDs. To generate the specs you can run `make build-crds`. | ||
|
||
Remember also to update the CRDs documentation running the `make docs` command. |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.