Skip to content

Commit

Permalink
Merge pull request #51 from stefanprodan/env-options
Browse files Browse the repository at this point in the history
Allow configuring the env of controller containers
  • Loading branch information
stefanprodan committed Nov 22, 2023
2 parents ec1484c + 30cc7a2 commit aedf966
Show file tree
Hide file tree
Showing 9 changed files with 47 additions and 20 deletions.
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,17 @@ bundle: {
}
```

For clusters without `kube-proxy`, you'll have to set following env vars:

```cue
values: {
env: {
"KUBERNETES_SERVICE_HOST": "<host>"
"KUBERNETES_SERVICE_PORT": "<port>"
}
}
```

Apply the bundle with:

```shell
Expand Down
5 changes: 3 additions & 2 deletions modules/flux-aio/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,9 @@ flux -n flux-system uninstall
| `persistence: size:` | `string` | `8Gi` | The persistent volume size |
| `tmpfs: enabled:` | `bool` | `false` | Enable RAM-backed filesystem for the Flux [emptyDir volume](https://kubernetes.io/docs/concepts/storage/volumes/#emptydir) to speed up the git pull and kustomize build operations |
| `tmpfs: sizeLimit:` | `string` | `null` | The tmpfs memory limit e.g. `500Mi` or `1Gi` |
| `proxy: http:` | `string` | `""` | HTTP Proxy URL |
| `proxy: https:` | `string` | `""` | HTTPS Proxy URL |
| `proxy: http:` | `string` | `null` | HTTP Proxy URL |
| `proxy: https:` | `string` | `null` | HTTPS Proxy URL |
| `env:` | `[string]: string` | `null` | Environment key values pairs for setting the `env` on all controller containers |
| `logLevel:` | `string` | `info` | Flux log level can be `debug`, `info`, `error` |
| `resources:` | `corev1.#ResourceRequirements` | `limits: memory: "1Gi"` | [Kubernetes resource requests and limits](https://kubernetes.io/docs/concepts/configuration/manage-resources-containers) common to all containers, can be overridden by controller basis |
| `tolerations:` | `[ ...corev1.#Toleration]` | `[{operator: "Exists"}]` | [Kubernetes toleration](https://kubernetes.io/docs/concepts/scheduling-eviction/taint-and-toleration) |
Expand Down
5 changes: 5 additions & 0 deletions modules/flux-aio/debug_values.cue
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,9 @@ values: {
sourceServer: true
}
persistence: enabled: true
proxy: http: "http://my.proxy"
env: {
"TEST_KEY1": "VAL1"
"TEST_KEY2": "VAL2"
}
}
13 changes: 8 additions & 5 deletions modules/flux-aio/templates/config.cue
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ import (
no: *".cluster.local.,.cluster.local,.svc" | string
}

env?: [string]: string

securityProfile: "restricted" | "privileged"

logLevel: *"info" | string
Expand Down Expand Up @@ -133,18 +135,19 @@ import (

// Instance takes the config values and outputs the Kubernetes objects.
#Instance: {
config: #Config
config: #Config
containerEnv: #ContainerEnv & {_config: config}

containers: [
#SourceController & {_config: config},
#SourceController & {_config: config, _env: containerEnv},
if config.controllers.kustomize.enabled {
#KustomizeController & {_config: config}
#KustomizeController & {_config: config, _env: containerEnv}
},
if config.controllers.helm.enabled {
#HelmController & {_config: config}
#HelmController & {_config: config, _env: containerEnv}
},
if config.controllers.notification.enabled {
#NotificationController & {_config: config}
#NotificationController & {_config: config, _env: containerEnv}
},
]

Expand Down
9 changes: 8 additions & 1 deletion modules/flux-aio/templates/env.cue
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package templates

#ContainerEnv: {
_config: #Config
env: [
defaultEnv: [
{
name: "SOURCE_CONTROLLER_LOCALHOST"
value: "localhost:9790"
Expand Down Expand Up @@ -30,4 +30,11 @@ package templates
value: _config.proxy.http
}},
]

extraEnv: [...]
if _config.env != _|_ {
extraEnv: [ for k , v in _config.env {name: k, value: v}]
}

env: defaultEnv + extraEnv
}
6 changes: 3 additions & 3 deletions modules/flux-aio/templates/helm-controller.cue
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ import (
)

#HelmController: corev1.#Container & {
_config: #Config
_containerEnv: #ContainerEnv & {_config: _config}
_config: #Config
_env: #ContainerEnv

name: "helm-controller"
image: _config.controllers.helm.image.reference
imagePullPolicy: "IfNotPresent"
securityContext: _config.securityContext
env: _containerEnv.env
env: _env.env
ports: [{
containerPort: 9795
name: "http-prom-hc"
Expand Down
6 changes: 3 additions & 3 deletions modules/flux-aio/templates/kustomize-controller.cue
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ import (
)

#KustomizeController: corev1.#Container & {
_config: #Config
_containerEnv: #ContainerEnv & {_config: _config}
_config: #Config
_env: #ContainerEnv

name: "kustomize-controller"
image: _config.controllers.kustomize.image.reference
imagePullPolicy: "IfNotPresent"
securityContext: _config.securityContext
env: _containerEnv.env
env: _env.env
ports: [{
containerPort: 9793
name: "http-prom-kc"
Expand Down
6 changes: 3 additions & 3 deletions modules/flux-aio/templates/notification-controller.cue
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ import (
)

#NotificationController: corev1.#Container & {
_config: #Config
_containerEnv: #ContainerEnv & {_config: _config}
_config: #Config
_env: #ContainerEnv

name: "notification-controller"
image: _config.controllers.notification.image.reference
imagePullPolicy: "IfNotPresent"
securityContext: _config.securityContext
env: _containerEnv.env
env: _env.env
ports: [{
containerPort: 9690
name: "http-nc"
Expand Down
6 changes: 3 additions & 3 deletions modules/flux-aio/templates/source-controller.cue
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ import (
)

#SourceController: corev1.#Container & {
_config: #Config
_containerEnv: #ContainerEnv & {_config: _config}
_config: #Config
_env: #ContainerEnv

name: "source-controller"
image: _config.controllers.source.image.reference
imagePullPolicy: "IfNotPresent"
securityContext: _config.securityContext
env: _containerEnv.env
env: _env.env

ports: [{
containerPort: 9790
Expand Down

0 comments on commit aedf966

Please sign in to comment.