Skip to content

Commit

Permalink
Merge pull request #497 from ezgidemirel/backport-4191
Browse files Browse the repository at this point in the history
[Backport release-0.19] Ignore k8s secret not found when ESS enabled
  • Loading branch information
phisco authored Aug 4, 2023
2 parents 2ef3cde + b0a09a3 commit 504fd54
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
2 changes: 1 addition & 1 deletion pkg/connection/store/kubernetes/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func buildClient(ctx context.Context, local client.Client, cfg v1.SecretStoreCon
// ReadKeyValues reads and returns key value pairs for a given Kubernetes Secret.
func (ss *SecretStore) ReadKeyValues(ctx context.Context, n store.ScopedName, s *store.Secret) error {
ks := &corev1.Secret{}
if err := ss.client.Get(ctx, types.NamespacedName{Name: n.Name, Namespace: ss.namespaceForSecret(n)}, ks); err != nil {
if err := ss.client.Get(ctx, types.NamespacedName{Name: n.Name, Namespace: ss.namespaceForSecret(n)}, ks); resource.IgnoreNotFound(err) != nil {
return errors.Wrap(err, errGetSecret)
}
s.Data = ks.Data
Expand Down
24 changes: 21 additions & 3 deletions pkg/connection/store/kubernetes/store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,22 +102,39 @@ func TestSecretStoreReadKeyValues(t *testing.T) {
args: args{
client: resource.ClientApplicator{
Client: &test.MockClient{
MockGet: test.NewMockGetFn(nil, func(obj client.Object) error {
MockGet: func(ctx context.Context, key client.ObjectKey, obj client.Object) error {
if key.Name != fakeSecretName || key.Namespace != fakeSecretNamespace {
return errors.New("unexpected secret name or namespace to get the secret")
}
*obj.(*corev1.Secret) = corev1.Secret{
Data: fakeKV(),
}
return nil
}),
},
},
},
n: store.ScopedName{
Name: fakeSecretName,
Name: fakeSecretName,
Scope: fakeSecretNamespace,
},
},
want: want{
result: store.KeyValues(fakeKV()),
},
},
"SecretNotFound": {
reason: "Should return nil as an error if secret is not found",
args: args{
client: resource.ClientApplicator{
Client: &test.MockClient{
MockGet: test.NewMockGetFn(kerrors.NewNotFound(schema.GroupResource{}, "")),
},
},
},
want: want{
err: nil,
},
},
}
for name, tc := range cases {
t.Run(name, func(t *testing.T) {
Expand All @@ -126,6 +143,7 @@ func TestSecretStoreReadKeyValues(t *testing.T) {
}

s := &store.Secret{}
s.ScopedName = tc.args.n
err := ss.ReadKeyValues(context.Background(), tc.args.n, s)
if diff := cmp.Diff(tc.want.err, err, test.EquateErrors()); diff != "" {
t.Errorf("\n%s\nss.ReadKeyValues(...): -want error, +got error:\n%s", tc.reason, diff)
Expand Down

0 comments on commit 504fd54

Please sign in to comment.