Skip to content

Commit b498778

Browse files
Merge pull request #600 from xek/fix-daily-pod-recreation-OSPRH-16545
Fix daily keystone pod recreation by mounting keys directly
2 parents aa5dac8 + d1dc2e2 commit b498778

File tree

7 files changed

+14
-28
lines changed

7 files changed

+14
-28
lines changed

controllers/keystoneapi_controller.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1524,7 +1524,7 @@ func (r *KeystoneAPIReconciler) ensureFernetKeys(
15241524
numberKeys = int(*instance.Spec.FernetMaxActiveKeys)
15251525
}
15261526

1527-
secret, hash, err := oko_secret.GetSecret(ctx, helper, secretName, instance.Namespace)
1527+
secret, _, err := oko_secret.GetSecret(ctx, helper, secretName, instance.Namespace)
15281528

15291529
if err != nil && !k8s_errors.IsNotFound(err) {
15301530
return err
@@ -1556,8 +1556,9 @@ func (r *KeystoneAPIReconciler) ensureFernetKeys(
15561556
return err
15571557
}
15581558
} else {
1559-
// add hash to envVars
1560-
(*envVars)[secret.Name] = env.SetValue(hash)
1559+
// DON'T add hash to envVars to prevent pod restarts when keys rotate
1560+
// Keys are mounted directly to /etc/keystone/fernet-keys, so Kubernetes
1561+
// will propagate changes automatically without needing pod recreation
15611562

15621563
changedKeys := false
15631564

pkg/keystone/volumes.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,12 +130,12 @@ func getVolumeMounts(
130130
ReadOnly: true,
131131
},
132132
{
133-
MountPath: "/var/lib/fernet-keys",
133+
MountPath: "/etc/keystone/fernet-keys",
134134
ReadOnly: true,
135135
Name: "fernet-keys",
136136
},
137137
{
138-
MountPath: "/var/lib/credential-keys",
138+
MountPath: "/etc/keystone/credential-keys",
139139
ReadOnly: true,
140140
Name: "credential-keys",
141141
},

templates/keystoneapi/config/keystone-api-config.json

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -57,18 +57,6 @@
5757
"optional": true,
5858
"merge": true
5959
},
60-
{
61-
"source": "/var/lib/credential-keys",
62-
"dest": "/etc/keystone/",
63-
"owner": "keystone:keystone",
64-
"perm": "0700"
65-
},
66-
{
67-
"source": "/var/lib/fernet-keys",
68-
"dest": "/etc/keystone/",
69-
"owner": "keystone:keystone",
70-
"perm": "0700"
71-
},
7260
{
7361
"source": "/var/lib/config-data/default/my.cnf",
7462
"dest": "/etc/my.cnf",

tests/functional/keystoneapi_controller_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1524,7 +1524,8 @@ var _ = Describe("Keystone controller", func() {
15241524

15251525
Eventually(func(g Gomega) {
15261526
keystone = GetKeystoneAPI(keystoneAPIName)
1527-
g.Expect(keystone.Status.Hash["input"]).ToNot(Equal(currentHash))
1527+
// With the new direct mounting approach, the input hash should NOT change
1528+
g.Expect(keystone.Status.Hash["input"]).To(Equal(currentHash))
15281529

15291530
updatedSecret := th.GetSecret(types.NamespacedName{Namespace: keystoneAPIName.Namespace, Name: "keystone"})
15301531
g.Expect(updatedSecret).ToNot(BeNil())

tests/kuttl/common/scripts/rotate_token.sh

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,7 @@ for rotation in {1..5}; do
2828

2929
sleep 100
3030

31-
# Wait for rollout to complete
32-
if ! oc rollout status deployment/keystone -n $NAMESPACE --timeout=60s; then
33-
echo "Rollout status check failed for rotation $rotation."
34-
continue
35-
fi
31+
# Note: keystone is not being restarted
3632

3733
echo "Rotation $rotation completed successfully."
3834
done

tests/kuttl/common/scripts/validate_test_token.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ while [ $seconds -le 30 ]; do
1111
seconds=$(( seconds + 1 ))
1212
done
1313

14-
sleep 20 # make sure a rollout started
15-
16-
oc rollout status deployment/keystone -n $NAMESPACE
14+
# Wait for secret propagation to pods instead of waiting for rollout
15+
# Since pods no longer restart during key rotation, keys are updated via Kubernetes secret propagation
16+
sleep 60
1717

1818
export OS_TOKEN=$(cat /tmp/temporary_test_token)
1919

tests/kuttl/tests/keystone_tls/01-assert.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,10 @@ spec:
4545
name: config-data
4646
readOnly: true
4747
subPath: keystone-api-config.json
48-
- mountPath: /var/lib/fernet-keys
48+
- mountPath: /etc/keystone/fernet-keys
4949
name: fernet-keys
5050
readOnly: true
51-
- mountPath: /var/lib/credential-keys
51+
- mountPath: /etc/keystone/credential-keys
5252
name: credential-keys
5353
readOnly: true
5454
- mountPath: /etc/pki/ca-trust/extracted/pem/tls-ca-bundle.pem

0 commit comments

Comments
 (0)