Git Product home page Git Product logo

controller-runtime-example's Introduction

controller-runtime-example

An example project that is multi-cluster aware and works with kcp

Description

This repository contains an example project that works with APIExports and multiple kcp workspaces. It demonstrates two reconcilers:

  1. ConfigMap

    1. Get a ConfigMap for the key from the queue, from the correct logical cluster
    2. If the ConfigMap has labels["name"], set labels["response"] = "hello-$name" and save the changes
    3. List all ConfigMaps in the logical cluster and log each one's namespace and name
    4. If the ConfigMap from step 1 has data["namespace"] set, create a namespace whose name is the data value.
    5. 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.
  2. Widget

    1. Show how to list all Widget instances across all logical clusters
    2. Get a Widget for the key from the queue, from the correct logical cluster
    3. List all Widgets in the same logical cluster
    4. Count the number of Widgets (list length)
    5. Make sure .status.total matches the current count (via a patch)

Getting Started

Running on kcp

  1. Build and push your image to the location specified by IMG:
make docker-build docker-push IMG=<some-registry>/controller-runtime-example:tag
  1. Deploy the controller to kcp with the image specified by IMG:
make deploy IMG=<some-registry>/controller-runtime-example:tag

Uninstall resources

To delete the resources from kcp:

make uninstall

Undeploy controller

Undeploy the controller from kcp:

make undeploy

Contributing

See CONTRIBUTING.md

How it works

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.

Test It Out

  1. Install the required resources into kcp:
make install
  1. 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

Modifying the API definitions

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

License

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.

controller-runtime-example's People

Contributors

ncdc avatar fabianvf avatar stevekuznetsov avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.