Skip to content

Commit ff7e27a

Browse files
committed
kcp provider changes
1 parent 258f6f9 commit ff7e27a

File tree

9 files changed

+268
-151
lines changed

9 files changed

+268
-151
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,6 @@ go.work
2525
*.swp
2626
*.swo
2727
*~
28+
29+
hack/tools/apigen
30+
bin/*

Makefile

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,8 @@ build: manifests generate fmt vet ## Build manager binary.
9696
go build -o bin/manager cmd/main.go
9797

9898
.PHONY: run
99-
run: manifests generate fmt vet ## Run a controller from your host.
100-
go run ./cmd/main.go
99+
run: manifests kcp-tools generate kcp-generate fmt vet ## Run a controller from your host.
100+
go run ./cmd/main.go --server=$$(kubectl get apiexport apis.contrib.kcp.io -o jsonpath="{.status.virtualWorkspaces[0].url}")
101101

102102
# If you wish to build the manager image targeting other platforms you can use the --platform flag.
103103
# (i.e. docker build --platform linux/arm64). However, you must enable docker buildKit for it.
@@ -222,3 +222,30 @@ mv $(1) $(1)-$(3) ;\
222222
} ;\
223223
ln -sf $(1)-$(3) $(1)
224224
endef
225+
226+
# MUTLICLUSTER-PROVIDER KCP SPECIFIC:
227+
TOOLS_DIR=hack/tools
228+
ARCH := $(shell go env GOARCH)
229+
OS := $(shell go env GOOS)
230+
231+
KCP_APIGEN_BIN := apigen
232+
KCP_APIGEN_VERSION ?= 0.27.0-rc.1
233+
# Construct the download URL.
234+
DOWNLOAD_URL = https://github.com/kcp-dev/kcp/releases/download/v$(KCP_APIGEN_VERSION)/apigen_$(KCP_APIGEN_VERSION)_$(OS)_$(ARCH).tar.gz
235+
KCP_APIGEN_GEN := $(TOOLS_DIR)/$(KCP_APIGEN_BIN)
236+
export KCP_APIGEN_GEN # so hack scripts can use it
237+
238+
# TODO: move to binary to avoid depeendencies
239+
$(KCP_APIGEN_GEN):
240+
# Create a temporary directory for download and extraction
241+
TMP_DIR=$$(mktemp -d) ; \
242+
curl -L -o $$TMP_DIR/apigen.tar.gz $(DOWNLOAD_URL) ; \
243+
tar -xzf $$TMP_DIR/apigen.tar.gz -C $$TMP_DIR ; \
244+
mv $$TMP_DIR/bin/apigen $(KCP_APIGEN_GEN) ; \
245+
rm -rf $$TMP_DIR
246+
247+
kcp-tools: $(KCP_APIGEN_GEN)
248+
.PHONY: kcp-tools
249+
250+
kcp-generate:
251+
$(TOOLS_DIR)/apigen --input-dir ./config/crd/bases --output-dir ./config/kcp

README.md

Lines changed: 45 additions & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -1,135 +1,78 @@
11
# multicluster-provider-kubebuilder-example
2-
// TODO(user): Add simple overview of use/purpose
32

4-
## Description
5-
// TODO(user): An in-depth paragraph about your project and overview of use
3+
A full kcp multicluster-provider example using kubebuilder.
64

7-
## Getting Started
5+
This example demonstrates how to lift&shift a kubebuilder project to a multicluster-provider project for kcp.
86

9-
### Prerequisites
10-
- go version v1.23.0+
11-
- docker version 17.03+.
12-
- kubectl version v1.11.3+.
13-
- Access to a Kubernetes v1.11.3+ cluster.
14-
15-
### To Deploy on the cluster
16-
**Build and push your image to the location specified by `IMG`:**
17-
18-
```sh
19-
make docker-build docker-push IMG=<some-registry>/multicluster-provider-kubebuilder-example:tag
20-
```
7+
There should be 2 commits in this repository at all times:
218

22-
**NOTE:** This image ought to be published in the personal registry you specified.
23-
And it is required to have access to pull the image from the working environment.
24-
Make sure you have the proper permission to the registry if the above commands don’t work.
9+
1. The initial commit with the kubebuilder project.
2510

26-
**Install the CRDs into the cluster:**
11+
Skeleton created by running [kubebuilder](https://book.kubebuilder.io/quick-start.html) with the following command:
2712

2813
```sh
29-
make install
14+
$ kubebuilder init --domain contrib.kcp.io --repo github.com/kcp-dev/multicluster-provider-kubebuilder-example
15+
$ kubebuilder create api --group apis --version v1alpha1 --kind Application
3016
```
3117

32-
**Deploy the Manager to the cluster with the image specified by `IMG`:**
18+
2. The commit with the kubebuilder project lifted&shifted to a multicluster-provider project to work with kcp.
3319

34-
```sh
35-
make deploy IMG=<some-registry>/multicluster-provider-kubebuilder-example:tag
36-
```
20+
Please refer to main repositories for more information:
3721

38-
> **NOTE**: If you encounter RBAC errors, you may need to grant yourself cluster-admin
39-
privileges or be logged in as admin.
22+
- [multicluster-provider for kcp](https://github.com/kcp-dev/multicluster-provider)
23+
- [multicluster-runtime](https://github.com/multicluster-runtime/multicluster-runtime)
24+
- [kcp](https://github.com/kcp-dev/kcp)
4025

41-
**Create instances of your solution**
42-
You can apply the samples (examples) from the config/sample:
4326

44-
```sh
45-
kubectl apply -k config/samples/
46-
```
27+
## Customizations & Run
4728

48-
>**NOTE**: Ensure that the samples has default values to test it out.
49-
50-
### To Uninstall
51-
**Delete the instances (CRs) from the cluster:**
52-
53-
```sh
54-
kubectl delete -k config/samples/
55-
```
56-
57-
**Delete the APIs(CRDs) from the cluster:**
29+
### Prerequisites
5830

59-
```sh
60-
make uninstall
61-
```
31+
- [kcp](https://github.com/kcp-dev/kcp) installed and running
32+
- [kcp krew plugins](https://docs.kcp.io/kcp/v0.26/setup/kubectl-plugin/) installed
6233

63-
**UnDeploy the controller from the cluster:**
34+
1. Make file targets to install kcp specific tooling and generate kcp specific manifests:
6435

6536
```sh
66-
make undeploy
37+
# install tooling
38+
make kcp-tools
39+
# generate kcp manifests
40+
make kcp-generate
6741
```
6842

69-
## Project Distribution
43+
After than content of `cmd/main.go` was updated with multicluster extension.
7044

71-
Following the options to release and provide this solution to the users.
45+
It can be tested by applying the necessary manifests from the respective folder while connected to the `root` workspace of a kcp instance:
7246

73-
### By providing a bundle with all YAML files
74-
75-
1. Build the installer for the image built and published in the registry:
47+
export KUBECONFIG=admin.kubeconfig
7648

7749
```sh
78-
make build-installer IMG=<some-registry>/multicluster-provider-kubebuilder-example:tag
50+
kubectl ws create provider --enter
51+
kubectl apply -f ./config/kcp/apiresourceschema-applications.apis.contrib.kcp.io.yaml
52+
kubectl apply -f ./config/kcp/apiexport-apis.contrib.kcp.io.yaml
53+
54+
# Consumer 1
55+
kubectl ws use :root
56+
kubectl ws create examples-kubebuilder-multicluster-1 --enter
57+
kubectl kcp bind apiexport root:provider:apis.contrib.kcp.io
58+
kubectl apply -f ./config/samples/apis_v1alpha1_application.yaml
59+
60+
# Consumer 2
61+
kubectl ws use :root
62+
kubectl ws create examples-kubebuilder-multicluster-2 --enter
63+
kubectl kcp bind apiexport root:provider:apis.contrib.kcp.io
64+
kubectl apply -f ./config/samples/apis_v1alpha1_application.yaml
7965
```
8066

81-
**NOTE:** The makefile target mentioned above generates an 'install.yaml'
82-
file in the dist directory. This file contains all the resources built
83-
with Kustomize, which are necessary to install this project without its
84-
dependencies.
85-
86-
2. Using the installer
87-
88-
Users can just run 'kubectl apply -f <URL for YAML BUNDLE>' to install
89-
the project, i.e.:
67+
Then, start the example controller by passing the virtual workspace URL to it:
9068

9169
```sh
92-
kubectl apply -f https://raw.githubusercontent.com/<org>/multicluster-provider-kubebuilder-example/<tag or branch>/dist/install.yaml
70+
kubectl ws use :root:provider
71+
make run
9372
```
9473

95-
### By providing a Helm Chart
96-
97-
1. Build the chart using the optional helm plugin
74+
Observe the controller reconciling the ` application-sample` Aplication in the workspaces:
9875

9976
```sh
100-
kubebuilder edit --plugins=helm/v1-alpha
101-
```
102-
103-
2. See that a chart was generated under 'dist/chart', and users
104-
can obtain this solution from there.
105-
106-
**NOTE:** If you change the project, you need to update the Helm Chart
107-
using the same command above to sync the latest changes. Furthermore,
108-
if you create webhooks, you need to use the above command with
109-
the '--force' flag and manually ensure that any custom configuration
110-
previously added to 'dist/chart/values.yaml' or 'dist/chart/manager/manager.yaml'
111-
is manually re-applied afterwards.
112-
113-
## Contributing
114-
// TODO(user): Add detailed information on how you would like others to contribute to this project
115-
116-
**NOTE:** Run `make help` for more information on all potential `make` targets
117-
118-
More information can be found via the [Kubebuilder Documentation](https://book.kubebuilder.io/introduction.html)
119-
120-
## License
121-
122-
Copyright 2025.
123-
124-
Licensed under the Apache License, Version 2.0 (the "License");
125-
you may not use this file except in compliance with the License.
126-
You may obtain a copy of the License at
127-
128-
http://www.apache.org/licenses/LICENSE-2.0
129-
130-
Unless required by applicable law or agreed to in writing, software
131-
distributed under the License is distributed on an "AS IS" BASIS,
132-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
133-
See the License for the specific language governing permissions and
134-
limitations under the License.
135-
77+
2025-03-11T13:04:52+02:00 INFO Reconciling Application {"controller": "kcp-applications-controller", "controllerGroup": "apis.contrib.kcp.io", "controllerKind": "Application", "reconcileID": "babfc696-50cc-4851-ab35-d1d956a6c120", "cluster": "1058d5hgzdd3ask6"}
78+
```

0 commit comments

Comments
 (0)