Pepr SDK
2 minute read
To use, import the sdk
from the pepr
package:
import { sdk } from "pepr";
containers
Returns list of all containers in a pod. Accepts the following parameters:
- @param peprValidationRequest The request/pod to get the containers from
- @param containerType The type of container to get
Usage:
Get all containers
const { containers } = sdk;
let result = containers(peprValidationRequest)
Get only the standard containers
const { containers } = sdk;
let result = containers(peprValidationRequest, "containers")
Get only the init containers
const { containers } = sdk;
let result = containers(peprValidationRequest, "initContainers")
Get only the ephemeral containers
const { containers } = sdk;
let result = containers(peprValidationRequest, "ephemeralContainers")
getOwnerRefFrom
Returns the owner reference for a Kubernetes resource. Accepts the following parameters:
- @param kubernetesResource: GenericKind The Kubernetes resource to get the owner reference for
Usage:
const { getOwnerRefFrom } = sdk;
const ownerRef = getOwnerRefFrom(kubernetesResource);
writeEvent
Write a K8s event for a CRD. Accepts the following parameters:
- @param kubernetesResource: GenericKind The Kubernetes resource to write the event for
- @param event The event to write, should contain a human-readable message for the event
- @param eventType The type of event to write, for example “Warning”
- @param eventReason The reason for the event, for example “ReconciliationFailed”
- @param reportingComponent The component that is reporting the event, for example “uds.dev/operator”
- @param reportingInstance The instance of the component that is reporting the event, for example process.env.HOSTNAME
Usage:
const { writeEvent } = sdk;
writeEvent(
kubernetesResource,
event,
"Warning",
"ReconciliationFailed",
"uds.dev/operator",
process.env.HOSTNAME,
);
sanitizeResourceName
Returns a sanitized resource name to make the given name a valid Kubernetes resource name. Accepts the following parameter:
- @param resourceName The name of the resource to sanitize
Usage:
const { sanitizeResourceName } = sdk;
const sanitizedResourceName = sanitizeResourceName(resourceName)
See Also
Looking for information on the Pepr mutate helpers? See Mutate Helpers for information on those.