Skip to content

Commit

Permalink
Merge pull request #32 from stefanprodan/example-caching
Browse files Browse the repository at this point in the history
Add auth and caching to examples
  • Loading branch information
stefanprodan authored Mar 22, 2023
2 parents 7bd7f61 + 69a614f commit c161a49
Show file tree
Hide file tree
Showing 11 changed files with 54 additions and 8 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ to offer a better experience of creating, packaging and delivering apps to Kuber
> **Warning**
>
> Note that Timoni in under active development and is still in its infancy.
> Its APIs and command-line interface may change in a backwards incompatible manner.
> The APIs and command-line interface may change in a backwards incompatible manner.
## Get started

Expand Down Expand Up @@ -50,7 +50,7 @@ Module structure:
└── values.cue # Timoni values placeholder
```

A module example can be found at [examples/podinfo](examples/podinfo).
Module examples can be found at [examples/podinfo](examples/podinfo) and [examples/redis](examples/redis).

Commands for working with local modules:

Expand Down
2 changes: 1 addition & 1 deletion docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ to offer a better experience of creating, packaging and delivering apps to Kuber
!!! warning "Development phase"

Timoni in under active development and is still in its infancy.
Its APIs and interfaces may change in a backwards incompatible manner.
The APIs and interfaces may change in a backwards incompatible manner.

## Concepts

Expand Down
4 changes: 4 additions & 0 deletions examples/podinfo-values/caching-values.cue
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
values: caching: {
enabled: true
redisURL: "tcp://:redis@redis:6379"
}
7 changes: 7 additions & 0 deletions examples/podinfo/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,3 +120,10 @@ values: {
|-------------------------|----------|---------|-------------------------------------------------------------------------------|
| `monitoring: enabled:` | `bool` | `false` | Enable [Prometheus ServiceMonitor](https://prometheus-operator.dev/) creation |
| `monitoring: interval:` | `string` | `15s` | Prometheus scrape interval |

### Cashing values

| Key | Type | Default | Description |
|----------------------|----------|---------|---------------------------------------------------------|
| `caching: enabled:` | `bool` | `false` | Enable Redis caching |
| `caching: redisURL:` | `string` | `""` | Redis URL in the format `tcp://:[password]@host[:port]` |
15 changes: 13 additions & 2 deletions examples/podinfo/templates/config.cue
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package templates

import (
"strings"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
corev1 "k8s.io/api/core/v1"
)
Expand All @@ -9,12 +11,15 @@ import (
#Config: {
// Metadata (common to all resources)
metadata: metav1.#ObjectMeta
metadata: name: *"podinfo" | string
metadata: namespace: *"default" | string
metadata: name: *"podinfo" | string & =~"^(([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9])?$" & strings.MaxRunes(63)
metadata: namespace: *"default" | string & strings.MaxRunes(63)
metadata: labels: *selectorLabels | {[ string]: string}
metadata: labels: "app.kubernetes.io/version": image.tag
metadata: annotations?: {[ string]: string}

// Redis
redis?: string

// Deployment
replicas: *1 | int & >0
selectorLabels: *{"app.kubernetes.io/name": metadata.name} | {[ string]: string}
Expand Down Expand Up @@ -62,6 +67,12 @@ import (
enabled: *false | bool
interval: *"15s" | string
}

// Caching (optional)
caching: {
enabled: *false | bool
redisURL?: string & =~"^tcp://.*$"
}
}

// Instance takes the config values and outputs the Kubernetes objects.
Expand Down
7 changes: 7 additions & 0 deletions examples/podinfo/templates/deployment.cue
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,13 @@ import (
if _config.securityContext != _|_ {
securityContext: _config.securityContext
}
command: [
"./podinfo",
"--level=info",
if _config.caching.enabled {
"--cache-server=\(_config.caching.redisURL)"
},
]
},
]
if _config.podSecurityContext != _|_ {
Expand Down
1 change: 1 addition & 0 deletions examples/redis/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ timoni -n default delete redis
| `persistence: enabled:` | `bool` | `true` | Enable persistent storage for the Redis master node |
| `persistence: storageClass:` | `string` | `standard` | The [PersistentVolumeClaim](https://kubernetes.io/docs/concepts/storage/persistent-volumes/) storage class name |
| `persistence: size:` | `string` | `8Gi` | The persistent volume size |
| `password` | `string` | `""` | When set, it enables auth for both the master and replicas with the specified password |

### General values

Expand Down
7 changes: 5 additions & 2 deletions examples/redis/templates/config.cue
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package templates

import (
"strings"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
corev1 "k8s.io/api/core/v1"
)
Expand All @@ -15,11 +17,12 @@ import (
storageClass: *"standard" | string
size: *"8Gi" | string
}
password?: string & =~"^(([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9])?$"

// Metadata (common to all resources)
metadata: metav1.#ObjectMeta
metadata: name: *"redis" | string
metadata: namespace: *"default" | string
metadata: name: *"redis" | string & =~"^(([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9])?$" & strings.MaxRunes(63)
metadata: namespace: *"default" | string & strings.MaxRunes(63)
metadata: labels: {
"app.kubernetes.io/version": image.tag
"app.kubernetes.io/part-of": metadata.name
Expand Down
8 changes: 7 additions & 1 deletion examples/redis/templates/master.deployment.cue
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,13 @@ import (
containerPort: 6379
protocol: "TCP"
}]
command: ["redis-server", "/redis-master/redis.conf"]
command: [
"redis-server",
"/redis-master/redis.conf",
if _config.password != _|_ {
"--requirepass \(_config.password)"
},
]
livenessProbe: {
tcpSocket: port: "redis"
initialDelaySeconds: 2
Expand Down
6 changes: 6 additions & 0 deletions examples/redis/templates/replica.deployment.cue
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ import (
"\(_config.service.port)",
"--include",
"/redis-replica/redis.conf",
if _config.password != _|_ {
"--masterauth \(_config.password)"
},
if _config.password != _|_ {
"--requirepass \(_config.password)"
},
]
livenessProbe: {
tcpSocket: port: "redis"
Expand Down
1 change: 1 addition & 0 deletions examples/redis/test_values.cue
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ package main
values: {
resources: requests: cpu: "100m"
resources: limits: cpu: "1000m"
password: "my-redis_password123"
}

0 comments on commit c161a49

Please sign in to comment.