Giter Club home page Giter Club logo

gardener-extension-shoot-flux's Introduction

Gardener Extension for Flux

reuse compliant

Project Gardener implements the automated management and operation of Kubernetes clusters as a service. Its main principle is to leverage Kubernetes concepts for all of its tasks.

This controller implements Gardener's extension contract for the shoot-flux extension. The latest release's ControllerRegistration resource that can be used to register this controller to Gardener can be found here.

Please find more information regarding the extensibility concepts and a detailed proposal here.

Table of Contents

What does this package provide?

The general idea of this controller is to install the fluxcd controllers together with a flux gitrepository resource and a flux kustomization resource into newly created shoot clusters. In consequence, your fresh shoot cluster will be reconciled to the state defined in the Git repository by the fluxcd controllers. Thus, this extension provides a general approach to install addons to shoot clusters.

Example use case

Let's say you have a CI-workflow which needs a kubernetes cluster with some basic components, such as cert-manager or minio. Thus, your CI-workflow creates a Shoot on which you perform all your actions. However, the process of creating the Shoot and installing the needed components takes for several minutes holding you back from effectively running your CI-pipeline. In this case, you can make use of this extension and pre-spawn Shoots, which are automatically equipped with fluxcd and reconciled to the state defined in a Git repository. Of course, there is a trade-off, as your pre-spawned shoots will consume some resources (either in terms of money, if running in a public cloud, or in terms of physical resources). However, in certain scenarios, this approach will dramatically improve the effectiveness of you CI-workflow.

How to...

Use it as a gardener operator

Of course, you need to apply the controller-registration resources to the garden cluster first. You can find the corresponding yaml-files in our releases. Moreover, you will need some configuration pointing to the git repository you want to use as a basis for flux. This configuration is provided on a per-project basis via a ConfigMap:

apiVersion: v1
kind: ConfigMap
metadata:
  name: flux-config
  namespace: YOUR-PROJECT-NAMESPACE
data:
  fluxVersion: v0.29.5 # optional, if not defined the latest release will be used
  repositoryUrl: ssh://[email protected]/THE-OWNER/THE-REPO
  repositoryBranch: main
  repositoryType: private

At the time writing this, the extension-controller will generate a new SSH-keypair for you, if the repositoryType is set to private. This keypair will be stored in the garden cluster as a Secret and you will need to make the public key available to you git SSH-server, so that flux can read from your repository. Note: On e.g. github.com, this can be achieved by adding a deploy key to your Git repository.

Next you can deploy a Shoot with the shoot-flux extension enabled:

apiVersion: core.gardener.cloud/v1beta1
kind: Shoot
metadata:
  name: bar
  namespace: garden-foo
spec:
  extensions:
  - type: shoot-flux
...

Then, your shoot cluster should be reconciled to the declarative definition in your Git repository.

Develop this extension locally

Prerequisites

  • A local installation of Go
  • A Gardener (could also be the local setup)

Running and Debugging the controller

  • Place the kubeconfig of the Seed cluster in PATH-TO-REPO-ROOT/dev/kubeconfig
  • Set ignoreResources=true and replicaCount=0 in PATH-TO-REPO-ROOT/charts/gardener-extension-shoot-flux/values.yaml
  • Generate the controller-registration.yaml by e.g.
./vendor/github.com/gardener/gardener/hack/generate-controller-registration.sh shoot-flux charts/gardener-extension-shoot-flux v0.0.1 example/controller-registration.yaml Extension:shoot-flux
  • Apply it to the garden cluster:
kubectl apply -f PATH-TO-REPO-ROOT/example/controller-registration.yaml
  • Run and debug the controller with dlv by:
dlv debug ./cmd/gardener-extension-shoot-flux -- --kubeconfig=dev/kubeconfig.yaml  --ignore-operation-annotation=true --leader-election=false --gardener-version="v1.44.4"
  • You can set breakpoints now, and instruct dlv to run the controller by entering "c" into the dlv commandline.
  • Lastly, deploy a ConfigMap pointing to a git repository and a Shoot with the shoot-flux extension enabled (as explained above).

General concepts and how it works internally

