Skip to content

Commit 36bdc48

Browse files
lilatomicdrivebyer
andauthored
fix: include external-config in config initContainer (OT-CONTAINER-KIT#1566)
* fix: include external-config in config initContainer The initContainer to generate the Redis config looks for the external config files for the targets to add `include` directives for. The external-config volume must therefore be mounted in this initContainer, or else the external configs will not be followed by Redis. Signed-off-by: Daniel Goldman <[email protected]> * add e2e test Signed-off-by: drivebyer <[email protected]> * fix syntax Signed-off-by: drivebyer <[email protected]> --------- Signed-off-by: Daniel Goldman <[email protected]> Signed-off-by: drivebyer <[email protected]> Co-authored-by: drivebyer <[email protected]>
1 parent dcfb286 commit 36bdc48

File tree

5 files changed

+48
-14
lines changed

5 files changed

+48
-14
lines changed

internal/k8sutils/statefulset.go

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ func generateStatefulSetsDef(stsMeta metav1.ObjectMeta, params statefulSetParame
314314
},
315315
}
316316

317-
statefulset.Spec.Template.Spec.InitContainers = generateInitContainerDef(containerParams.Role, stsMeta.GetName(), initcontainerParams, initcontainerParams.AdditionalMountPath, containerParams, params.ClusterVersion)
317+
statefulset.Spec.Template.Spec.InitContainers = generateInitContainerDef(containerParams.Role, stsMeta.GetName(), initcontainerParams, params.ExternalConfig, initcontainerParams.AdditionalMountPath, containerParams, params.ClusterVersion)
318318

