Skip to content

Commit c2a3c27

Browse files
feat(api): add Crossplane and ProviderConfig (#2)
* feat(api): add `Crossplane` and `ProviderConfig` * chore: add `VERSION` file * chore: remove test files for now * feat(api): first design `ProviderConfig` * chore: update sample * feat(api): first design `Crossplane` * chore: remove unnecessary files * Delete .github/workflows/test.yml * Delete .github/workflows/lint.yml * fix(api): `Crossplane` config * fix(api): `ProviderConfig` config * fix(api): remove description * fix(api): update description * chore: `go mod tidy` * feat: add `CommonStatus` struct from openmcp-operator --------- Co-authored-by: Valentin Gerlach <[email protected]>
1 parent 62adf83 commit c2a3c27

Some content is hidden

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

48 files changed

+2823
-0
lines changed

.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: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
version: "2"
2+
run:
3+
allow-parallel-runners: true
4+
linters:
5+
default: none
6+
enable:
7+
- copyloopvar
8+
- dupl
9+
- errcheck
10+
- ginkgolinter
11+
- goconst
12+
- gocyclo
13+
- govet
14+
- ineffassign
15+
- lll
16+
- misspell
17+
- nakedret
18+
- prealloc
19+
- revive
20+
- staticcheck
21+
- unconvert
22+
- unparam
23+
- unused
24+
settings:
25+
revive:
26+
rules:
27+
- name: comment-spacings
28+
- name: import-shadowing
29+
exclusions:
30+
generated: lax
31+
rules:
32+
- linters:
33+
- lll
34+
path: api/*
35+
- linters:
36+
- dupl
37+
- lll
38+
path: internal/*
39+
paths:
40+
- third_party$
41+
- builtin$
42+
- examples$
43+
formatters:
44+
enable:
45+
- gofmt
46+
- goimports
47+
exclusions:
48+
generated: lax
49+
paths:
50+
- third_party$
51+
- builtin$
52+
- examples$

Makefile

Lines changed: 238 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,238 @@
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+
KIND_CLUSTER ?= service-provider-crossplane-test-e2e
69+
70+
.PHONY: setup-test-e2e
71+
setup-test-e2e: ## Set up a Kind cluster for e2e tests if it does not exist
72+
@command -v $(KIND) >/dev/null 2>&1 || { \
73+
echo "Kind is not installed. Please install Kind manually."; \
74+
exit 1; \
75+
}
76+
@case "$$($(KIND) get clusters)" in \
77+
*"$(KIND_CLUSTER)"*) \
78+
echo "Kind cluster '$(KIND_CLUSTER)' already exists. Skipping creation." ;; \
79+
*) \
80+
echo "Creating Kind cluster '$(KIND_CLUSTER)'..."; \
81+
$(KIND) create cluster --name $(KIND_CLUSTER) ;; \
82+
esac
83+
84+
.PHONY: test-e2e
85+
test-e2e: setup-test-e2e manifests generate fmt vet ## Run the e2e tests. Expected an isolated environment using Kind.
86+
KIND_CLUSTER=$(KIND_CLUSTER) go test ./test/e2e/ -v -ginkgo.v
87+
$(MAKE) cleanup-test-e2e
88+
89+
.PHONY: cleanup-test-e2e
90+
cleanup-test-e2e: ## Tear down the Kind cluster used for e2e tests
91+
@$(KIND) delete cluster --name $(KIND_CLUSTER)
92+
93+
.PHONY: lint
94+
lint: golangci-lint ## Run golangci-lint linter
95+
$(GOLANGCI_LINT) run
96+
97+
.PHONY: lint-fix
98+
lint-fix: golangci-lint ## Run golangci-lint linter and perform fixes
99+
$(GOLANGCI_LINT) run --fix
100+
101+
.PHONY: lint-config
102+
lint-config: golangci-lint ## Verify golangci-lint linter configuration
103+
$(GOLANGCI_LINT) config verify
104+
105+
##@ Build
106+
107+
.PHONY: build
108+
build: manifests generate fmt vet ## Build manager binary.
109+
go build -o bin/manager cmd/main.go
110+
111+
.PHONY: run
112+
run: manifests generate fmt vet ## Run a controller from your host.
113+
go run ./cmd/main.go
114+
115+
# If you wish to build the manager image targeting other platforms you can use the --platform flag.
116+
# (i.e. docker build --platform linux/arm64). However, you must enable docker buildKit for it.
117+
# More info: https://docs.docker.com/develop/develop-images/build_enhancements/
118+
.PHONY: docker-build
119+
docker-build: ## Build docker image with the manager.
120+
$(CONTAINER_TOOL) build -t ${IMG} .
121+
122+
.PHONY: docker-push
123+
docker-push: ## Push docker image with the manager.
124+
$(CONTAINER_TOOL) push ${IMG}
125+
126+
# PLATFORMS defines the target platforms for the manager image be built to provide support to multiple
127+
# architectures. (i.e. make docker-buildx IMG=myregistry/mypoperator:0.0.1). To use this option you need to:
128+
# - be able to use docker buildx. More info: https://docs.docker.com/build/buildx/
129+
# - have enabled BuildKit. More info: https://docs.docker.com/develop/develop-images/build_enhancements/
130+
# - 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)
131+
# To adequately provide solutions that are compatible with multiple platforms, you should consider using this option.
132+
PLATFORMS ?= linux/arm64,linux/amd64,linux/s390x,linux/ppc64le
133+
.PHONY: docker-buildx
134+
docker-buildx: ## Build and push docker image for the manager for cross-platform support
135+
# copy existing Dockerfile and insert --platform=${BUILDPLATFORM} into Dockerfile.cross, and preserve the original Dockerfile
136+
sed -e '1 s/\(^FROM\)/FROM --platform=\$$\{BUILDPLATFORM\}/; t' -e ' 1,// s//FROM --platform=\$$\{BUILDPLATFORM\}/' Dockerfile > Dockerfile.cross
137+
- $(CONTAINER_TOOL) buildx create --name service-provider-crossplane-builder
138+
$(CONTAINER_TOOL) buildx use service-provider-crossplane-builder
139+
- $(CONTAINER_TOOL) buildx build --push --platform=$(PLATFORMS) --tag ${IMG} -f Dockerfile.cross .
140+
- $(CONTAINER_TOOL) buildx rm service-provider-crossplane-builder
141+
rm Dockerfile.cross
142+
143+
.PHONY: build-installer
144+
build-installer: manifests generate kustomize ## Generate a consolidated YAML with CRDs and deployment.
145+
mkdir -p dist
146+
cd config/manager && $(KUSTOMIZE) edit set image controller=${IMG}
147+
$(KUSTOMIZE) build config/default > dist/install.yaml
148+
149+
##@ Deployment
150+
151+
ifndef ignore-not-found
152+
ignore-not-found = false
153+
endif
154+
155+
.PHONY: install
156+
install: manifests kustomize ## Install CRDs into the K8s cluster specified in ~/.kube/config.
157+
$(KUSTOMIZE) build config/crd | $(KUBECTL) apply -f -
158+
159+
.PHONY: uninstall
160+
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.
161+
$(KUSTOMIZE) build config/crd | $(KUBECTL) delete --ignore-not-found=$(ignore-not-found) -f -
162+
163+
.PHONY: deploy
164+
deploy: manifests kustomize ## Deploy controller to the K8s cluster specified in ~/.kube/config.
165+
cd config/manager && $(KUSTOMIZE) edit set image controller=${IMG}
166+
$(KUSTOMIZE) build config/default | $(KUBECTL) apply -f -
167+
168+
.PHONY: undeploy
169+
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.
170+
$(KUSTOMIZE) build config/default | $(KUBECTL) delete --ignore-not-found=$(ignore-not-found) -f -
171+
172+
##@ Dependencies
173+
174+
## Location to install dependencies to
175+
LOCALBIN ?= $(shell pwd)/bin
176+
$(LOCALBIN):
177+
mkdir -p $(LOCALBIN)
178+
179+
## Tool Binaries
180+
KUBECTL ?= kubectl
181+
KIND ?= kind
182+
KUSTOMIZE ?= $(LOCALBIN)/kustomize
183+
CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen
184+
ENVTEST ?= $(LOCALBIN)/setup-envtest
185+
GOLANGCI_LINT = $(LOCALBIN)/golangci-lint
186+
187+
## Tool Versions
188+
KUSTOMIZE_VERSION ?= v5.6.0
189+
CONTROLLER_TOOLS_VERSION ?= v0.18.0
190+
#ENVTEST_VERSION is the version of controller-runtime release branch to fetch the envtest setup script (i.e. release-0.20)
191+
ENVTEST_VERSION ?= $(shell go list -m -f "{{ .Version }}" sigs.k8s.io/controller-runtime | awk -F'[v.]' '{printf "release-%d.%d", $$2, $$3}')
192+
#ENVTEST_K8S_VERSION is the version of Kubernetes to use for setting up ENVTEST binaries (i.e. 1.31)
193+
ENVTEST_K8S_VERSION ?= $(shell go list -m -f "{{ .Version }}" k8s.io/api | awk -F'[v.]' '{printf "1.%d", $$3}')
194+
GOLANGCI_LINT_VERSION ?= v2.1.6
195+
196+
.PHONY: kustomize
197+
kustomize: $(KUSTOMIZE) ## Download kustomize locally if necessary.
198+
$(KUSTOMIZE): $(LOCALBIN)
199+
$(call go-install-tool,$(KUSTOMIZE),sigs.k8s.io/kustomize/kustomize/v5,$(KUSTOMIZE_VERSION))
200+
201+
.PHONY: controller-gen
202+
controller-gen: $(CONTROLLER_GEN) ## Download controller-gen locally if necessary.
203+
$(CONTROLLER_GEN): $(LOCALBIN)
204+
$(call go-install-tool,$(CONTROLLER_GEN),sigs.k8s.io/controller-tools/cmd/controller-gen,$(CONTROLLER_TOOLS_VERSION))
205+
206+
.PHONY: setup-envtest
207+
setup-envtest: envtest ## Download the binaries required for ENVTEST in the local bin directory.
208+
@echo "Setting up envtest binaries for Kubernetes version $(ENVTEST_K8S_VERSION)..."
209+
@$(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path || { \
210+
echo "Error: Failed to set up envtest binaries for version $(ENVTEST_K8S_VERSION)."; \
211+
exit 1; \
212+
}
213+
214+
.PHONY: envtest
215+
envtest: $(ENVTEST) ## Download setup-envtest locally if necessary.
216+
$(ENVTEST): $(LOCALBIN)
217+
$(call go-install-tool,$(ENVTEST),sigs.k8s.io/controller-runtime/tools/setup-envtest,$(ENVTEST_VERSION))
218+
219+
.PHONY: golangci-lint
220+
golangci-lint: $(GOLANGCI_LINT) ## Download golangci-lint locally if necessary.
221+
$(GOLANGCI_LINT): $(LOCALBIN)
222+
$(call go-install-tool,$(GOLANGCI_LINT),github.com/golangci/golangci-lint/v2/cmd/golangci-lint,$(GOLANGCI_LINT_VERSION))
223+
224+
# go-install-tool will 'go install' any package with custom target and name of binary, if it doesn't exist
225+
# $1 - target path with name of binary
226+
# $2 - package url which can be installed
227+
# $3 - specific version of package
228+
define go-install-tool
229+
@[ -f "$(1)-$(3)" ] || { \
230+
set -e; \
231+
package=$(2)@$(3) ;\
232+
echo "Downloading $${package}" ;\
233+
rm -f $(1) || true ;\
234+
GOBIN=$(LOCALBIN) go install $${package} ;\
235+
mv $(1) $(1)-$(3) ;\
236+
} ;\
237+
ln -sf $(1)-$(3) $(1)
238+
endef

PROJECT

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
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+
cliVersion: 4.7.1
6+
domain: crossplane.services.openmcp.cloud
7+
layout:
8+
- go.kubebuilder.io/v4
9+
projectName: service-provider-crossplane
10+
repo: github.com/openmcp-project/service-provider-crossplane
11+
resources:
12+
- api:
13+
crdVersion: v1
14+
namespaced: true
15+
controller: true
16+
domain: crossplane.services.openmcp.cloud
17+
kind: Crossplane
18+
path: github.com/openmcp-project/service-provider-crossplane/api/v1alpha1
19+
version: v1alpha1
20+
- api:
21+
crdVersion: v1
22+
namespaced: true
23+
controller: true
24+
domain: crossplane.services.openmcp.cloud
25+
kind: ProviderConfig
26+
path: github.com/openmcp-project/service-provider-crossplane/api/v1alpha1
27+
version: v1alpha1
28+
version: "3"

VERSION

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
v0.0.1

0 commit comments

Comments
 (0)