Generally, this extension was motivated by the idea of enabling Gardener operators to pre-configure Shoot clusters with addons. Obviously, a declarative approach to the configuration makes sense in this scenario. Consequently fluxcd was chosen as a more general configuration tool for Kubernetes clusters. From this basis, a Gardener operator can track the configuration of Shoot clusters in Git repositories and configure all Shoots in a project to use a configuration via a ConfigMap in the project namespace. This overall workflow is depicted in the block diagram below.

                 ┌─────────────────────────────────────────────────────────┐
                 │ Gardener operator                                       │
                 ├─────────────────────────────────────────────────────────┤
                 │ - A human being                                         │
                 │                                                         ├────────────┐
                 │                                                         │            │
                 │                                                         │            │
                 └────────┬────────────────────────────────────────────────┘            │
                          │                           ▲                                 │configures
                          │deploys                    │                                 │SSH-key
                          │Configmap                  │read SSH-key                     │
                          │                           │                                 │
                          ▼                           │                                 │
                 ┌────────────────────────────────────┴───────────────────┐             │
                 │ Garden cluster                                         │             │
                 ├────────────────────────┬─────────────────────────┬─────┤             │
                 │ Projetct 1             │ Project 2               │ ... │             ▼
                 ├────────────────────────┼─────────────────────────┼─────┤  ┌─────────────────────┐
                 │- Configmap containing  │- Configmap containing   │     │  │ Git repository      │
                 │  flux configuration    │  flux configuration     │     │  ├─────────────────────┤
                 │                        │                         │     │  │ - Configuration for │
            ┌───►│- ControllerRegistration│- ControllerRegistration │ ... │  │   shoot clusters    │
            │    │                        │                         │     │  └─────────────────────┘
            │    │- Shoot with extension  │- Shoot with extension   │     │             ▲
            │    │  enabled               │  enabled                │     │             │
            │    │                        │                         │     │             │
read config │    │                        │                         │     │             │
and generate│    └────────────────────────┴─────────────────────────┴─────┘             │reconcile
SSH-keys    │                                                                           │
            │    ┌────────────────────────┐     ┌────────────────────────┐              │
            │    │ Seed cluster           │     │ Shoot cluster          │              │
            │    ├────────────────────────┤     ├────────────────────────┤              │
            │    │- Controller watching   │     │                        │              │
            └────┼─ extension resource    │     │- Flux controllers  ────┼──────────────┘
                 │     │                  │     │                        │
                 │     │deploys           │     │- GitRepository resource│
                 │     │                  │     │                        │
                 │     ▼                  │     │- A main kustomization  │
                 │- Managed resources     │     │                        │
                 │  for flux controllers  │     │                        │
                 │  and flux config       │     │                        │
                 │                        │     │                        │
                 └────────────────────────┘     └────────────────────────┘

Wait! How does the controller in the Seed cluster communicate to the garden cluster? Actually, we are just using the Secret containing the gardenlet-kubeconfig which should be available, when the gardenlet is run inside the Seed cluster. Of course, this is not a rock solid solution, but it was an easy way to achieve the overall goal by simple means.

Last remarks

This extensions is still in a preliminary state and contains some hacks. However, the work and testing is still ongoing and the extension will be continuously improved. In general, you could consider the current state of the extension as kind of a minimal working example for Gardener extensions, as it is very low complex to this point.

gardener-extension-shoot-flux's People

Contributors

jensac avatar renovate[bot] avatar timebertt avatar lotharbach avatar nottheevilone avatar kumm-kai avatar maboehm avatar robinschneider avatar afritzler avatar j2l4e avatar dependabot[bot] avatar

Watchers

 avatar

Forkers

j2l4e afritzler

gardener-extension-shoot-flux's Issues

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Open

These updates have all been created already. Click a checkbox below to force a retry/rebase of any.

Detected dependencies

github-actions
.github/workflows/images.yml
  • actions/checkout v4
  • docker/login-action v3
  • actions/setup-go v5
.github/workflows/verify.yml
  • actions/checkout v4
  • actions/setup-go v5
gomod
go.mod
  • go 1.22.3
  • github.com/ahmetb/gen-crd-api-reference-docs v0.3.0
  • github.com/fluxcd/flux2/v2 v2.2.3
  • github.com/fluxcd/kustomize-controller/api v1.2.2
  • github.com/fluxcd/pkg/apis/meta v1.3.0
  • github.com/fluxcd/source-controller/api v1.2.5
  • github.com/gardener/gardener v1.92.2
  • github.com/go-logr/logr v1.4.1
  • github.com/ironcore-dev/vgopath v0.1.5
  • github.com/onsi/ginkgo/v2 v2.17.3
  • github.com/onsi/gomega v1.33.1
  • github.com/spf13/cobra v1.8.0
  • github.com/spf13/pflag v1.0.5
  • golang.org/x/tools v0.21.0
  • k8s.io/api v0.29.5
  • k8s.io/apiextensions-apiserver v0.29.5
  • k8s.io/apimachinery v0.29.5
  • k8s.io/client-go v0.29.5
  • k8s.io/code-generator v0.29.5
  • k8s.io/component-base v0.29.5
  • k8s.io/utils v0.0.0-20240502163921-fe8a2dddb1d0@fe8a2dddb1d0
  • sigs.k8s.io/controller-runtime v0.17.5
helm-values
charts/gardener-extension-shoot-flux/values.yaml
regex
example/shoot.yaml
  • github.com/fluxcd/flux2/v2 v2.2.3
pkg/apis/flux/v1alpha1/defaults.go
  • github.com/fluxcd/flux2/v2 v2.2.3
pkg/apis/flux/v1alpha1/types.go
  • github.com/fluxcd/flux2/v2 v2.2.3

  • Check this box to trigger a request for Renovate to run again on this repository

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.