Skip to content

Commit

Permalink
Merge pull request #315 from stefanprodan/timoni-tests
Browse files Browse the repository at this point in the history
timoni: Add connectivity test to module
  • Loading branch information
stefanprodan authored Oct 30, 2023
2 parents bb2408d + 0f526c3 commit 1ee349f
Show file tree
Hide file tree
Showing 8 changed files with 91 additions and 1 deletion.
2 changes: 2 additions & 0 deletions timoni/bundles/test.podinfo.cue
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ bundle: {
maxReplicas: 10
cpu: 90
}
test: enabled: true
}
}
frontend: {
Expand Down Expand Up @@ -60,6 +61,7 @@ bundle: {
"cert-manager.io/cluster-issuer": "self-signed"
}
}
test: enabled: true
}
}
}
Expand Down
1 change: 1 addition & 0 deletions timoni/podinfo/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion timoni/podinfo/debug_tool.cue
Original file line number Diff line number Diff line change
Expand Up @@ -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'.
Expand Down
9 changes: 9 additions & 0 deletions timoni/podinfo/debug_values.cue
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
10 changes: 10 additions & 0 deletions timoni/podinfo/templates/config.cue
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -101,4 +107,8 @@ import (
"\(config.metadata.name)-monitor": #ServiceMonitor & {_config: config}
}
}

tests: {
"test-svc": #TestJob & {_config: config}
}
}
58 changes: 58 additions & 0 deletions timoni/podinfo/templates/job.cue
Original file line number Diff line number Diff line change
@@ -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
}
}
5 changes: 5 additions & 0 deletions timoni/podinfo/timoni.cue
Original file line number Diff line number Diff line change
Expand Up @@ -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}]
}
}
5 changes: 5 additions & 0 deletions timoni/podinfo/values.cue
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,9 @@ values: {
tag: "6.5.2"
digest: ""
}
test: image: {
repository: "ghcr.io/curl/curl-container/curl-multi"
tag: "master"
digest: ""
}
}

0 comments on commit 1ee349f

Please sign in to comment.