This test is to ensure you can migrate test keys from one pepr version to the next and that the new version can read the old keys. It should work with multple capabilities like UDS Core.
Create a module using the existing Pepr Version with pepr
and one
capabilities.
pepr:
In package.json, add the following to the pepr
section:
"pepr": {
"uuid": "static-test",
}
import {
Capability,
K8s,
Log,
a,
kind,
} from "pepr";
export const HelloPepr = new Capability({
name: "pepr",
description: "Make sure store migration works",
});
const { When, OnSchedule,Store } = HelloPepr;
OnSchedule({
name: "hello-interval",
every: 11,
unit: "seconds",
run: async () => {
Log.info("Wait 10 seconds and create/update a ConfigMap");
try {
await K8s(kind.ConfigMap).Apply({
metadata: {
name: "last-updated",
namespace: "default",
},
data: {
count: `${new Date()}`,
},
});
} catch (error) {
Log.error(error, "Failed to apply ConfigMap using server-side apply.");
}
},
});
OnSchedule({
name:"hi",
unit: "seconds",
every: 11,
run: () => Log.info("hi", `${Date.now()}`)
})
When(a.Pod)
.IsCreatedOrUpdated()
.Mutate(po => Store.setItem("a", po.Raw.metadata.namespace));
one:
import {
Capability,
K8s,
Log,
a,
kind,
} from "pepr";
export const One = new Capability({
name: "one",
description: "Make sure store migration works",
});
const { When, OnSchedule,Store } = One;
OnSchedule({
name:"hi",
unit: "seconds",
every: 11,
run: () => Log.info("one", `${Date.now()}`)
})
Run npx pepr build
to create the new version of Pepr from core with pepr
and one
capabilities.
pepr:
import {
Capability,
a,
} from "pepr";
export const HelloPepr = new Capability({
name: "pepr",
description: "Make sure store migration works",
});
const { When, OnSchedule,Store } = HelloPepr;
When(a.ConfigMap)
.IsCreatedOrUpdated()
.WithName("a")
.Mutate(() => {
let a = Store.getItem("a")
console.log("Value of a ",a)
});
one:
import {
Capability,
Log,
} from "pepr";
export const One = new Capability({
name: "one",
description: "Make sure store migration works",
});
const { When, OnSchedule,Store } = One;
OnSchedule({
name:"hi",
unit: "seconds",
every: 11,
run: () => Log.info("one", `${Date.now()}`)
})
# start fresh if this is not the first time
k delete cm,po --all --force
# step 1: npx pepr dev in MIG module, the one old
# mig> npx pepr dev --confirm
# Create a pod to trigger the store
k run a --image=nginx
# wait for schedules to start ~11 seconds later and run migration script
npx ts-node migrate.ts pepr one
# stop running mig and run pepr-stic-test
# mig> ^CReceived SIGINT, removing webhooks
# step 2: npx pepr dev in pepr-static-test module, the new one
# pepr-static-test> npx pepr dev --confirm
# SAVE YOUR OLD MODULES IF THIS IS PROD
# apply the migrated store after the store starts up to configure
k apply -f pepr-static-test-schedule.json;k apply -f pepr-static-test-store.json
# output
# peprstore.pepr.dev/pepr-static-test-schedule configured
# peprstore.pepr.dev/pepr-static-test-store configured
k create cm a --from-literal=a=a
# assert you get default, probably use the debugger
#assert hi is still getting printed out