A Kubernetes Operator that manages the lifecycle of a NamespaceClass resource. Built using kubebuilder.
The NamespaceClass Operator is designed to automate the management of NamespaceClass resources in a Kubernetes
cluster. A NamespaceClass defines a set of resources and policies that can be applied to namespaces within the cluster.
When a Namespace is labeled with a specific NamespaceClass, the operator ensures that the resources and policies
defined in the NamespaceClass are applied to that namespace.
- Automatically creates and manages resources defined in a
NamespaceClassfor each namespace that uses it - Support for defining any resource type within a
NamespaceClass - Switching
NamespaceClassfor a namespace will automatically update the resources in that namespace - Updating a
NamespaceClasswill automatically update the resources in any namespace using that class
This project is in the early stages of development. Here's how you can get started using and developing locally.
- Go 1.20 or later
- Kubernetes cluster (minikube, kind, etc.)
kubectlkubebuilder
With your Kubernetes cluster running, you can run the operator locally using the following commands:
- Generate
WebhookConfiguration,ClusterRoleandCustomResourceDefinitionobjects
make manifests- Generate code containing
DeepCopy,DeepCopyInto, andDeepCopyObjectmethod implementations
make generate- Install CRDs into the K8s cluster specified in
~/.kube/config
make install- Run the controller from your host
make run- Apply a
NamespaceClassCRD to the cluster Example CRD:
apiVersion: stanton.sh/v1
kind: NamespaceClass
metadata:
labels:
app.kubernetes.io/name: namespace-class
name: namespaceclass-sample
spec:
resources:
- apiVersion: v1
kind: ConfigMap
metadata:
name: configmap-sample
namespace: default
- apiVersion: v1
kind: Secret
metadata:
name: secret-sample
- apiVersion: apps/v1
kind: Deployment
metadata:
name: deployment-sample
spec:
replicas: 1
selector:
matchLabels:
app: deployment-sample
template:
metadata:
labels:
app: deployment-sample
spec:
containers:
- name: nginx
image: nginx:latest
ports:
- containerPort: 80kubectl apply -f config/samples/nsclass-sample.yaml- Create a
Namespaceand label it with theNamespaceClass
apiVersion: v1
kind: Namespace
metadata:
name: sample
labels:
namespaceclass.stanton.sh/name: namespaceclass-samplekubectl apply -f config/samples/ns-sample.yaml- Verify that the resources defined in the
NamespaceClasshave been created in thesamplenamespace
kubectl get configmap,secret,deployment -n sample
NAME DATA AGE
configmap/configmap-sample 0 54s
configmap/kube-root-ca.crt 1 54s
NAME TYPE DATA AGE
secret/secret-sample Opaque 0 54s
NAME READY UP-TO-DATE AVAILABLE AGE
deployment.apps/deployment-sample 1/1 1 1 54s