stefanprodan / timoni

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

[Proposal] Module should allow to export some values #333

Open yyvess opened 5 months ago

yyvess commented 5 months ago

A module can declare a list of exported value.

On timoni.cue we should able to declare exported value like

// Define how Timoni should build, validate and
// apply the Kubernetes resources.
timoni: {
    apiVersion: "v1alpha1"

    export: [ {url: "redis://\(instance.config.metadata.name).\(instance.config.metadata.namespace).svc.cluster.local:\(instance.config.port)"}]

Then we should able to re-use these variables on bundle file as =>

bundle: {
    apiVersion: "v1alpha1"
    name:       "podinfo"
    instances: {
        redis: {
            module: {
                url:     "oci://ghcr.io/stefanprodan/modules/redis"
                version: "7.2.3"
            }
            namespace: "podinfo"
            values: maxmemory: 256
        }
        podinfo: {
            module: url:     "oci://ghcr.io/stefanprodan/modules/podinfo"
            module: version: "6.5.4"
            namespace: "podinfo"
            values: caching: {
                enabled:  true
                redisURL: redis.url
            }
        }
    }
}
jmgilman commented 5 months ago

This is a nice alternative to the bundle runtime, especially when you don't actually need runtime data in many cases. If my module produces one or more Kubernetes secrets, for example, being able to export their names for other instances to use is helpful.

Given that the CLI is mostly just transpiling a given CUE output into YAML (that happens to produce valid Kubernetes manifests), it's plausible you could add another reserved output (i.e., export as shown above) that is ingested and made available when the bundle is being processed.

I would propose the outputs appear in their own namespace, like: redis.outputs.url. Otherwise, you'll have collisions (i.e., what happens when an output is named namespace).

salotz commented 3 months ago

+1 for this. Same use case with the secrets/configs.

Although I'll ask if it is possible to just fully introspect/unify on any value within Timoni module?

I think its still useful to have a declared and expected interface like outputs but it would probably be also useful to have read access to everything. I.e. only use the values for unification of the module, but then be able to view the already concretized values from bundles.