From 9a56cc120f71de397d9cadb1f3b2fe439d3dfa77 Mon Sep 17 00:00:00 2001 From: Stefan Prodan Date: Thu, 21 Dec 2023 22:31:44 +0200 Subject: [PATCH] Add `#ObjectReference` to Timoni's CUE schemas Signed-off-by: Stefan Prodan --- examples/minimal/README.md | 2 +- .../pkg/timoni.sh/core/v1alpha1/object.cue | 21 +++++++++++++++++++ examples/minimal/templates/config.cue | 2 +- schemas/README.md | 2 ++ schemas/timoni.sh/core/v1alpha1/object.cue | 21 +++++++++++++++++++ 5 files changed, 46 insertions(+), 2 deletions(-) create mode 100644 examples/minimal/cue.mod/pkg/timoni.sh/core/v1alpha1/object.cue create mode 100644 schemas/timoni.sh/core/v1alpha1/object.cue diff --git a/examples/minimal/README.md b/examples/minimal/README.md index 2d608e82..980a5bbf 100644 --- a/examples/minimal/README.md +++ b/examples/minimal/README.md @@ -52,7 +52,7 @@ timoni -n default delete minimal | `metadata: labels:` | `{[ string]: string}` | `{}` | Common labels for all resources | | `metadata: annotations:` | `{[ string]: string}` | `{}` | Common annotations for all resources | | `podAnnotations:` | `{[ string]: string}` | `{}` | Annotations applied to pods | -| `imagePullSecrets:` | `[...corev1.LocalObjectReference]` | `[]` | [Kubernetes image pull secrets](https://kubernetes.io/docs/concepts/containers/images/#specifying-imagepullsecrets-on-a-pod) | +| `imagePullSecrets:` | `[...timoniv1.ObjectReference]` | `[]` | [Kubernetes image pull secrets](https://kubernetes.io/docs/concepts/containers/images/#specifying-imagepullsecrets-on-a-pod) | | `tolerations:` | `[ ...corev1.#Toleration]` | `[]` | [Kubernetes toleration](https://kubernetes.io/docs/concepts/scheduling-eviction/taint-and-toleration) | | `affinity:` | `corev1.#Affinity` | `{}` | [Kubernetes affinity and anti-affinity](https://kubernetes.io/docs/concepts/scheduling-eviction/assign-pod-node/#affinity-and-anti-affinity) | | `resources:` | `timoniv1.#ResourceRequirements` | `{}` | [Kubernetes resource requests and limits](https://kubernetes.io/docs/concepts/configuration/manage-resources-containers) | diff --git a/examples/minimal/cue.mod/pkg/timoni.sh/core/v1alpha1/object.cue b/examples/minimal/cue.mod/pkg/timoni.sh/core/v1alpha1/object.cue new file mode 100644 index 00000000..1dcdb699 --- /dev/null +++ b/examples/minimal/cue.mod/pkg/timoni.sh/core/v1alpha1/object.cue @@ -0,0 +1,21 @@ +// Copyright 2023 Stefan Prodan +// SPDX-License-Identifier: Apache-2.0 + +package v1alpha1 + +import "strings" + +// ObjectReference is a reference to a Kubernetes object. +#ObjectReference: { + // Name of the referent. + name!: string & strings.MaxRunes(256) + + // Namespace of the referent. + namespace?: string & strings.MaxRunes(256) + + // API version of the referent. + apiVersion?: string & strings.MaxRunes(256) + + // Kind of the referent. + kind?: string & strings.MaxRunes(256) +} diff --git a/examples/minimal/templates/config.cue b/examples/minimal/templates/config.cue index eae88453..992bfa8a 100644 --- a/examples/minimal/templates/config.cue +++ b/examples/minimal/templates/config.cue @@ -77,7 +77,7 @@ import ( // Pod optional settings. podAnnotations?: {[string]: string} podSecurityContext?: corev1.#PodSecurityContext - imagePullSecrets?: [...corev1.LocalObjectReference] + imagePullSecrets?: [...timoniv1.ObjectReference] tolerations?: [...corev1.#Toleration] affinity?: corev1.#Affinity topologySpreadConstraints?: [...corev1.#TopologySpreadConstraint] diff --git a/schemas/README.md b/schemas/README.md index fdc7244c..c3fd3102 100644 --- a/schemas/README.md +++ b/schemas/README.md @@ -21,6 +21,8 @@ The Timoni's CUE schemas are included in the modules generated with `timoni mod with automatic generation of `app.kubernetes.io/component` label. - `#Selector` - Schema for generating Kubernetes label selectors with automatic generation of `app.kubernetes.io/name` label. +- `#ObjectReference` - Schema for generating Kubernetes object references + based on `apiVersion`, `kind`, `name` and `namespace`. ### Container Image diff --git a/schemas/timoni.sh/core/v1alpha1/object.cue b/schemas/timoni.sh/core/v1alpha1/object.cue new file mode 100644 index 00000000..1dcdb699 --- /dev/null +++ b/schemas/timoni.sh/core/v1alpha1/object.cue @@ -0,0 +1,21 @@ +// Copyright 2023 Stefan Prodan +// SPDX-License-Identifier: Apache-2.0 + +package v1alpha1 + +import "strings" + +// ObjectReference is a reference to a Kubernetes object. +#ObjectReference: { + // Name of the referent. + name!: string & strings.MaxRunes(256) + + // Namespace of the referent. + namespace?: string & strings.MaxRunes(256) + + // API version of the referent. + apiVersion?: string & strings.MaxRunes(256) + + // Kind of the referent. + kind?: string & strings.MaxRunes(256) +}