Skip to content

Commit b876541

Browse files
committed
Ensure that spec.hmacSecretData's value honoured
Previously, upon the first application of a VaultStaticSecret instance that had spec.hmacSecretData explicitly set to false, the K8s API would replace that value with default as is defined in the CRD's schema. This fix makes HMACSecretData a pointer receiver, which make K8s do the right thing.
1 parent 17f8448 commit b876541

File tree

4 files changed

+12
-6
lines changed

4 files changed

+12
-6
lines changed

api/v1beta1/vaultstaticsecret_types.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ type VaultStaticSecretSpec struct {
4242
// and during incoming Vault secret comparison.
4343
// Enabling this feature is recommended to ensure that Secret's data stays consistent with Vault.
4444
// +kubebuilder:default=true
45-
HMACSecretData bool `json:"hmacSecretData,omitempty"`
45+
HMACSecretData *bool `json:"hmacSecretData,omitempty"`
4646
// RolloutRestartTargets should be configured whenever the application(s) consuming the Vault secret does
4747
// not support dynamically reloading a rotated secret.
4848
// In that case one, or more RolloutRestartTarget(s) can be configured here. The Operator will

api/v1beta1/zz_generated.deepcopy.go

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

controllers/vaultstaticsecret_controller.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ func (r *VaultStaticSecretReconciler) Reconcile(ctx context.Context, req ctrl.Re
127127

128128
var doRolloutRestart bool
129129
doSync := true
130-
if o.Spec.HMACSecretData {
130+
if o.Spec.HMACSecretData != nil && *o.Spec.HMACSecretData {
131131
// we want to ensure that requeueAfter is set so that we can perform the proper drift detection during each reconciliation.
132132
// setting up a watcher on the Secret is also possibility, but polling seems to be the simplest approach for now.
133133
if requeueAfter == 0 {

test/integration/vaultstaticsecret_integration_test.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import (
1717

1818
"github.com/cenkalti/backoff/v4"
1919
"github.com/gruntwork-io/terratest/modules/terraform"
20+
"github.com/hashicorp/vault/sdk/helper/pointerutil"
2021
"github.com/stretchr/testify/assert"
2122
"github.com/stretchr/testify/require"
2223
corev1 "k8s.io/api/core/v1"
@@ -215,7 +216,7 @@ func TestVaultStaticSecret(t *testing.T) {
215216
Name: "secretkv",
216217
Create: false,
217218
},
218-
HMACSecretData: true,
219+
HMACSecretData: pointerutil.BoolPtr(true),
219220
RefreshAfter: "5s",
220221
RolloutRestartTargets: []secretsv1beta1.RolloutRestartTarget{
221222
{
@@ -243,7 +244,7 @@ func TestVaultStaticSecret(t *testing.T) {
243244
Create: false,
244245
},
245246
RefreshAfter: "5s",
246-
HMACSecretData: false,
247+
HMACSecretData: pointerutil.BoolPtr(false),
247248
},
248249
},
249250
}
@@ -360,7 +361,7 @@ func TestVaultStaticSecret(t *testing.T) {
360361
obj.ObjectMeta.Namespace, data)
361362
if assert.NoError(t, err) {
362363
assertSyncableSecret(t, crdClient, obj, secret)
363-
if obj.Spec.HMACSecretData {
364+
if obj.Spec.HMACSecretData != nil && *obj.Spec.HMACSecretData {
364365
assertHMAC(t, ctx, crdClient, obj, expectInitial)
365366
} else {
366367
assertNoHMAC(t, obj)
@@ -444,7 +445,7 @@ func TestVaultStaticSecret(t *testing.T) {
444445
Create: true,
445446
},
446447
RefreshAfter: "5s",
447-
HMACSecretData: true,
448+
HMACSecretData: pointerutil.BoolPtr(true),
448449
},
449450
}
450451
if tt.version != 0 {

0 commit comments

Comments
 (0)