vmware-archive / operator-builder

A Kubebuilder plugin to accelerate the development of Kubernetes operators
MIT License
41 stars 6 forks source link

Use parent resource name as a value in a child resource #248

Open lander2k2 opened 2 years ago

lander2k2 commented 2 years ago

We don't currently have a way to do this. Consider this custom resource that is the parent:

apiVersion: v1alpha1
kind: WebApp
metadata:
  name: intance-x
spec:
  env: dev

Suppose we want to deploy n number of these webapps to a single cluster - each into their own namespace. Suppose we shove this resource into operator-builder...

apiVersion: v1
kind: Namespace
metadata:
  name: webapp-placeholder  # +operator-builder:field:name=parent.metadata.name,type=string,replace="placeholder"

So, given the WebApp resource above, this would produce a namespace with name webapp-instance-x.

And if a WebApp with name instance-y was created the result would be a namespace called webapp-instance-y.