Reputation: 570
I want to refer a property of an object created by a CRD.
Here is my example. I create a Cloud SQL instance using the CRD from https://github.com/GoogleCloudPlatform/k8s-config-connector.
This generates an instance with an IP. I want to reference the IP address in another resource.
Is there something similar to the downstream API that will allow me to do this?
If I can't do it Natively can I do it with third party templating tools like Helm, Helmfile or Kustomize?
Upvotes: 0
Views: 437
Reputation: 54251
Nothing in particular, the way we do it is the controller exposes info like the IP or hostname on the Status sub-struct of the subordinate object, and then copy that into the Status of the root object, and then we read from that and inject it into a config file.
https://github.com/Ridecell/ridecell-operator/blob/39344f4318ff3bcb68ce32dd4319b655a60277da/pkg/controller/summon/components/postgres.go#L58-L61 is an example of the copy-over but it's in our framework so probably not super helpful directly.
Another option we use in other places is making an init container that reads from the CRD status and writes out (or transforms) config files. An example of that is https://github.com/Ridecell/ridecell-operator/blob/39344f4318ff3bcb68ce32dd4319b655a60277da/cmd/initcontainer/main.go#L181-L203
Upvotes: 1