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

Clear Cache for Pepr Store on Failure #865

Closed
cmwylie19 opened this issue Jun 7, 2024 · 0 comments · Fixed by #866
Closed

Clear Cache for Pepr Store on Failure #865

cmwylie19 opened this issue Jun 7, 2024 · 0 comments · Fixed by #866

Comments

@cmwylie19
Copy link
Collaborator

Environment

If you try to remove an item from the Pepr store that is not there, it will always give a 422 error.

      try {
        // Send the patch to the cluster
        await K8s(PeprStore, { namespace, name: this.#name }).Patch(payload);
      } catch (err) {
        Log.error(err, "Pepr store update failure");

        // On failure to update, re-add the operations to the cache to be retried
        for (const idx of indexes) {
          sendCache[idx] = payload[Number(idx)];
        }
      }

Steps to reproduce

import { Capability, Log, a } from "pepr";

export const HelloPepr = new Capability({
  name: "hello-pepr",
  description: "A simple example capability to show how things work.",
});

const { When, Store } = HelloPepr;

When(a.Pod)
  .IsCreatedOrUpdated()
  .WithLabel("removeItem")
  .Watch(() => {
    Log.info("Pod with timeout label");
    for (let i = 0; i < 20; i++) {
      Store.removeItem(`element-${i}`);
    }
  });


  When(a.Pod)
  .IsCreatedOrUpdated()
  .WithLabel("a")
  .Watch(() => {
    Log.info("Pod with timeout label");
    Store.setItem("a","a")
  });

First, create a pod that gets the store's cache out of whack: k run a --image=nginx -l removeItem=2

Notice the 422 in the logs

Now try to update the store: k run b --image=nginx -l a=a

Notice you still get a 422 bc the cache still contains items that do not exist from the store

Expected result

Actual Result

Visual Proof (screenshots, videos, text, etc)

Severity/Priority

Additional Context

Add any other context or screenshots about the technical debt here.

rjferguson21 added a commit to defenseunicorns/uds-core that referenced this issue Jun 11, 2024
## Description
Workaround for issue where Pepr store fails to update the store
perpetually if a `removeItem` is called on a key that does not exist.

FIxes #463

## Related Issue
Fixes #463
<!-- or -->
Relates to defenseunicorns/pepr#865

## Type of change

- [x] Bug fix (non-breaking change which fixes an issue)
- [ ] New feature (non-breaking change which adds functionality)
- [ ] Other (security config, docs update, etc)

## Checklist before merging

- [ ] Test, docs, adr added or updated as needed
- [ ] [Contributor Guide
Steps](https://github.com/defenseunicorns/uds-template-capability/blob/main/CONTRIBUTING.md)(https://github.com/defenseunicorns/uds-template-capability/blob/main/CONTRIBUTING.md#submitting-a-pull-request)
followed
btlghrants pushed a commit that referenced this issue Jun 11, 2024
## Description

We were seeing behavior where on a `Store.removeItem()`, if the item was
not there the .Patch call returns a 422 but not clear the body of the
patch. This means that every proceeding patch will also fail. This
clears the cache on failure.

## Related Issue

Fixes #865 
<!-- or -->
Relates to #

## Type of change

- [x] Bug fix (non-breaking change which fixes an issue)
- [ ] New feature (non-breaking change which adds functionality)
- [ ] Other (security config, docs update, etc)

## Checklist before merging

- [x] Test, docs, adr added or updated as needed
- [x] [Contributor Guide
Steps](https://docs.pepr.dev/main/contribute/#submitting-a-pull-request)
followed

---------

Signed-off-by: Case Wylie <cmwylie19@defenseunicorns.com>
rjferguson21 added a commit to defenseunicorns/uds-core that referenced this issue Jul 11, 2024
## Description
Workaround for issue where Pepr store fails to update the store
perpetually if a `removeItem` is called on a key that does not exist.

FIxes #463

## Related Issue
Fixes #463
<!-- or -->
Relates to defenseunicorns/pepr#865

## Type of change

- [x] Bug fix (non-breaking change which fixes an issue)
- [ ] New feature (non-breaking change which adds functionality)
- [ ] Other (security config, docs update, etc)

## Checklist before merging

- [ ] Test, docs, adr added or updated as needed
- [ ] [Contributor Guide
Steps](https://github.com/defenseunicorns/uds-template-capability/blob/main/CONTRIBUTING.md)(https://github.com/defenseunicorns/uds-template-capability/blob/main/CONTRIBUTING.md#submitting-a-pull-request)
followed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

1 participant