Skip to main content

☑️ Ensure deployment-like resource is using a valid restart policy

From the Kubernetes docs:

"Only a .spec.template.spec.restartPolicy equal to Always is allowed, which is the default if not specified."

Therefore, restartPolicy values like OnFailure or Never will be invalid and will not be applied as the user expect them to.

Targeted objects by this rule (types of kind): Deployment / Pod / DaemonSet / ReplicaSet / ReplicationController

Complexity: medium (What does this mean?)

Policy as code identifier: WORKLOAD_INCORRECT_RESTARTPOLICY_VALUE_ALWAYS


This rule will fail​

If restartPolicy is set with any value other than Always

spec:
template:
spec:
restartPolicy: Never

Rule output in the CLI​

$ datree test *.yaml

>> File: failExample.yaml
❌ Ensure deployment-like resource is using a valid restart policy [1 occurrence]
💡 Incorrect value for key `restartPolicy` - any other value than `Always` is not supported by this resource

How to fix this failure​

Set restartPolicy to Always or don't include the restartPolicy key at all

spec:
template:
spec:
restartPolicy: Always

Read more​