Skip to content

Commit 64c7f62

Browse files
chore: open source repository (#1)
Co-authored-by: Valentin Gerlach <[email protected]>
1 parent cfbb4b4 commit 64c7f62

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+6724
-4
lines changed

.dockerignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# More info: https://docs.docker.com/engine/reference/builder/#dockerignore-file
2+
# Ignore build and test binaries.
3+
bin/

.gitignore

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Binaries for programs and plugins
2+
*.exe
3+
*.exe~
4+
*.dll
5+
*.so
6+
*.dylib
7+
bin/*
8+
Dockerfile.cross
9+
10+
# Test binary, built with `go test -c`
11+
*.test
12+
13+
# Output of the go coverage tool, specifically when used with LiteIDE
14+
*.out
15+
16+
# Go workspace file
17+
go.work
18+
19+
# Kubernetes Generated files - skip generated files, except for vendored files
20+
!vendor/**/zz_generated.*
21+
22+
# editor and IDE paraphernalia
23+
.idea
24+
.vscode
25+
*.swp
26+
*.swo
27+
*~

.golangci.yml

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
run:
2+
timeout: 5m
3+
allow-parallel-runners: true
4+
5+
issues:
6+
# don't skip warning about doc comments
7+
# don't exclude the default set of lint
8+
exclude-use-default: false
9+
# restore some of the defaults
10+
# (fill in the rest as needed)
11+
exclude-rules:
12+
- path: "api/*"
13+
linters:
14+
- lll
15+
- path: "internal/*"
16+
linters:
17+
- dupl
18+
- lll
19+
linters:
20+
disable-all: true
21+
enable:
22+
- dupl
23+
- errcheck
24+
- copyloopvar
25+
- ginkgolinter
26+
- goconst
27+
- gocyclo
28+
- gofmt
29+
- goimports
30+
- gosimple
31+
- govet
32+
- ineffassign
33+
- lll
34+
- misspell
35+
- nakedret
36+
- prealloc
37+
- revive
38+
- staticcheck
39+
- typecheck
40+
- unconvert
41+
- unparam
42+
- unused
43+
44+
linters-settings:
45+
revive:
46+
rules:
47+
- name: comment-spacings

Dockerfile

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Build the manager binary
2+
FROM docker.io/golang:1.23 AS builder
3+
ARG TARGETOS
4+
ARG TARGETARCH
5+
6+
WORKDIR /workspace
7+
# Copy the Go Modules manifests
8+
COPY go.mod go.mod
9+
COPY go.sum go.sum
10+
# cache deps before building and copying source so that we don't need to re-download as much
11+
# and so that source changes don't invalidate our downloaded layer
12+
RUN go mod download
13+
14+
# Copy the go source
15+
COPY cmd/main.go cmd/main.go
16+
COPY api/ api/
17+
COPY internal/ internal/
18+
COPY pkg/ pkg/
19+
20+
# Build
21+
# the GOARCH has not a default value to allow the binary be built according to the host where the command
22+
# was called. For example, if we call make docker-build in a local env which has the Apple Silicon M1 SO
23+
# the docker BUILDPLATFORM arg will be linux/arm64 when for Apple x86 it will be linux/amd64. Therefore,
24+
# by leaving it empty we can ensure that the container and binary shipped on it will have the same platform.
25+
RUN CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} go build -a -o manager cmd/main.go
26+
27+
FROM alpine:3.21.3
28+
RUN apk add --no-cache docker-cli kind
29+
WORKDIR /
30+
COPY --from=builder /workspace/manager .
31+
USER 65532:65532
32+
33+
ENTRYPOINT ["/manager"]

Makefile

