vmware-archive / operator-builder

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

feat: metadata.name field in child resource #294

Closed scottd018 closed 2 years ago

scottd018 commented 2 years ago

When defining a child resource with operator-builder, it is often times desirable to take in the input of a parent resource field. The metadata.name field is the one in particular that is NOT accessible to child resources, because it is not defined with a marker, but would be real helpful to be able to use.

Consider the following resource:

---
apiVersion: container.cnrm.cloud.google.com/v1beta1
kind: ContainerCluster
metadata:
  # +operator-builder:field:name=clusterName,type=string,description=`
  # Name of the GKE cluster to create.`
  name: cluster

In the above example, a spec of the following would be used:

apiVersion: v1alpha1
kind: MyKind
metadata:
  name: my-cluster
spec:
  clusterName: my-cluster

The clusterName field must be defined in order for the input to be used, but it may make sense, in this instance to simply use the metadata.name field of the parent resource.

Maybe a marker like this would make sense:

---
apiVersion: container.cnrm.cloud.google.com/v1beta1
kind: ContainerCluster
metadata:
  # +operator-builder:field:fromMetadataName,description=`
  # Name of the GKE cluster to create.`
  name: cluster
scottd018 commented 2 years ago

Closing in favor of https://github.com/vmware-tanzu-labs/operator-builder/issues/248.