Skip to content

Commit 99edfeb

Browse files
feat: Helm configuration (#304)
Signed-off-by: James Milligan <[email protected]> Signed-off-by: James Milligan <[email protected]> Co-authored-by: Skye Gill <[email protected]>
1 parent 75bdd8b commit 99edfeb

File tree

18 files changed

+399
-114
lines changed

18 files changed

+399
-114
lines changed

.github/workflows/pr-checks.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ jobs:
7272
steps:
7373
- name: Checkout
7474
uses: actions/checkout@v3
75+
- name: Update flagd tag
76+
run: make update-flagd
7577
- name: Set up QEMU
7678
uses: docker/setup-qemu-action@master
7779
with:

apis/core/v1alpha1/flagsourceconfiguration_types.go

Lines changed: 70 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -19,23 +19,30 @@ package v1alpha1
1919
import (
2020
"fmt"
2121
"os"
22+
"strconv"
23+
"strings"
2224

2325
corev1 "k8s.io/api/core/v1"
2426
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2527
)
2628

2729
const (
28-
FlagdMetricPortEnvVar string = "FLAGD_METRICS_PORT"
29-
FlagdPortEnvVar string = "FLAGD_PORT"
30-
FlagdSocketPathEnvVar string = "FLAGD_SOCKET_PATH"
31-
FlagdEvaluatorEnvVar string = "FLAGD_EVALUATOR"
32-
flagDVersionEnvVar string = "FLAGD_VERSION"
33-
defaultMetricPort int32 = 8014
34-
defaultPort int32 = 8013
35-
defaultSocketPath string = ""
36-
defaultEvaluator string = "json"
37-
defaultImage string = "ghcr.io/open-feature/flagd"
38-
defaultTag string = "main"
30+
SidecarEnvVarPrefix string = "SIDECAR_ENV_VAR_PREFIX"
31+
SidecarMetricPortEnvVar string = "METRICS_PORT"
32+
SidecarPortEnvVar string = "PORT"
33+
SidecarSocketPathEnvVar string = "SOCKET_PATH"
34+
SidecarEvaluatorEnvVar string = "EVALUATOR"
35+
SidecarImageEnvVar string = "IMAGE"
36+
SidecarVersionEnvVar string = "TAG"
37+
SidecarProviderArgsEnvVar string = "PROVIDER_ARGS"
38+
defaultSidecarEnvVarPrefix string = "FLAGD"
39+
InputConfigurationEnvVarPrefix string = "SIDECAR"
40+
defaultMetricPort int32 = 8014
41+
defaultPort int32 = 8013
42+
defaultSocketPath string = ""
43+
defaultEvaluator string = "json"
44+
defaultImage string = "ghcr.io/open-feature/flagd"
45+
defaultTag string = "v0.3.1"
3946
)
4047

4148
// EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN!
@@ -66,29 +73,63 @@ type FlagSourceConfigurationSpec struct {
6673
// +optional
6774
Evaluator string `json:"evaluator"`
6875

69-
// Image allows for the flagd image to be overridden, defaults to 'ghcr.io/open-feature/flagd'
76+
// Image allows for the sidecar image to be overridden, defaults to 'ghcr.io/open-feature/flagd'
7077
// +optional
7178
Image string `json:"image"`
7279

73-
// Tag to be appended to the flagd image, defaults to 'main'
80+
// Tag to be appended to the sidecar image, defaults to 'main'
7481
// +optional
7582
Tag string `json:"tag"`
7683
}
7784

78-
func NewFlagSourceConfigurationSpec() *FlagSourceConfigurationSpec {
79-
var tag = defaultTag
80-
if flagDVersion := os.Getenv(flagDVersionEnvVar); flagDVersion != "" {
81-
tag = flagDVersion
82-
}
83-
return &FlagSourceConfigurationSpec{
85+
func NewFlagSourceConfigurationSpec() (*FlagSourceConfigurationSpec, error) {
86+
fsc := &FlagSourceConfigurationSpec{
8487
MetricsPort: defaultMetricPort,
8588
Port: defaultPort,
8689
SocketPath: defaultSocketPath,
8790
SyncProviderArgs: []string{},
8891
Evaluator: defaultEvaluator,
8992
Image: defaultImage,
90-
Tag: tag,
93+
Tag: defaultTag,
94+
}
95+
96+
if metricsPort := os.Getenv(fmt.Sprintf("%s_%s", InputConfigurationEnvVarPrefix, SidecarMetricPortEnvVar)); metricsPort != "" {
97+
metricsPortI, err := strconv.Atoi(metricsPort)
98+
if err != nil {
99+
return fsc, fmt.Errorf("unable to parse metrics port value %s to int32: %w", metricsPort, err)
100+
}
101+
fsc.MetricsPort = int32(metricsPortI)
102+
}
103+
104+
if port := os.Getenv(fmt.Sprintf("%s_%s", InputConfigurationEnvVarPrefix, SidecarPortEnvVar)); port != "" {
105+
portI, err := strconv.Atoi(port)
106+
if err != nil {
107+
return fsc, fmt.Errorf("unable to parse sidecar port value %s to int32: %w", port, err)
108+
}
109+
fsc.Port = int32(portI)
110+
}
111+
112+
if socketPath := os.Getenv(fmt.Sprintf("%s_%s", InputConfigurationEnvVarPrefix, SidecarSocketPathEnvVar)); socketPath != "" {
113+
fsc.SocketPath = socketPath
114+
}
115+
116+
if evaluator := os.Getenv(fmt.Sprintf("%s_%s", InputConfigurationEnvVarPrefix, SidecarEvaluatorEnvVar)); evaluator != "" {
117+
fsc.Evaluator = evaluator
91118
}
119+
120+
if image := os.Getenv(fmt.Sprintf("%s_%s", InputConfigurationEnvVarPrefix, SidecarImageEnvVar)); image != "" {
121+
fsc.Image = image
122+
}
123+
124+
if tag := os.Getenv(fmt.Sprintf("%s_%s", InputConfigurationEnvVarPrefix, SidecarVersionEnvVar)); tag != "" {
125+
fsc.Tag = tag
126+
}
127+
128+
if syncProviderArgs := os.Getenv(fmt.Sprintf("%s_%s", InputConfigurationEnvVarPrefix, SidecarProviderArgsEnvVar)); syncProviderArgs != "" {
129+
fsc.SyncProviderArgs = strings.Split(syncProviderArgs, ",") // todo: add documentation for this
130+
}
131+
132+
return fsc, nil
92133
}
93134

94135
func (fc *FlagSourceConfigurationSpec) Merge(new *FlagSourceConfigurationSpec) {
@@ -121,30 +162,35 @@ func (fc *FlagSourceConfigurationSpec) Merge(new *FlagSourceConfigurationSpec) {
121162
func (fc *FlagSourceConfigurationSpec) ToEnvVars() []corev1.EnvVar {
122163
envs := []corev1.EnvVar{}
123164

165+
prefix := defaultSidecarEnvVarPrefix
166+
if p := os.Getenv(SidecarEnvVarPrefix); p != "" {
167+
prefix = p
168+
}
169+
124170
if fc.MetricsPort != defaultMetricPort {
125171
envs = append(envs, corev1.EnvVar{
126-
Name: FlagdMetricPortEnvVar,
172+
Name: fmt.Sprintf("%s_%s", prefix, SidecarMetricPortEnvVar),
127173
Value: fmt.Sprintf("%d", fc.MetricsPort),
128174
})
129175
}
130176

131177
if fc.Port != defaultPort {
132178
envs = append(envs, corev1.EnvVar{
133-
Name: FlagdPortEnvVar,
179+
Name: fmt.Sprintf("%s_%s", prefix, SidecarPortEnvVar),
134180
Value: fmt.Sprintf("%d", fc.Port),
135181
})
136182
}
137183

138184
if fc.Evaluator != defaultEvaluator {
139185
envs = append(envs, corev1.EnvVar{
140-
Name: FlagdEvaluatorEnvVar,
186+
Name: fmt.Sprintf("%s_%s", prefix, SidecarEvaluatorEnvVar),
141187
Value: fc.Evaluator,
142188
})
143189
}
144190

145191
if fc.SocketPath != defaultSocketPath {
146192
envs = append(envs, corev1.EnvVar{
147-
Name: FlagdSocketPathEnvVar,
193+
Name: fmt.Sprintf("%s_%s", prefix, SidecarSocketPathEnvVar),
148194
Value: fc.SocketPath,
149195
})
150196
}

chart/open-feature-operator/README.md

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ To install/upgrade the chart with the release name `open-feature-operator`:
2424
helm upgrade -i open-feature-operator openfeature/open-feature-operator
2525
```
2626
This installation will use the default helm configuration, described in the [configuration section](#configuration)
27+
To overwrite these default values use the `--set` flag when calling `helm upgrade` or `helm install`, for example:
28+
```
29+
helm upgrade -i open-feature-operator ./chart/open-feature-operator --set sidecarConfiguration.port=8080 --set controllerManager.kubeRbacProxy.resources.limits.cpu=400m
30+
```
2731

2832
## Uninstall
2933

@@ -38,10 +42,39 @@ The command removes all the Kubernetes components associated with the chart and
3842
## Configuration
3943
<a name="configuration"></a>
4044

45+
### Sidecar configuration
4146
| Value | Default | Explanation |
4247
| ----------- | ----------- | ----------- |
43-
| `defaultNamespace` | `open-feature-operator` | [INTERNAL USE ONLY] To override the namespace use the `--namespace` flag. This default is provided to ensure that the kustomize build charts in `/templates` deploy correctly when no `namespace` is provided via the `-n` flag.|
48+
| `sidecarConfiguration.envVarPrefix` | `FLAGD` | Sets the prefix for all environment variables set in the injected sidecar. |
49+
| `sidecarConfiguration.port` | 8013 | Sets the value of the `XXX_PORT` environment variable for the injected sidecar container.|
50+
| `sidecarConfiguration.metricsPort` | 8014 | Sets the value of the `XXX_METRICS_PORT` environment variable for the injected sidecar container.|
51+
| `sidecarConfiguration.socketPath` | `""` | Sets the value of the `XXX_SOCKET_PATH` environment variable for the injected sidecar container.|
52+
| `sidecarConfiguration.repository` | `ghcr.io/open-feature/flagd` | Sets the image for the injected sidecar container. |
53+
| `sidecarConfiguration.tag` | current flagd version: `v0.3.0` | Sets the version tag for the injected sidecar container. |
54+
| `sidecarConfiguration.providerArgs` | `""` | Used to append arguments to the sidecar startup command. This value is a comma separated string of key values separated by '=', e.g. `key=value,key2=value2` results in the appending of `--sync-provider-args key=value --sync-provider-args key2=value2` |
4455

56+
### Operator resource configuration
57+
<!-- x-release-please-start-version -->
58+
| Value | Default |
59+
| ----------- | ----------- |
60+
| `defaultNamespace` | `open-feature-operator` | [INTERNAL USE ONLY] To override the namespace use the `--namespace` flag. This default is provided to ensure that the kustomize build charts in `/templates` deploy correctly when no `namespace` is provided via the `-n` flag.|
61+
| `controllerManager.kubeRbacProxy.image.repository` | `gcr.io/kubebuilder/kube-rbac-proxy` |
62+
| `controllerManager.kubeRbacProxy.image.tag` | `v0.13.1` |
63+
| `controllerManager.kubeRbacProxy.resources.limits.cpu` | `500m` |
64+
| `controllerManager.kubeRbacProxy.resources.limits.memory` | `128Mi` |
65+
| `controllerManager.kubeRbacProxy.resources.requests.cpu` | `5m` |
66+
| `controllerManager.kubeRbacProxy.resources.requests.memory` | `64Mi` |
67+
| `controllerManager.manager.image.repository` | `ghcr.io/open-feature/open-feature-operator` |
68+
| `controllerManager.manager.image.tag` | `v0.2.23` |
69+
| `controllerManager.manager.resources.limits.cpu` | `500m` |
70+
| `controllerManager.manager.resources.limits.memory` | `128Mi` |
71+
| `controllerManager.manager.resources.requests.cpu` | `10m` |
72+
| `controllerManager.manager.resources.requests.memory` | `64Mi` |
73+
| `managerConfig.controllerManagerConfigYaml` | `1` |
74+
| `managerConfig.replicas.health.healthProbeBindAddress` | `:8081` |
75+
| `managerConfig.replicas.metrics.bindAddress` | `127.0.0.1:8080` |
76+
| `managerConfig.replicas.webhook.port` | `9443` |
77+
<!-- x-release-please-end -->
4578
## Changelog
4679

47-
See [CHANGELOG.md](https://github.com/open-feature/open-feature-operator/blob/main/CHANGELOG.md)
80+
See [CHANGELOG.md](https://github.com/open-feature/open-feature-operator/blob/main/CHANGELOG.md)

chart/open-feature-operator/templates/rendered.yaml

Lines changed: 42 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -611,8 +611,8 @@ spec:
611611
description: Evaluator sets an evaluator, defaults to 'json'
612612
type: string
613613
image:
614-
description: Image allows for the flagd image to be overridden, defaults
615-
to 'ghcr.io/open-feature/flagd'
614+
description: Image allows for the sidecar image to be overridden,
615+
defaults to 'ghcr.io/open-feature/flagd'
616616
type: string
617617
metricsPort:
618618
description: MetricsPort defines the port to serve metrics on, defaults
@@ -633,7 +633,8 @@ spec:
633633
type: string
634634
type: array
635635
tag:
636-
description: Tag to be appended to the flagd image, defaults to 'main'
636+
description: Tag to be appended to the sidecar image, defaults to
637+
'main'
637638
type: string
638639
type: object
639640
status:
@@ -950,14 +951,11 @@ data:
950951
apiVersion: controller-runtime.sigs.k8s.io/v1alpha1
951952
kind: ControllerManagerConfig
952953
health:
953-
healthProbeBindAddress: :8081
954+
healthProbeBindAddress: "{{ .Values.managerConfig.controllerManagerConfigYaml.health.healthProbeBindAddress }}"
954955
metrics:
955-
bindAddress: 127.0.0.1:8080
956+
bindAddress: "{{ .Values.managerConfig.controllerManagerConfigYaml.metrics.bindAddress }}"
956957
webhook:
957-
port: 9443
958-
leaderElection:
959-
leaderElect: true
960-
resourceName: 131bf64c.openfeature.dev
958+
port: 0{{ .Values.managerConfig.controllerManagerConfigYaml.webhook.port }}
961959
kind: ConfigMap
962960
metadata:
963961
name: open-feature-operator-manager-config
@@ -1002,7 +1000,7 @@ metadata:
10021000
name: open-feature-operator-controller-manager
10031001
namespace: '{{ include "chart.namespace" . }}'
10041002
spec:
1005-
replicas: 1
1003+
replicas: 0{{ .Values.controllerManager.replicas }}
10061004
selector:
10071005
matchLabels:
10081006
control-plane: controller-manager
@@ -1018,14 +1016,27 @@ spec:
10181016
- --health-probe-bind-address=:8081
10191017
- --metrics-bind-address=127.0.0.1:8080
10201018
- --leader-elect
1021-
- --flagd-cpu-limit=0.5
1022-
- --flagd-ram-limit=64M
1019+
- --sidecar-cpu-limit=0.5
1020+
- --sidecar-ram-limit=64M
10231021
command:
10241022
- /manager
10251023
env:
1026-
- name: FLAGD_VERSION
1027-
value: v0.3.1
1028-
image: ghcr.io/open-feature/open-feature-operator:main
1024+
- name: SIDECAR_METRICS_PORT
1025+
value: '{{ .Values.sidecarConfiguration.metricsPort }}'
1026+
- name: SIDECAR_PORT
1027+
value: '{{ .Values.sidecarConfiguration.port }}'
1028+
- name: SIDECAR_SOCKET_PATH
1029+
value: '{{ .Values.sidecarConfiguration.socketPath }}'
1030+
- name: SIDECAR_IMAGE
1031+
value: '{{ .Values.sidecarConfiguration.image.repository }}'
1032+
- name: SIDECAR_TAG
1033+
value: '{{ .Values.sidecarConfiguration.image.tag }}'
1034+
- name: SIDECAR_PROVIDER_ARGS
1035+
value: '{{ .Values.sidecarConfiguration.providerArgs }}'
1036+
- name: SIDECAR_ENV_VAR_PREFIX
1037+
value: '{{ .Values.sidecarConfiguration.envVarPrefix }}'
1038+
image: '{{ .Values.controllerManager.manager.image.repository }}:{{ .Values.controllerManager.manager.image.tag
1039+
}}'
10291040
imagePullPolicy: IfNotPresent
10301041
livenessProbe:
10311042
httpGet:
@@ -1046,11 +1057,13 @@ spec:
10461057
periodSeconds: 10
10471058
resources:
10481059
limits:
1049-
cpu: 500m
1050-
memory: 128Mi
1060+
cpu: '{{ .Values.controllerManager.manager.resources.limits.cpu }}'
1061+
memory: '{{ .Values.controllerManager.manager.resources.limits.memory
1062+
}}'
10511063
requests:
1052-
cpu: 10m
1053-
memory: 64Mi
1064+
cpu: '{{ .Values.controllerManager.manager.resources.requests.cpu }}'
1065+
memory: '{{ .Values.controllerManager.manager.resources.requests.memory
1066+
}}'
10541067
securityContext:
10551068
allowPrivilegeEscalation: false
10561069
volumeMounts:
@@ -1062,19 +1075,24 @@ spec:
10621075
- --upstream=http://127.0.0.1:8080/
10631076
- --logtostderr=true
10641077
- --v=0
1065-
image: gcr.io/kubebuilder/kube-rbac-proxy:v0.13.1
1078+
image: '{{ .Values.controllerManager.kubeRbacProxy.image.repository }}:{{
1079+
.Values.controllerManager.kubeRbacProxy.image.tag }}'
10661080
name: kube-rbac-proxy
10671081
ports:
10681082
- containerPort: 8443
10691083
name: https
10701084
protocol: TCP
10711085
resources:
10721086
limits:
1073-
cpu: 500m
1074-
memory: 128Mi
1087+
cpu: '{{ .Values.controllerManager.kubeRbacProxy.resources.limits.cpu
1088+
}}'
1089+
memory: '{{ .Values.controllerManager.kubeRbacProxy.resources.limits.memory
1090+
}}'
10751091
requests:
1076-
cpu: 5m
1077-
memory: 64Mi
1092+
cpu: '{{ .Values.controllerManager.kubeRbacProxy.resources.requests.cpu
1093+
}}'
1094+
memory: '{{ .Values.controllerManager.kubeRbacProxy.resources.requests.memory
1095+
}}'
10781096
securityContext:
10791097
runAsNonRoot: true
10801098
serviceAccountName: open-feature-operator-controller-manager
Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,22 @@
11
# If this namespace is changed the value must be reflected in /open-feature-operator/values.yaml
22
defaultNamespace: open-feature-operator-system
33

4+
sidecarConfiguration:
5+
port: 8013
6+
metricsPort: 8014
7+
socketPath: ""
8+
image:
9+
# these fields must remain in the same order, renovate uses a regex to update the tag value
10+
repository: "ghcr.io/open-feature/flagd"
11+
tag: v0.3.1
12+
providerArgs: ""
13+
envVarPrefix: "FLAGD"
14+
415
controllerManager:
516
kubeRbacProxy:
617
image:
718
repository: gcr.io/kubebuilder/kube-rbac-proxy
8-
tag: v0.13.1
19+
tag: "v0.13.0"
920
resources:
1021
limits:
1122
cpu: 500m
@@ -25,27 +36,12 @@ controllerManager:
2536
cpu: 10m
2637
memory: 64Mi
2738
replicas: 1
39+
2840
managerConfig:
2941
controllerManagerConfigYaml:
3042
health:
3143
healthProbeBindAddress: :8081
32-
leaderElection:
33-
leaderElect: true
34-
resourceName: 131bf64c.openfeature.dev
3544
metrics:
3645
bindAddress: 127.0.0.1:8080
3746
webhook:
3847
port: 9443
39-
metricsService:
40-
ports:
41-
- name: https
42-
port: 8443
43-
protocol: TCP
44-
targetPort: https
45-
type: ClusterIP
46-
webhookService:
47-
ports:
48-
- port: 443
49-
protocol: TCP
50-
targetPort: 9443
51-
type: ClusterIP

0 commit comments

Comments
 (0)