Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ignore k8s secret not found when ESS enabled #492

Merged
merged 2 commits into from
Aug 4, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pkg/connection/store/kubernetes/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,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 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if not found, then what would be the value of ks.Data?

could we add a unit test for the new behavior?

If ESS is not enabled, then should we return the error?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if not found, then what would be the value of ks.Data?

It will be an empty map.

could we add a unit test for the new behavior?

Sure, will update the PR.

If ESS is not enabled, then should we return the error?

This code block is only called when ESS is enabled.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It will be an empty map.

Can we update the functions docs to reflect that?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It will be an empty map.

Can we update the functions docs to reflect that?

It shouldn't be necessary. In real world, we shouldn't end up with an empty secret. This change is done to proceed with an intermediate stage where the claim/composite secret is not created yet but it's fetched by the PTF composer to observe the state. Later in the reconciliation loop, the secret will be created as usual and we don't need to handle not found errors.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe making it more explicit would be helpful, something like:

Suggested change
if err := ss.client.Get(ctx, types.NamespacedName{Name: n.Name, Namespace: ss.namespaceForSecret(n)}, ks); resource.IgnoreNotFound(err) != nil {
err := ss.client.Get(ctx, types.NamespacedName{Name: n.Name, Namespace: ss.namespaceForSecret(n)}, ks)
if kerrors.IsNotFound(err) {
return nil
}
if err != nil {
return errors.Wrap(err, errGetSecret)
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or is the caller relying on the fact that Metadata is set even on not found?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think if we cannot find the secret on the store, we should overwrite the given secret fields with empty/nil values.

return errors.Wrap(err, errGetSecret)
}
s.Data = ks.Data
Expand Down