The store is backed by ETCD in a PeprStore
resource, and updates happen at 5-second intervals when an array of patches is sent to the Kubernetes API Server. The store is intentionally not designed to be transactional
; instead, it is built to be eventually consistent, meaning that the last operation within the interval will be persisted, potentially overwriting other operations. In simpler terms, changes to the data are made without a guarantee that they will occur simultaneously, so caution is needed in managing errors and ensuring consistency.
OnSchedule
is supported by a PeprStore
to safeguard against schedule loss following a pod restart. It is utilized at the top level, distinct from being within a Validate
, Mutate
, or Watch
. Recommended intervals are 30 seconds or longer, and jobs are advised to be idempotent, meaning that if the code is applied or executed multiple times, the outcome should be the same as if it had been executed only once. A major use-case for OnSchedule
is day 2 operations.
Pepr streamlines the process of receiving timely change notifications on resources by employing the Watch
mechanism. It is advisable to opt for Watch
over Mutate
or Validate
when dealing with more extended operations, as Watch
does not face any timeout limitations. Additionally, Watch
proves particularly advantageous for monitoring previously existing resources within a cluster. One compelling scenario for leveraging Watch
is when there is a need to chain API calls together, allowing Watch
operations to be sequentially executed following Mutate
and Validate
actions.
When(a.Pod)
.IsCreated()
.InNamespace("my-app")
.WithName("database")
.Mutate(pod => // .... )
.Validate(pod => // .... )
.Watch(async (pod, phase) => {
Log.info(pod, `Pod was ${phase}.`);
// do consecutive api calls