319319
if params.Tolerations != nil {
320320
statefulset.Spec.Template.Spec.Tolerations = *params.Tolerations
@@ -571,7 +571,7 @@ if [ "$ROLE" = "master" ]; then
571571
fi`, authArgs, tlsArgs, authArgs, tlsArgs, authArgs, tlsArgs)
572572
}
573573

574-
func generateInitContainerDef(role, name string, initcontainerParams initContainerParameters, mountpath []corev1.VolumeMount, containerParams containerParameters, clusterVersion *string) []corev1.Container {
574+
func generateInitContainerDef(role, name string, initcontainerParams initContainerParameters, externalConfig *string, mountpath []corev1.VolumeMount, containerParams containerParameters, clusterVersion *string) []corev1.Container {
575575
containers := []corev1.Container{}
576576

577577
if features.Enabled(features.GenerateConfigInInitContainer) {
@@ -591,6 +591,14 @@ func generateInitContainerDef(role, name string, initcontainerParams initContain
591591
})
592592
}
593593
}
594+
595+
VolumeMounts := []corev1.VolumeMount{
596+
generateConfigVolumeMount(common.VolumeNameConfig),
597+
}
598+
if externalConfig != nil {
599+
VolumeMounts = append(VolumeMounts, externalConfigMount)
600+
}
601+
594602
container := corev1.Container{
595603
Name: "init-config",
596604
Image: image,
@@ -609,9 +617,7 @@ func generateInitContainerDef(role, name string, initcontainerParams initContain
609617
containerParams.Port,
610618
clusterVersion,
611619
),
612-
VolumeMounts: []corev1.VolumeMount{
613-
generateConfigVolumeMount(common.VolumeNameConfig),
614-
},
620+
VolumeMounts: VolumeMounts,
615621
}
616622
// Set init-config resources to match main container if present
617623
if containerParams.Resources != nil {
@@ -759,6 +765,11 @@ func getExporterEnvironmentVariables(params containerParameters) []corev1.EnvVar
759765
return envVars
760766
}
761767

768+
var externalConfigMount = corev1.VolumeMount{
769+
Name: "external-config",
770+
MountPath: "/etc/redis/external.conf.d",
771+
}
772+
762773
// getVolumeMount gives information about persistence mount
763774
func getVolumeMount(name string, persistenceEnabled *bool, clusterMode bool, nodeConfVolume bool, externalConfig *string, mountpath []corev1.VolumeMount, tlsConfig *commonapi.TLSConfig, aclConfig *commonapi.ACLConfig) []corev1.VolumeMount {
764775
var VolumeMounts []corev1.VolumeMount
@@ -794,10 +805,7 @@ func getVolumeMount(name string, persistenceEnabled *bool, clusterMode bool, nod
794805
}
795806

796807
if externalConfig != nil {
797-
VolumeMounts = append(VolumeMounts, corev1.VolumeMount{
798-
Name: "external-config",
799-
MountPath: "/etc/redis/external.conf.d",
800-
})
808+
VolumeMounts = append(VolumeMounts, externalConfigMount)
801809
}
802810

803811
if features.Enabled(features.GenerateConfigInInitContainer) {

internal/k8sutils/statefulset_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1139,7 +1139,7 @@ func TestGenerateInitContainerDef(t *testing.T) {
11391139
for i := range tests {
11401140
test := tests[i]
11411141
t.Run(test.name, func(t *testing.T) {
1142-
initContainer := generateInitContainerDef("", test.initContainerName, test.initContainerDef, test.mountPaths, containerParameters{}, ptr.To("v6"))
1142+
initContainer := generateInitContainerDef("", test.initContainerName, test.initContainerDef, nil, test.mountPaths, containerParameters{}, ptr.To("v6"))
11431143
assert.Equal(t, initContainer, test.expectedInitContainerDef, "Init Container Configuration")
11441144
})
11451145
}
@@ -1377,7 +1377,7 @@ func TestGenerateInitContainerDefWithSecurityContext(t *testing.T) {
13771377
// Note: The operator image will be determined by the actual implementation
13781378
// We'll test the SecurityContext functionality without mocking the image
13791379

1380-
initContainer := generateInitContainerDef("", test.initContainerName, test.initContainerDef, test.mountPaths, containerParameters{}, ptr.To("v6"))
1380+
initContainer := generateInitContainerDef("", test.initContainerName, test.initContainerDef, nil, test.mountPaths, containerParameters{}, ptr.To("v6"))
13811381

13821382
// Verify the SecurityContext is correctly applied
13831383
if test.featureEnabled {

tests/e2e-chainsaw/v1beta2/setup/redis-cluster/chainsaw-test.yaml

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ spec:
1313
file: secret.yaml
1414
- apply:
1515
file: ../../../../data-assert/resources.yaml
16+
- apply:
17+
file: ../../../../testdata/additional-config.yaml
1618
- script:
1719
timeout: 10s
1820
content: |
@@ -52,7 +54,7 @@ spec:
5254
- assert:
5355
file: secret.yaml
5456

55-
- name: Random Check Dynamic Config
57+
- name: Assert config
5658
try:
5759
- script:
5860
timeout: 30s
@@ -68,21 +70,31 @@ spec:
6870
6971
# Check leader configuration
7072
LEADER_CMD="kubectl exec -n ${NAMESPACE} redis-cluster-v1beta2-leader-${LEADER_INDEX}"
71-
LEADER_CMD="${LEADER_CMD} -c redis-cluster-v1beta2-leader -- redis-cli -a Opstree1234 --tls --cacert /tls/ca.crt"
73+
LEADER_CMD="${LEADER_CMD} -c redis-cluster-v1beta2-leader -- redis-cli --no-auth-warning -a Opstree1234 --tls --cacert /tls/ca.crt"
7274
SLOWLOG_VALUE=$(${LEADER_CMD} config get slowlog-log-slower-than | grep -A1 "slowlog-log-slower-than" | tail -n1)
75+
TCP_KEEPALIVE_VALUE=$(${LEADER_CMD} config get tcp-keepalive | grep -A1 "tcp-keepalive" | tail -n1)
7376
if [ "$SLOWLOG_VALUE" != "5000" ]; then
7477
echo "leader-${LEADER_INDEX} slowlog-log-slower-than value is $SLOWLOG_VALUE, expected 5000"
7578
exit 1
7679
fi
80+
if [ "$TCP_KEEPALIVE_VALUE" != "400" ]; then
81+
echo "leader-${LEADER_INDEX} tcp-keepalive value is $TCP_KEEPALIVE_VALUE, expected 400"
82+
exit 1
83+
fi
7784
7885
# Check follower configuration
7986
FOLLOWER_CMD="kubectl exec -n ${NAMESPACE} redis-cluster-v1beta2-follower-${FOLLOWER_INDEX}"
80-
FOLLOWER_CMD="${FOLLOWER_CMD} -c redis-cluster-v1beta2-follower -- redis-cli -a Opstree1234 --tls --cacert /tls/ca.crt"
87+
FOLLOWER_CMD="${FOLLOWER_CMD} -c redis-cluster-v1beta2-follower -- redis-cli --no-auth-warning -a Opstree1234 --tls --cacert /tls/ca.crt"
8188
SLOWLOG_VALUE=$(${FOLLOWER_CMD} config get slowlog-log-slower-than | grep -A1 "slowlog-log-slower-than" | tail -n1)
89+
TCP_KEEPALIVE_VALUE=$(${FOLLOWER_CMD} config get tcp-keepalive | grep -A1 "tcp-keepalive" | tail -n1)
8290
if [ "$SLOWLOG_VALUE" != "5000" ]; then
8391
echo "follower-${FOLLOWER_INDEX} slowlog-log-slower-than value is $SLOWLOG_VALUE, expected 5000"
8492
exit 1
8593
fi
94+
if [ "$TCP_KEEPALIVE_VALUE" != "400" ]; then
95+
echo "follower-${LEADER_INDEX} tcp-keepalive value is $TCP_KEEPALIVE_VALUE, expected 400"
96+
exit 1
97+
fi
8698
8799
echo "Redis instances leader-${LEADER_INDEX} and follower-${FOLLOWER_INDEX} have correct slowlog-log-slower-than configuration"
88100
exit 0

tests/e2e-chainsaw/v1beta2/setup/redis-cluster/cluster.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@ spec:
1313
clusterSize: 3
1414
clusterVersion: v7
1515
persistenceEnabled: true
16+
redisLeader:
17+
redisConfig:
18+
additionalRedisConfig: redis-external-config
19+
redisFollower:
20+
redisConfig:
21+
additionalRedisConfig: redis-external-config
1622
redisConfig:
1723
maxMemoryPercentOfLimit: 80
1824
dynamicConfig:
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
apiVersion: v1
3+
kind: ConfigMap
4+
metadata:
5+
name: redis-external-config
6+
data:
7+
redis-additional.conf: |
8+
tcp-keepalive 400

0 commit comments

Comments
 (0)