timoni: Add connectivity test to module

Signed-off-by: Stefan Prodan <stefan.prodan@gmail.com>
This commit is contained in:
Stefan Prodan
2023-10-30 14:10:25 +02:00
parent bb2408d17d
commit 021c55fed9
7 changed files with 89 additions and 1 deletions

View File

@@ -71,6 +71,7 @@ timoni -n default delete podinfo
| `topologySpreadConstraints:` | `[...corev1.#TopologySpreadConstraint]` | `[]` | [Kubernetes pod topology spread constraints](https://kubernetes.io/docs/concepts/scheduling-eviction/topology-spread-constraints) |
| `podSecurityContext:` | `corev1.#PodSecurityContext` | `{}` | [Kubernetes pod security context](https://kubernetes.io/docs/tasks/configure-pod-container/security-context) |
| `securityContext:` | `corev1.#SecurityContext` | `{}` | [Kubernetes container security context](https://kubernetes.io/docs/tasks/configure-pod-container/security-context) |
| `test: enabled:` | `bool` | `false` | Run end-to-end tests at install and upgrades |
#### Recommended values

View File

@@ -6,7 +6,7 @@ import (
"text/tabwriter"
)
_resources: timoni.apply.app
_resources: timoni.apply.app + timoni.apply.test
// The build command generates the Kubernetes manifests and prints the multi-docs YAML to stdout.
// Example 'cue cmd -t debug -t name=podinfo -t namespace=test -t mv=1.0.0 -t kv=1.28.0 build'.

View File

@@ -11,6 +11,15 @@ values: {
digest: ""
}
test: {
enabled: true
image: {
repository: "ghcr.io/curl/curl-container/curl-multi"
tag: "master"
digest: ""
}
}
ui: backend: "http://backend.default.svc.cluster.local/echo"
metadata: {

View File

@@ -78,6 +78,12 @@ import (
enabled: *false | bool
redisURL?: string & =~"^tcp://.*$"
}
// Test Jobs (optional)
test: {
enabled: *false | bool
image!: timoniv1.#Image
}
}
// Instance takes the config values and outputs the Kubernetes objects.
@@ -101,4 +107,8 @@ import (
"\(config.metadata.name)-monitor": #ServiceMonitor & {_config: config}
}
}
tests: {
"test-svc": #TestJob & {_config: config}
}
}

View File

@@ -0,0 +1,58 @@
package templates
import (
"encoding/yaml"
"uuid"
corev1 "k8s.io/api/core/v1"
batchv1 "k8s.io/api/batch/v1"
timoniv1 "timoni.sh/core/v1alpha1"
)
#TestJob: batchv1.#Job & {
_config: #Config
apiVersion: "batch/v1"
kind: "Job"
metadata: name: "\(_config.metadata.name)-test"
metadata: namespace: _config.metadata.namespace
metadata: labels: _config.metadata.labels
metadata: annotations: timoniv1.Action.Force
spec: batchv1.#JobSpec & {
template: corev1.#PodTemplateSpec & {
metadata: labels: _config.metadata.labels
let _checksum = uuid.SHA1(uuid.ns.DNS, yaml.Marshal(_config))
metadata: annotations: "timoni.sh/checksum": "\(_checksum)"
spec: {
containers: [{
name: "curl"
image: _config.test.image.reference
imagePullPolicy: _config.imagePullPolicy
command: [
"curl",
"-v",
"-m",
"5",
"\(_config.metadata.name):\(_config.service.port)",
]
}]
restartPolicy: "Never"
if _config.podSecurityContext != _|_ {
securityContext: _config.podSecurityContext
}
if _config.topologySpreadConstraints != _|_ {
topologySpreadConstraints: _config.topologySpreadConstraints
}
if _config.affinity != _|_ {
affinity: _config.affinity
}
if _config.tolerations != _|_ {
tolerations: _config.tolerations
}
if _config.imagePullSecrets != _|_ {
imagePullSecrets: _config.imagePullSecrets
}
}
}
backoffLimit: 1
}
}

View File

@@ -46,4 +46,9 @@ timoni: {
// Pass Kubernetes resources outputted by the instance
// to Timoni's multi-step apply.
apply: app: [ for obj in instance.objects {obj}]
// Conditionally run tests after an install or upgrade.
if instance.config.test.enabled {
apply: test: [ for obj in instance.tests {obj}]
}
}

View File

@@ -12,4 +12,9 @@ values: {
tag: "6.5.2"
digest: ""
}
test: image: {
repository: "ghcr.io/curl/curl-container/curl-multi"
tag: "master"
digest: ""
}
}