Example code was moved into the kcp-dev/controller-runtime repository itself!
An example project that is multi-cluster aware and works with kcp
This repository contains an example project that works with APIExports and multiple kcp workspaces. It demonstrates two reconcilers:
-
ConfigMap
- Get a ConfigMap for the key from the queue, from the correct logical cluster
- If the ConfigMap has labels["name"], set labels["response"] = "hello-$name" and save the changes
- List all ConfigMaps in the logical cluster and log each one's namespace and name
- If the ConfigMap from step 1 has data["namespace"] set, create a namespace whose name is the data value.
- If the ConfigMap from step 1 has data["secretData"] set, create a secret in the same namespace as the ConfigMap, with an owner reference to the ConfigMap, and data["dataFromCM"] set to the data value.
-
Widget
- Show how to list all Widget instances across all logical clusters
- Get a Widget for the key from the queue, from the correct logical cluster
- List all Widgets in the same logical cluster
- Count the number of Widgets (list length)
- Make sure
.status.total
matches the current count (via apatch
)
- Build and push your image to the location specified by
IMG
:
make docker-build docker-push REGISTRY=<some-registry> IMG=controller-runtime-example:tag
- Deploy the controller to kcp with the image specified by
IMG
:
make deploy REGISTRY=<some-registry> IMG=controller-runtime-example:tag
To delete the resources from kcp:
make uninstall
Undeploy the controller from kcp:
make undeploy
See CONTRIBUTING.md
This project aims to follow the Kubernetes Operator pattern
It uses Controllers which provides a reconcile function responsible for synchronizing resources until the desired state is reached.
- Install the required resources into kcp:
make install
- Run your controller (this will run in the foreground, so switch to a new terminal if you want to leave it running):
make run
NOTE: You can also run this in one step by running: make install run
If you are editing the API definitions, regenerate the manifests using:
make manifests apiresourceschemas
NOTE: Run make --help
for more information on all potential make
targets
More information can be found via the Kubebuilder Documentation
Copyright 2022.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.