Skip to content

Commit 735288b

Browse files
authored
fix: check if exemption exists before cleanup (defenseunicorns#468)
## 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 defenseunicorns#463 ## Related Issue Fixes defenseunicorns#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
1 parent 7cf9c4c commit 735288b

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

pepr.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { Log, PeprModule } from "pepr";
22

33
import cfg from "./package.json";
44

5+
import { DataStore } from "pepr/dist/lib/storage";
56
import { istio } from "./src/pepr/istio";
67
import { operator } from "./src/pepr/operator";
78
import { Policy } from "./src/pepr/operator/crd";
@@ -28,11 +29,19 @@ import { prometheus } from "./src/pepr/prometheus";
2829
prometheus,
2930
]);
3031
// Remove legacy policy entries from the pepr store for the 0.5.0 upgrade
31-
if (process.env.PEPR_WATCH_MODE === "true" && cfg.version === "0.5.0") {
32+
if (
33+
process.env.PEPR_MODE === "dev" ||
34+
(process.env.PEPR_WATCH_MODE === "true" && cfg.version === "0.5.0")
35+
) {
3236
Log.debug("Clearing legacy pepr store exemption entries...");
33-
policies.Store.onReady(() => {
34-
for (const p of Object.values(Policy)) {
35-
policies.Store.removeItem(p);
37+
policies.Store.onReady((data: DataStore) => {
38+
const policiesList = Object.values(Policy);
39+
for (const p of Object.keys(data)) {
40+
// if p matches a Policy key, remove it
41+
if (policiesList.includes(p as Policy)) {
42+
Log.debug(`Removing legacy storage of ${p} policy exemptions...`);
43+
policies.Store.removeItem(p);
44+
}
3645
}
3746
});
3847
}

0 commit comments

Comments
 (0)