stefanprodan / timoni

Timoni is a package manager for Kubernetes, powered by CUE and inspired by Helm.
https://timoni.sh
Apache License 2.0
1.54k stars 68 forks source link

Add `#MatchLabelsComponent` generator to Timoni's CUE schemas #271

Closed Nalum closed 10 months ago

Nalum commented 10 months ago

This PR adds a generator for Kubernetes object selectors that will inject the app.kubernetes.io/component label to the selector. The example below makes use of the #MetaComponent introduce in #270.

Example:

#Deployment: appsv1.#Deployment & {
        _config:    #Config
        _component: "test"

        apiVersion: "apps/v1"
        kind:       "Deployment"

        _metadata: timoniv1.#MetaComponent & {
                #Meta:      _config.metadata
                #Component: _component
        }

        metadata: _metadata

        spec: appsv1.#DeploymentSpec & {
                replicas: _config.replicaCount
                selector: timoniv1.#MatchLabelsComponent & {
                        #SelectorLabels: _config.selector.labels
                        #Component:      _component
                }

                template: {
                        metadata: labels: _metadata.labels

                        if _metadata.annotations != _|_ {
                                metadata: annotations: _metadata.annotations
                        }
                }
        }
}
stefanprodan commented 10 months ago

@Nalum please see https://github.com/stefanprodan/timoni/pull/270 that exposes the selector directly from Metadata without the need for an extra helper. Also in your example above, you set the template labels to the metadata.labels, but these should be set to the selector value.

Nalum commented 10 months ago

Happy to close this in favor of the changes you've setup in #270.