Skip to content

Commit

Permalink
Merge pull request #624 from aiven/rriski-dev-instructions
Browse files Browse the repository at this point in the history
  • Loading branch information
Serpentiel authored Feb 6, 2024
2 parents 3fb2d7e + 877d1d9 commit fd751c1
Show file tree
Hide file tree
Showing 21 changed files with 246 additions and 115 deletions.
135 changes: 82 additions & 53 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,12 @@ help: ## Display this help.
##@ Development

.PHONY: charts
charts: ## Updates helm charts, updates changelog in docs (removes placeholder header)
charts: ## Updates helm charts, updates changelog in docs (removes placeholder header).
go run ./generators/charts/... --version=$(version) --operator-charts ./charts/aiven-operator --crd-charts ./charts/aiven-operator-crds
[ "$(version)" == "" ] || sed '/## \[/d' ./CHANGELOG.md > docs/docs/changelog.md

.PHONY: userconfigs
userconfigs:
userconfigs: ## Run userconfigs generator.
go generate ./...

.PHONY: manifests
Expand All @@ -63,30 +63,52 @@ boilerplate: controller-gen ## Generate code containing DeepCopy, DeepCopyInto,
$(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./..."

.PHONY: generate
generate: userconfigs boilerplate imports manifests docs charts fmt
generate: userconfigs boilerplate imports manifests docs charts fmt ## Run all code generation targets.

.PHONY: fmt
fmt:
fmt: ## Format code.
go fmt ./...
trunk fmt

.PHONY: vet
vet: ## Run go vet against code.
go vet ./...

# On MACOS requires gnu-sed. Run `brew info gnu-sed` and follow instructions to replace default sed.
.PHONY: imports
imports: ## Run goimports against code.
find . -type f -name '*.go' -exec sed -zi 's/"\n\+\t"/"\n"/g' {} +
goimports -local "github.com/aiven/aiven-operator" -w .

##@ Checks

.PHONY: check-avn-client
check-avn-client: ## Check if avn client is installed and user is authenticated.
@if ! command -v avn >/dev/null 2>&1; then \
(echo ">> avn command not found, please install https://github.com/aiven/aiven-client"; exit 1) \
fi
@if ! avn user info >/dev/null 2>&1; then \
(echo ">> User not authenticated, please login first with 'avn user login'"; exit 1) \
fi

.PHONY: check-env-vars
check-env-vars: ## Check if required environment variables are set.
@[ "${AIVEN_TOKEN}" ] || (echo ">> variable AIVEN_TOKEN is not set"; exit 1)
@[ "${AIVEN_PROJECT_NAME}" ] || (echo ">> variable AIVEN_PROJECT_NAME is not set"; exit 1)

##@ Tests

.PHONY: test-e2e
test-e2e: build ## Run end-to-end tests using kuttl (https://kuttl.dev/)
@[ "${AIVEN_TOKEN}" ] || ( echo ">> variable AIVEN_TOKEN is not set"; exit 1 )
@[ "${AIVEN_PROJECT_NAME}" ] || ( echo ">> variable AIVEN_PROJECT_NAME is not set"; exit 1 )
test-e2e: check-env-vars check-avn-client build ## Run end-to-end tests using kuttl (https://kuttl.dev).
kubectl kuttl test --config test/e2e/kuttl-test.yaml

.PHONY: test-e2e-preinstalled
test-e2e-preinstalled:
test-e2e-preinstalled: check-env-vars check-avn-client ## Run end-to-end tests using kuttl (https://kuttl.dev) with preinstalled operator ('make e2e-setup-kind' should be run before this target).
kubectl kuttl test --config test/e2e/kuttl-test.preinstalled.yaml

test: envtest ## Run tests.
test: envtest ## Run tests. To target a specific test, use 'run=TestName make test'.
export KUBEBUILDER_ASSETS=$(shell eval ${KUBEBUILDER_ASSETS_CMD}); \
go test ./tests/... -race -run=$(run) -v -timeout 42m -parallel 10 -cover -coverpkg=./controllers -covermode=atomic -coverprofile=coverage.out
go test ./tests/... -race -run=$(run) -v $(if $(run), -timeout 10m, -timeout 42m) -parallel 10 -cover -coverpkg=./controllers -covermode=atomic -coverprofile=coverage.out

##@ Build

Expand Down Expand Up @@ -132,14 +154,14 @@ undeploy: ## Undeploy controller from the K8s cluster specified in ~/.kube/confi
##@ Docs

.PHONY: docs
docs: ## Generate CRDS api-reference
docs: ## Generate CRDs api-reference.
go run ./generators/docs/...

.PHONY: serve-docs
serve-docs: ## Run live preview.
$(CONTAINER_TOOL) run --rm -it -p 8000:8000 -v ${PWD}/docs:/docs squidfunk/mkdocs-material

##@ Build Dependencies
##@ Build dependencies

## Location to install dependencies to
LOCALBIN ?= $(shell pwd)/bin
Expand Down Expand Up @@ -175,46 +197,54 @@ $(CONTROLLER_GEN): $(LOCALBIN)
envtest: $(ENVTEST) ## Download setup-envtest locally if necessary.
$(ENVTEST): $(LOCALBIN)
$(call go-install-tool,$(ENVTEST),sigs.k8s.io/controller-runtime/tools/setup-envtest,$(ENVTEST_VERSION)) ;\
echo -e "\n>>Installing kubebuilder assets to path:"; \
eval $(KUBEBUILDER_ASSETS_CMD)
echo -e ">>Installing kubebuilder assets to path:"; \
eval $(KUBEBUILDER_ASSETS_CMD); \
echo -e "\n"

.PHONY: golangci-lint
golangci-lint: $(GOLANGCI_LINT) ## Download golangci-lint locally if necessary.
$(GOLANGCI_LINT): $(LOCALBIN)
$(call go-install-tool,$(GOLANGCI_LINT),github.com/golangci/golangci-lint/cmd/golangci-lint,${GOLANGCI_LINT_VERSION})

.PHONY: e2e-setup-kind
WEBHOOKS_ENABLED ?= true
ENABLE_WEBHOOKS ?= true
CERT_MANAGER_TAG ?= v1.11.0
OPERATOR_IMAGE_TAG ?= $(shell git rev-parse HEAD)

# Podman requires specific image name
OPERATOR_IMAGE_NAME ?= localhost/operator
ifeq ($(CONTAINER_TOOL), podman)
ifneq ($(CONTAINER_TOOL), podman)
OPERATOR_IMAGE_NAME = operator
endif

SETUP_PREREQUISITES = jq base64 kcat helm kind $(PODMAN) avn
e2e-setup-kind:
# Validates prerequisites
##@ Test setup and cleanup

# Clean previous installations and delete resources
CLEANUP_TARGETS := aiven-operator-crds aiven-operator aiven-token cert-manager
CLEANUP_NAMESPACES := cert-manager
CLEANUP_SECRETS := aiven-token
.PHONY: cleanup
cleanup: ## Cleanup resources created by e2e-setup-kind.
$(foreach target,$(CLEANUP_TARGETS),helm uninstall $(target) || true;)
$(foreach namespace,$(CLEANUP_NAMESPACES),kubectl delete namespace $(namespace) || true;)
$(foreach secret,$(CLEANUP_SECRETS),kubectl delete secret $(secret) || true;)

SETUP_PREREQUISITES = jq base64 kcat helm kind $(CONTAINER_TOOL) avn
.PHONY: e2e-setup-kind
e2e-setup-kind: check-env-vars ## Setup kind cluster and install operator.
# Validates prerequisites
$(foreach bin,$(SETUP_PREREQUISITES),\
$(if $(shell command -v $(bin) 2> /dev/null),,$(error Please install `$(bin)` first)))
@[ "${AIVEN_TOKEN}" ] || ( echo ">> variable AIVEN_TOKEN is not set"; exit 1 )
@[ "${AIVEN_PROJECT_NAME}" ] || ( echo ">> variable AIVEN_PROJECT_NAME is not set"; exit 1 )

# Cleans previous installation. Ignores errors
helm uninstall aiven-operator-crds || true
helm uninstall aiven-operator || true
kubectl delete secret aiven-token || true

# Cleanups cert-manager
helm uninstall cert-manager || true
kubectl delete namespace cert-manager || true

# Installs cert manager if webhooks enabled
# We use helm here instead of "kubectl apply", because it waits pods up and running
# Otherwise, operator will fail webhook check
ifeq ($(WEBHOOKS_ENABLED), true)

# Check that kind cluster is running. Keep the --image argument in sync with developer-docs.md
@kubectl config view -o jsonpath='{.contexts[*].name}' | grep -q kind-kind || \
(echo ">> Kind cluster not found. Please create it using 'kind create cluster --image kindest/node:v1.26.6 --wait 5m'"; exit 1)

$(MAKE) cleanup

# Installs cert manager if webhooks enabled
# We use helm here instead of "kubectl apply", because it waits pods up and running
# Otherwise, operator will fail webhook check
ifeq ($(ENABLE_WEBHOOKS), true)
helm repo add jetstack https://charts.jetstack.io
helm repo update
helm install \
Expand All @@ -225,11 +255,16 @@ ifeq ($(WEBHOOKS_ENABLED), true)
--set installCRDs=true
endif

# Builds the operator
$(PODMAN) build -t ${OPERATOR_IMAGE_NAME}:${OPERATOR_IMAGE_TAG} .
# Builds the operator
$(CONTAINER_TOOL) build -t ${OPERATOR_IMAGE_NAME}:${OPERATOR_IMAGE_TAG} .
ifeq ($(CONTAINER_TOOL), podman)
podman image save --format oci-archive ${OPERATOR_IMAGE_NAME}:${OPERATOR_IMAGE_TAG} -o /tmp/operator-image.tar
kind load image-archive /tmp/operator-image.tar
else
kind load docker-image $(OPERATOR_IMAGE_NAME):$(OPERATOR_IMAGE_TAG)
endif

# Installs operators charts
# Installs operators charts
kubectl create secret generic aiven-token --from-literal=token=$(AIVEN_TOKEN)
helm install aiven-operator-crds charts/aiven-operator-crds
helm install \
Expand All @@ -241,25 +276,19 @@ endif
--set image.pullPolicy="Never" \
--set resources.requests.cpu=0 \
--set resources.requests.memory=0 \
--set webhooks.enabled=${WEBHOOKS_ENABLED} \
--set webhooks.enabled=${ENABLE_WEBHOOKS} \
aiven-operator charts/aiven-operator

# On MACOS requires gnu-sed. Run `brew info gnu-sed` and follow instructions to replace default sed.
.PHONY: imports
imports:
find . -type f -name '*.go' -exec sed -zi 's/"\n\+\t"/"\n"/g' {} +
goimports -local "github.com/aiven/aiven-operator" -w .

# go-install-tool will 'go install' any package with custom target and name of binary, if it doesn't exist
# $1 - target path with name of binary (ideally with version)
# $2 - package url which can be installed
# $3 - specific version of package
define go-install-tool
@[ -f $(1) ] || { \
set -e; \
package=$(2)@$(3) ;\
echo "Downloading $${package}" ;\
GOBIN=$(LOCALBIN) go install $${package} ;\
mv "$$(echo "$(1)" | sed "s/-$(3)$$//")" $(1) ;\
}
@[ -f $(1) ] || { \
set -e; \
package=$(2)@$(3) ;\
echo "Downloading $${package}" ;\
GOBIN=$(LOCALBIN) go install $${package} ;\
mv "$$(echo "$(1)" | sed "s/-$(3)$$//")" $(1) ;\
}
endef
21 changes: 21 additions & 0 deletions docs/docs/.snippets/pg-example.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
apiVersion: aiven.io/v1alpha1
kind: PostgreSQL
metadata:
name: aiven-devdocs-pg
spec:
# reads the authentication token
authSecretRef:
name: aiven-token
key: token

# stores the PostgreSQL connection information on the specified Secret
connInfoSecretTarget:
name: pg-connection

project: <your-project-name>
cloudName: google-europe-west1
plan: hobbyist
maintenanceWindowDow: friday
maintenanceWindowTime: 23:00:00
userConfig:
pg_version: "15"
Binary file added docs/docs/assets/developer-guide-k9s.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions docs/docs/authentication.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ for a free trial. 🦀**

1\. Generate an authentication token

Refer to [our documentation article](https://help.aiven.io/en/articles/2059201-authentication-tokens) to generate your
Refer to [our documentation article](https://aiven.io/docs/platform/concepts/authentication-tokens) to generate your
authentication token.

2\. Create the Kubernetes Secret
Expand Down Expand Up @@ -42,7 +42,7 @@ spec:

Also, note that within Aiven, all resources are conceptually inside a _Project_. By default, a random project name is
generated when you signup, but you can
also [create new projects](https://help.aiven.io/en/articles/5039826-how-to-create-new-project).
also [create new projects](https://aiven.io/docs/platform/howto/manage-project).

The Project name is required in most of the resources. It will look like the example below:

Expand Down
Loading

0 comments on commit fd751c1

Please sign in to comment.