Lines changed: 224 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,224 @@
1+
# Image URL to use all building/pushing image targets
2+
IMG ?= controller:latest
3+
4+
# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
5+
ifeq (,$(shell go env GOBIN))
6+
GOBIN=$(shell go env GOPATH)/bin
7+
else
8+
GOBIN=$(shell go env GOBIN)
9+
endif
10+
11+
# CONTAINER_TOOL defines the container tool to be used for building images.
12+
# Be aware that the target commands are only tested with Docker which is
13+
# scaffolded by default. However, you might want to replace it to use other
14+
# tools. (i.e. podman)
15+
CONTAINER_TOOL ?= docker
16+
17+
# Setting SHELL to bash allows bash commands to be executed by recipes.
18+
# Options are set to exit when a recipe line exits non-zero or a piped command fails.
19+
SHELL = /usr/bin/env bash -o pipefail
20+
.SHELLFLAGS = -ec
21+
22+
.PHONY: all
23+
all: build
24+
25+
##@ General
26+
27+
# The help target prints out all targets with their descriptions organized
28+
# beneath their categories. The categories are represented by '##@' and the
29+
# target descriptions by '##'. The awk command is responsible for reading the
30+
# entire set of makefiles included in this invocation, looking for lines of the
31+
# file as xyz: ## something, and then pretty-format the target and help. Then,
32+
# if there's a line with ##@ something, that gets pretty-printed as a category.
33+
# More info on the usage of ANSI control characters for terminal formatting:
34+
# https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_parameters
35+
# More info on the awk command:
36+
# http://linuxcommand.org/lc3_adv_awk.php
37+
38+
.PHONY: help
39+
help: ## Display this help.
40+
@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)
41+
42+
##@ Development
43+
44+
.PHONY: manifests
45+
manifests: controller-gen ## Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects.
46+
$(CONTROLLER_GEN) rbac:roleName=manager-role crd webhook paths="./..." output:crd:artifacts:config=config/crd/bases
47+
48+
.PHONY: generate
49+
generate: controller-gen ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.
50+
$(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./..."
51+
52+
.PHONY: fmt
53+
fmt: ## Run go fmt against code.
54+
go fmt ./...
55+
56+
.PHONY: vet
57+
vet: ## Run go vet against code.
58+
go vet ./...
59+
60+
.PHONY: test
61+
test: manifests generate fmt vet setup-envtest ## Run tests.
62+
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path)" go test $$(go list ./... | grep -v /e2e) -coverprofile cover.out
63+
64+
# TODO(user): To use a different vendor for e2e tests, modify the setup under 'tests/e2e'.
65+
# The default setup assumes Kind is pre-installed and builds/loads the Manager Docker image locally.
66+
# CertManager is installed by default; skip with:
67+
# - CERT_MANAGER_INSTALL_SKIP=true
68+
.PHONY: test-e2e
69+
test-e2e: manifests generate fmt vet ## Run the e2e tests. Expected an isolated environment using Kind.
70+
@command -v kind >/dev/null 2>&1 || { \
71+
echo "Kind is not installed. Please install Kind manually."; \
72+
exit 1; \
73+
}
74+
@kind get clusters | grep -q 'kind' || { \
75+
echo "No Kind cluster is running. Please start a Kind cluster before running the e2e tests."; \
76+
exit 1; \
77+
}
78+
go test ./test/e2e/ -v -ginkgo.v
79+
80+
.PHONY: lint
81+
lint: golangci-lint ## Run golangci-lint linter
82+
$(GOLANGCI_LINT) run
83+
84+
.PHONY: lint-fix
85+
lint-fix: golangci-lint ## Run golangci-lint linter and perform fixes
86+
$(GOLANGCI_LINT) run --fix
87+
88+
.PHONY: lint-config
89+
lint-config: golangci-lint ## Verify golangci-lint linter configuration
90+
$(GOLANGCI_LINT) config verify
91+
92+
##@ Build
93+
94+
.PHONY: build
95+
build: manifests generate fmt vet ## Build manager binary.
96+
go build -o bin/manager cmd/main.go
97+
98+
.PHONY: run
99+
run: manifests generate fmt vet ## Run a controller from your host.
100+
go run ./cmd/main.go
101+
102+
# If you wish to build the manager image targeting other platforms you can use the --platform flag.
103+
# (i.e. docker build --platform linux/arm64). However, you must enable docker buildKit for it.
104+
# More info: https://docs.docker.com/develop/develop-images/build_enhancements/
105+
.PHONY: docker-build
106+
docker-build: ## Build docker image with the manager.
107+
$(CONTAINER_TOOL) build -t ${IMG} .
108+
109+
.PHONY: docker-push
110+
docker-push: ## Push docker image with the manager.
111+
$(CONTAINER_TOOL) push ${IMG}
112+
113+
# PLATFORMS defines the target platforms for the manager image be built to provide support to multiple
114+
# architectures. (i.e. make docker-buildx IMG=myregistry/mypoperator:0.0.1). To use this option you need to:
115+
# - be able to use docker buildx. More info: https://docs.docker.com/build/buildx/
116+
# - have enabled BuildKit. More info: https://docs.docker.com/develop/develop-images/build_enhancements/
117+
# - be able to push the image to your registry (i.e. if you do not set a valid value via IMG=<myregistry/image:<tag>> then the export will fail)
118+
# To adequately provide solutions that are compatible with multiple platforms, you should consider using this option.
119+
PLATFORMS ?= linux/arm64,linux/amd64,linux/s390x,linux/ppc64le
120+
.PHONY: docker-buildx
121+
docker-buildx: ## Build and push docker image for the manager for cross-platform support
122+
# copy existing Dockerfile and insert --platform=${BUILDPLATFORM} into Dockerfile.cross, and preserve the original Dockerfile
123+
sed -e '1 s/\(^FROM\)/FROM --platform=\$$\{BUILDPLATFORM\}/; t' -e ' 1,// s//FROM --platform=\$$\{BUILDPLATFORM\}/' Dockerfile > Dockerfile.cross
124+
- $(CONTAINER_TOOL) buildx create --name cluster-provider-kind-builder
125+
$(CONTAINER_TOOL) buildx use cluster-provider-kind-builder
126+
- $(CONTAINER_TOOL) buildx build --push --platform=$(PLATFORMS) --tag ${IMG} -f Dockerfile.cross .
127+
- $(CONTAINER_TOOL) buildx rm cluster-provider-kind-builder
128+
rm Dockerfile.cross
129+
130+
.PHONY: build-installer
131+
build-installer: manifests generate kustomize ## Generate a consolidated YAML with CRDs and deployment.
132+
mkdir -p dist
133+
cd config/manager && $(KUSTOMIZE) edit set image controller=${IMG}
134+
$(KUSTOMIZE) build config/default > dist/install.yaml
135+
136+
##@ Deployment
137+
138+
ifndef ignore-not-found
139+
ignore-not-found = false
140+
endif
141+
142+
.PHONY: install
143+
install: manifests kustomize ## Install CRDs into the K8s cluster specified in ~/.kube/config.
144+
$(KUSTOMIZE) build config/crd | $(KUBECTL) apply -f -
145+
146+
.PHONY: uninstall
147+
uninstall: manifests kustomize ## Uninstall CRDs from the K8s cluster specified in ~/.kube/config. Call with ignore-not-found=true to ignore resource not found errors during deletion.
148+
$(KUSTOMIZE) build config/crd | $(KUBECTL) delete --ignore-not-found=$(ignore-not-found) -f -
149+
150+
.PHONY: deploy
151+
deploy: manifests kustomize ## Deploy controller to the K8s cluster specified in ~/.kube/config.
152+
cd config/manager && $(KUSTOMIZE) edit set image controller=${IMG}
153+
$(KUSTOMIZE) build config/default | $(KUBECTL) apply -f -
154+
155+
.PHONY: undeploy
156+
undeploy: kustomize ## Undeploy controller from the K8s cluster specified in ~/.kube/config. Call with ignore-not-found=true to ignore resource not found errors during deletion.
157+
$(KUSTOMIZE) build config/default | $(KUBECTL) delete --ignore-not-found=$(ignore-not-found) -f -
158+
159+
##@ Dependencies
160+
161+
## Location to install dependencies to
162+
LOCALBIN ?= $(shell pwd)/bin
163+
$(LOCALBIN):
164+
mkdir -p $(LOCALBIN)
165+
166+
## Tool Binaries
167+
KUBECTL ?= kubectl
168+
KUSTOMIZE ?= $(LOCALBIN)/kustomize
169+
CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen
170+
ENVTEST ?= $(LOCALBIN)/setup-envtest
171+
GOLANGCI_LINT = $(LOCALBIN)/golangci-lint
172+
173+
## Tool Versions
174+
KUSTOMIZE_VERSION ?= v5.5.0
175+
CONTROLLER_TOOLS_VERSION ?= v0.17.2
176+
#ENVTEST_VERSION is the version of controller-runtime release branch to fetch the envtest setup script (i.e. release-0.20)
177+
ENVTEST_VERSION ?= $(shell go list -m -f "{{ .Version }}" sigs.k8s.io/controller-runtime | awk -F'[v.]' '{printf "release-%d.%d", $$2, $$3}')
178+
#ENVTEST_K8S_VERSION is the version of Kubernetes to use for setting up ENVTEST binaries (i.e. 1.31)
179+
ENVTEST_K8S_VERSION ?= $(shell go list -m -f "{{ .Version }}" k8s.io/api | awk -F'[v.]' '{printf "1.%d", $$3}')
180+
GOLANGCI_LINT_VERSION ?= v1.63.4
181+
182+
.PHONY: kustomize
183+
kustomize: $(KUSTOMIZE) ## Download kustomize locally if necessary.
184+
$(KUSTOMIZE): $(LOCALBIN)
185+
$(call go-install-tool,$(KUSTOMIZE),sigs.k8s.io/kustomize/kustomize/v5,$(KUSTOMIZE_VERSION))
186+
187+
.PHONY: controller-gen
188+
controller-gen: $(CONTROLLER_GEN) ## Download controller-gen locally if necessary.
189+
$(CONTROLLER_GEN): $(LOCALBIN)
190+
$(call go-install-tool,$(CONTROLLER_GEN),sigs.k8s.io/controller-tools/cmd/controller-gen,$(CONTROLLER_TOOLS_VERSION))
191+
192+
.PHONY: setup-envtest
193+
setup-envtest: envtest ## Download the binaries required for ENVTEST in the local bin directory.
194+
@echo "Setting up envtest binaries for Kubernetes version $(ENVTEST_K8S_VERSION)..."
195+
@$(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path || { \
196+
echo "Error: Failed to set up envtest binaries for version $(ENVTEST_K8S_VERSION)."; \
197+
exit 1; \
198+
}
199+
200+
.PHONY: envtest
201+
envtest: $(ENVTEST) ## Download setup-envtest locally if necessary.
202+
$(ENVTEST): $(LOCALBIN)
203+
$(call go-install-tool,$(ENVTEST),sigs.k8s.io/controller-runtime/tools/setup-envtest,$(ENVTEST_VERSION))
204+
205+
.PHONY: golangci-lint
206+
golangci-lint: $(GOLANGCI_LINT) ## Download golangci-lint locally if necessary.
207+
$(GOLANGCI_LINT): $(LOCALBIN)
208+
$(call go-install-tool,$(GOLANGCI_LINT),github.com/golangci/golangci-lint/cmd/golangci-lint,$(GOLANGCI_LINT_VERSION))
209+
210+
# go-install-tool will 'go install' any package with custom target and name of binary, if it doesn't exist
211+
# $1 - target path with name of binary
212+
# $2 - package url which can be installed
213+
# $3 - specific version of package
214+
define go-install-tool
215+
@[ -f "$(1)-$(3)" ] || { \
216+
set -e; \
217+
package=$(2)@$(3) ;\
218+
echo "Downloading $${package}" ;\
219+
rm -f $(1) || true ;\
220+
GOBIN=$(LOCALBIN) go install $${package} ;\
221+
mv $(1) $(1)-$(3) ;\
222+
} ;\
223+
ln -sf $(1)-$(3) $(1)
224+
endef

PROJECT

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Code generated by tool. DO NOT EDIT.
2+
# This file is used to track the info used to scaffold your project
3+
# and allow the plugins properly work.
4+
# More info: https://book.kubebuilder.io/reference/project-config.html
5+
domain: kind.clusters.openmcp.cloud
6+
layout:
7+
- go.kubebuilder.io/v4
8+
projectName: cluster-provider-kind
9+
repo: github.com/openmcp-project/cluster-provider-kind
10+
resources:
11+
- api:
12+
crdVersion: v1
13+
namespaced: true
14+
controller: true
15+
domain: kind.clusters.openmcp.cloud
16+
kind: Cluster
17+
path: github.com/openmcp-project/cluster-provider-kind/api/v1alpha1
18+
version: v1alpha1
19+
- api:
20+
crdVersion: v1
21+
namespaced: true
22+
controller: true
23+
domain: kind.clusters.openmcp.cloud
24+
kind: AccessRequest
25+
path: github.com/openmcp-project/cluster-provider-kind/api/v1alpha1
26+
version: v1alpha1
27+
version: "3"

0 commit comments

Comments
 (0)