✨ Adding ADR - Reading yaml and applying objects to Kubernetes using Golang
Created by: batistein
Overview: The document explores methods to read from a yaml file and apply Kubernetes objects to the API. It deliberates on whether to adopt a generic approach for arbitrary CRDs or a specific approach for known CRDs, with the former being preferred.
Background: For cluster stacks, the need is to apply Helm charts without knowing a priori the Kubernetes objects contained. The operator in the system must read yaml configurations and apply these objects.
Reading from yaml files:
- Unstructured Approach: Utilizes unstructured.Unstructured from Kubernetes' client-go library. It offers flexibility, version agnosticism, and generic handling.
- Structured Approach: Involves predefined Go structs for Kubernetes resources. This approach offers type safety, auto-completion, and clearer code.
Schemes in Kubernetes:
- Unstructured.UnstructuredJSONScheme: Provides generality without prior knowledge of specific API types. It simplifies initialization and allows dynamic data manipulation.
- Specific Schemes for CRDs: Offers type safety, clarity, rich features, and better performance by working with specific Go types.
Applying Objects to Kubernetes:
- Static Client: Useful for well-defined resources and offers type safety, an intuitive API, and autocompletion. However, it's less flexible and more dependent on specific libraries.
- Dynamic Client: Ideal for Custom Resources or CRDs, providing flexibility, version independence, and reduced dependencies. It might lack type safety and requires more verbose interactions.
This ADR underscores the importance of adopting a flexible, unstructured approach when handling dynamic Kubernetes resources, especially when the exact resources are unknown beforehand.