> ## Documentation Index
> Fetch the complete documentation index at: https://timoni.sh/llms.txt
> Use this file to discover all available pages before exploring further.

# Kubernetes Version Constraints

> Adapt module output to the Kubernetes version of the target cluster.

At apply-time, Timoni reads the Kubernetes version from the live cluster and sets the version
string as the value of the `kubeVersion` field in the module's `#Config` definition.

With the `timoniv1.#SemVer` helper, you can parse the Kubernetes version string to extract the
major and minor version numbers.

```cue theme={"system"}
#Config: {
	kubeVersion!: string
	clusterVersion: timoniv1.#SemVer & {
		#Version: kubeVersion
		#Minimum: "0.0.0"
	}
}

```

## Enforcing a minimum supported version

To enforce a minimum supported version for your module, set a constraint for the minor
version e.g. `#Minimum: "1.20.0"`.

To test the constraint, you can use the `TIMONI_KUBE_VERSION` env var
with `timoni mod vet` and `timoni build`.

```console theme={"system"}
$ TIMONI_KUBE_VERSION=1.19.0 timoni mod vet
validation failed: clusterVersion.minor: invalid value 19 (out of bound >=20)
```

## Conditionally enabling features based on cluster version

You can use the `clusterVersion.minor` value to conditionally apply certain Kubernetes resources
based on the cluster version.

For example, the `FlowSchema` v1 API was introduced in Kubernetes 1.29. To apply this resource
only on clusters running Kubernetes 1.19 or newer,
you can use the following condition in your module's `#Instance` definition:

```cue theme={"system"}
#Instance: {
	config: #Config

	if config.clusterVersion.minor >= 29 {
		objects: flowSchema: #FlowSchema & {#config: config}
	}
}

```
