hashicorp / terraform-cloud-operator

Kubernetes Operator allows managing HCP Terraform resources via Kubernetes Custom Resources.
https://developer.hashicorp.com/terraform/cloud-docs
Mozilla Public License 2.0
114 stars 27 forks source link

🚀 Update Config Map and Secret get key ref methods #384

Closed arybolovlev closed 3 months ago

arybolovlev commented 3 months ago

Description

This PR replaces the per-controller reconciler methods getSecret and getConfigMap, which returned corresponding Kubernetes objects, with a more generic functions configMapKeyRef and secretKeyRef. These functions return only a requested key or an error if the key or object does not exist.

Tests

Usage Example

N/A.

References

N/A.

Community Note

arybolovlev commented 3 months ago

Looks good, technically. Left some optional error message suggestions, but feel free to ignore them.

One question though, as I didn't trace the calls to these functions back through the code: will this lead to more frequent calls to the API to fetch CM and secrets? In theory, for each new key value that's needed, it would make a new call, right?

We should be good here. The controller runtime client uses a cache to cache API responses. I have validated this with the API server metrics and it works well. :)