Skip to content

Commit 238ddf6

Browse files
committed
Handle create/rotate operations from Vault
Add isCreateOrRotatePath helper to detect create/rotate-related operations and use it in the event stream handler. Update the dynamicSecretEventPath unit test to pass a VaultDynamicSecret instance.
1 parent c08c81d commit 238ddf6

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

controllers/vaultdynamicsecret_controller.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -870,8 +870,8 @@ func (r *VaultDynamicSecretReconciler) streamDynamicSecretEvents(ctx context.Con
870870
logger.Info("Modified event received from Vault",
871871
"path", path, "operation", operation, "vdsPath", vdsPath)
872872

873-
// handle update during a lease renewal
874-
if operation == "creds-renew" && path == vdsPath {
873+
// handle update during credential creation or role rotation
874+
if isCreateOrRotatePath(operation) && path == vdsPath {
875875
logger.Info("Create/update event received on VaultDynamicSecret, triggering reconciliation",
876876
"operation", operation, "path", path)
877877

@@ -1065,6 +1065,11 @@ func (r *VaultDynamicSecretReconciler) vaultClientCallback(ctx context.Context,
10651065
}
10661066
}
10671067

1068+
// isCreateOrRotatePath checks if the operation is a create or rotate operation
1069+
func isCreateOrRotatePath(operation string) bool {
1070+
return operation == "creds-create" || operation == "static-creds-create" || operation == "rotate"
1071+
}
1072+
10681073
func computeRotationTime(o *secretsv1beta1.VaultDynamicSecret) time.Time {
10691074
var ts int64
10701075
var horizon time.Duration

controllers/vaultdynamicsecret_controller_test.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1022,7 +1022,12 @@ func Test_dynamicSecretEventPath(t *testing.T) {
10221022

10231023
for _, tt := range tests {
10241024
t.Run(tt.name, func(t *testing.T) {
1025-
assert.Equal(t, tt.want, dynamicSecretEventPath)
1025+
vds := &secretsv1beta1.VaultDynamicSecret{
1026+
Spec: secretsv1beta1.VaultDynamicSecretSpec{
1027+
Mount: tt.mount,
1028+
},
1029+
}
1030+
assert.Equal(t, tt.want, dynamicSecretEventPath(vds))
10261031
})
10271032
}
10281033
}

0 commit comments

Comments
 (0)