Przeglądaj źródła

fix: make vault provider return NoSecretErr to respect deletionPolicy (#2455)

relates to #1512 #1502

Signed-off-by: Moritz Johner <beller.moritz@googlemail.com>
Moritz Johner 2 lat temu
rodzic
commit
69fe93ea49
2 zmienionych plików z 17 dodań i 1 usunięć
  1. 1 1
      pkg/provider/vault/vault.go
  2. 16 0
      pkg/provider/vault/vault_test.go

+ 1 - 1
pkg/provider/vault/vault.go

@@ -707,7 +707,7 @@ func (v *client) GetSecret(ctx context.Context, ref esv1beta1.ExternalSecretData
 
 	// Return nil if secret value is null
 	if data == nil {
-		return nil, nil
+		return nil, esv1beta1.NoSecretError{}
 	}
 	jsonStr, err := json.Marshal(data)
 	if err != nil {

+ 16 - 0
pkg/provider/vault/vault_test.go

@@ -632,6 +632,22 @@ func TestGetSecret(t *testing.T) {
 				val: []byte("something different"),
 			},
 		},
+		"ReadSecretWithMissingValueFromData": {
+			reason: "Should return a NoSecretErr",
+			args: args{
+				store: makeValidSecretStoreWithVersion(esv1beta1.VaultKVStoreV1).Spec.Provider.Vault,
+				data: esv1beta1.ExternalSecretDataRemoteRef{
+					Property: "not-relevant",
+				},
+				vLogical: &fake.Logical{
+					ReadWithDataWithContextFn: fake.NewReadWithContextFn(nil, nil),
+				},
+			},
+			want: want{
+				err: esv1beta1.NoSecretErr,
+				val: nil,
+			},
+		},
 		"ReadSecretWithSliceValue": {
 			reason: "Should return property as a joined slice",
 			args: args{