porter_run_taints.rego 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. package node.porter_run_taints
  2. import future.keywords
  3. POLICY_ID := sprintf("porter_run_taints_%s", [input.metadata.name])
  4. POLICY_VERSION := "v0.0.1"
  5. POLICY_SEVERITY := "high"
  6. POLICY_TITLE := sprintf("The only taints on node %s should be porter.run/workload-kind=system", [input.metadata.name])
  7. POLICY_SUCCESS_MESSAGE := sprintf("Success: this node either has no taints, or has a taint with key porter.run/workload-kind", [])
  8. # if there are no taints, allow the condition
  9. allow if {
  10. not input.spec.taints[0]
  11. }
  12. # if there is a taint with the key porter.run/workload-kind, allow the condition
  13. allow if {
  14. input.spec.taints[0].key == "porter.run/workload-kind"
  15. input.spec.taints[0].effect == "NoSchedule"
  16. }
  17. FAILURE_MESSAGE contains msg1 if {
  18. not allow
  19. msg1 := sprintf("Failed: the only permitted taints must contain the key porter.run/workload-kind", [])
  20. }
  21. FAILURE_MESSAGE contains msg2 if {
  22. not allow
  23. not input.spec.taints[0].key == "porter.run/workload-kind"
  24. msg2 := sprintf("Taint has key %s", [input.spec.taints[0].key])
  25. }
  26. FAILURE_MESSAGE contains msg3 if {
  27. not allow
  28. not input.spec.taints[0].effect == "NoSchedule"
  29. msg3 := sprintf("Taint has effect %s", [input.spec.taints[0].effect])
  30. }