Skip to content

Commit 3d52fdb

Browse files
authored
feat: Add SecurityContext to init-config when behind GenerateConfigInInitContainer feature flag
feat: Add SecurityContext to Redis init containers in tests and configurations when behind GenerateConfigInInitContainer feature flag Signed-off-by: Jeffrey Böhm <[email protected]>
1 parent 88d688a commit 3d52fdb

File tree

9 files changed

+354
-21
lines changed

9 files changed

+354
-21
lines changed

README.md

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,13 @@
2323
</a>
2424
</p>
2525

26-
A Golang based redis operator that will make/oversee Redis standalone and cluster mode setup on top of the Kubernetes. It can create a redis cluster setup with best practices on Cloud as well as the Bare metal environment. Also, it provides an in-built monitoring capability using redis-exporter.
26+
A Golang-based Redis operator that will make/oversee Redis standalone and cluster mode setup on top of Kubernetes. It can create a Redis cluster setup with best practices on Cloud as well as the bare metal environment. Also, it provides an in-built monitoring capability using redis-exporter.
2727

2828
For documentation, please refer to <https://redis-operator.opstree.dev/>
2929

30-
Organizations that are using Redis Operator to manage their redis workload can be found [here](./USED_BY_ORGANIZATIONS.md). If your organization is also using Redis Operator, please free to add by creating a [pull request](https://github.com/OT-CONTAINER-KIT/redis-operator/pulls)
30+
Organizations that are using Redis Operator to manage their Redis workload can be found [here](./USED_BY_ORGANIZATIONS.md). If your organization is also using Redis Operator, please feel free to add by creating a [pull request](https://github.com/OT-CONTAINER-KIT/redis-operator/pulls)
3131

32-
This operator only supports versions of redis `=>6`.
32+
This operator only supports versions of Redis `>=6`.
3333

3434
## Architecture
3535

@@ -39,23 +39,23 @@ This operator only supports versions of redis `=>6`.
3939

4040
## Purpose
4141

42-
There are multiple problems that people face while setting up redis setup on Kubernetes, specially cluster type setup. The purpose of creating this opperator is to provide an easy and production ready interface for redis setup that include best-practices, security controls, monitoring, and management.
42+
There are multiple problems that people face while setting up Redis setup on Kubernetes, especially cluster type setup. The purpose of creating this operator is to provide an easy and production-ready interface for Redis setup that includes best-practices, security controls, monitoring, and management.
4343

4444
## Supported Features
4545

46-
Here the features which are supported by this operator:-
46+
Here are the features which are supported by this operator:
4747

4848
- Redis cluster and standalone mode setup
4949
- Redis cluster failover and recovery
5050
- Inbuilt monitoring with redis exporter
51-
- Password and password-less setup of redis
51+
- Password and password-less setup of Redis
5252
- TLS support for additional security layer
53-
- Ipv4 and Ipv6 support for redis setup
54-
- Detailed monitoring grafana dashboard
53+
- IPv4 and IPv6 support for Redis setup
54+
- Detailed monitoring Grafana dashboard
5555

5656
## Prerequisites
5757

58-
Redis operator requires a Kubernetes cluster of version `>=1.18.0`. If you have just started with Operators, it's highly recommended using the latest version of Kubernetes.
58+
Redis Operator requires a Kubernetes cluster of version `>=1.18.0`. If you have just started with Operators, it's highly recommended using the latest version of Kubernetes.
5959

6060
## Image Compatibility
6161

@@ -74,59 +74,59 @@ The following table shows the compatibility between the Operator Version, Redis
7474

7575
## Quickstart
7676

77-
The setup can be done by using helm. If you want to see more example, please go through the [example](./example) folder.
77+
The setup can be done by using Helm. If you want to see more examples, please go through the [example](./example) folder.
7878

79-
But you can simply use the helm chart for installation.
79+
But you can simply use the Helm chart for installation.
8080

8181
```shell
82-
# Add the helm chart
82+
# Add the Helm chart
8383
$ helm repo add ot-helm https://ot-container-kit.github.io/helm-charts/
8484
```
8585

8686
```shell
87-
# Deploy the redis-operator
87+
# Deploy the Redis operator
8888
$ helm upgrade redis-operator ot-helm/redis-operator \
8989
--install --create-namespace --namespace ot-operators
9090
```
9191

92-
After deployment, verify the installation of operator
92+
After deployment, verify the installation of the operator
9393

9494
```shell
9595
helm test redis-operator --namespace ot-operators
9696
```
9797

98-
Creating redis cluster, standalone, replication and sentinel setup.
98+
Creating Redis cluster, standalone, replication and sentinel setup.
9999

100100
```shell
101-
# Create redis cluster setup
101+
# Create Redis cluster setup
102102
$ helm upgrade redis-cluster ot-helm/redis-cluster \
103103
--set redisCluster.clusterSize=3 --install \
104104
--namespace ot-operators
105105
```
106106

107107
```shell
108-
# Create redis standalone setup
108+
# Create Redis standalone setup
109109
$ helm upgrade redis ot-helm/redis \
110110
--install --namespace ot-operators
111111
```
112112

113113
```shell
114-
# Create redis replication setup
114+
# Create Redis replication setup
115115
$ helm upgrade redis-replication ot-helm/replication \
116116
--install --namespace ot-operators
117117
```
118118

119119
```shell
120-
# Create redis sentinel setup
120+
# Create Redis sentinel setup
121121
$ helm upgrade redis-sentinel ot-helm/sentinel \
122122
--install --namespace ot-operators
123123
```
124124

125-
If you want to customize the value file by yourself while initializing the helm command, the values files for reference are present [here](https://github.com/OT-CONTAINER-KIT/helm-charts/tree/main/charts/redis-setup).
125+
If you want to customize the values file by yourself while initializing the Helm command, the values files for reference are present [here](https://github.com/OT-CONTAINER-KIT/helm-charts/tree/main/charts/redis-setup).
126126

127127
## Monitoring with Prometheus
128128

129-
To monitor redis performance we will be using prometheus. In any case, extra prometheus configuration will not be required because we will be using the Prometheus service discover pattern. For that we already have set these annotations:-
129+
To monitor Redis performance we will be using Prometheus. In any case, extra Prometheus configuration will not be required because we will be using the Prometheus service discovery pattern. For that we already have set these annotations:
130130

131131
```yaml
132132
annotations:

internal/k8sutils/redis-cluster_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -498,6 +498,16 @@ func Test_generateRedisClusterInitContainerParams(t *testing.T) {
498498
Name: "example-config",
499499
},
500500
},
501+
SecurityContext: &corev1.SecurityContext{
502+
RunAsUser: ptr.To(int64(1000)),
503+
RunAsGroup: ptr.To(int64(1000)),
504+
AllowPrivilegeEscalation: ptr.To(false),
505+
ReadOnlyRootFilesystem: ptr.To(true),
506+
Capabilities: &corev1.Capabilities{
507+
Drop: []corev1.Capability{"ALL"},
508+
Add: []corev1.Capability{"NET_BIND_SERVICE"},
509+
},
510+
},
501511
}
502512

503513
data, err := os.ReadFile(path)

internal/k8sutils/redis-sentinel_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,16 @@ func Test_generateRedisSentinelInitContainerParams(t *testing.T) {
281281
SubPathExpr: "",
282282
},
283283
},
284+
SecurityContext: &corev1.SecurityContext{
285+
RunAsUser: ptr.To(int64(1000)),
286+
RunAsGroup: ptr.To(int64(1000)),
287+
AllowPrivilegeEscalation: ptr.To(false),
288+
ReadOnlyRootFilesystem: ptr.To(true),
289+
Capabilities: &corev1.Capabilities{
290+
Drop: []corev1.Capability{"ALL"},
291+
Add: []corev1.Capability{"NET_BIND_SERVICE"},
292+
},
293+
},
284294
}
285295

286296
data, err := os.ReadFile(path)

internal/k8sutils/redis-standalone_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,16 @@ func Test_generateRedisStandaloneInitContainerParams(t *testing.T) {
291291
Name: "example-config",
292292
},
293293
},
294+
SecurityContext: &corev1.SecurityContext{
295+
RunAsUser: ptr.To(int64(1000)),
296+
RunAsGroup: ptr.To(int64(1000)),
297+
AllowPrivilegeEscalation: ptr.To(false),
298+
ReadOnlyRootFilesystem: ptr.To(true),
299+
Capabilities: &corev1.Capabilities{
300+
Drop: []corev1.Capability{"ALL"},
301+
Add: []corev1.Capability{"NET_BIND_SERVICE"},
302+
},
303+
},
294304
}
295305

296306
data, err := os.ReadFile(path)

internal/k8sutils/statefulset.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -596,6 +596,7 @@ func generateInitContainerDef(role, name string, initcontainerParams initContain
596596
Image: image,
597597
ImagePullPolicy: corev1.PullIfNotPresent,
598598
Command: []string{"/operator", "agent"},
599+
SecurityContext: initcontainerParams.SecurityContext,
599600
Env: getEnvironmentVariables(
600601
containerParams.Role,
601602
containerParams.EnabledPassword,

0 commit comments

Comments
 (0)