Skip to main content

warn() Function

The warn() function will print warnings to the client. Warnings from webhooks are a feature introduced in Kubernetes version v1.19, so for clusters below this version, the function has no effect. You can call this function multiple times to print multiple warnings.


kind: JsPolicy
name: ""
operations: ["CREATE", "UPDATE"]
resources: ["configmaps"]
javascript: |
// warn() will print a warning to the client. If warn() is called multiple times, it will print multiple warnings
// Warnings are a feature of kubernetes since v1.19 and could look like this:
// kubectl create -f my-configmap.yaml
// Warning: []: Hello This Is A Warning for ConfigMap default/my-configmap
// Warning: []: Hello This Is Another Warning
// configmap "my-configmap" created
warn(`Hello This Is A Warning for ConfigMap ${request.object.metadata.namespace}/${}`);
// print another warning to the client
warn("Hello This Is Another Warning");