kubestellar / kubeflex

A flexible and scalable platform for running Kubernetes control plane APIs.
Apache License 2.0
47 stars 13 forks source link

feature: add post-create hook for controlplane #114

Closed pdettori closed 11 months ago

pdettori commented 11 months ago

Feature Description

This feature cover the use case where a user wants to install custom resources, perform configurations or even runs pods on a control plane after the creation. An example use case is to create a vcluster-type control plane and then install the ocm cluster-manager on it. The post-create hook should be able to install specified Kubernetes templates, for example a job that runs a helm install.

Proposed Solution

Define a new cluster-scoped custom resource of kind PostCreateHook which would allow to specify a container spec and the type of workload (job or deployment).

Example:

apiVersion: tenancy.kflex.kubestellar.org/v1alpha1
kind: PostCreateHook
metadata:
  name: hello
spec:
   templates:
    - apiVersion: batch/v1
      kind: Job
      metadata:
        name: pi
      spec:
        template:
          spec:
            containers:
            - name: pi
              image: perl:5.34.0
              command: ["perl",  "-Mbignum=bpi", "-wle", "print bpi(2000)"]
            restartPolicy: Never
        backoffLimit: 4

Then, in the controlplane CR, we can specify a post-create hook

apiVersion: tenancy.kflex.kubestellar.org/v1alpha1
kind: ControlPlane
metadata:
  name: vc
spec:
  backend: shared
  type: vcluster
  postCreateHook: hello

The kflex CLI should be updated as well to include the option to pass the hook:

kflex create vc --type vcluster --postcreate-hook hello

The templates defined in PostCreateHook are applied in the namespace for the control plane to which the hook is associated. By default the objects defined in the template are applied to the hosting cluster. One special use case is applying a helm chart to the API server running in the control plane. This can be done using a job running the helm command with a kubeconfig mounted from the secret with the in-cluster config for the API server of the control plane.

Want to contribute?

Additional Context

No response