healthy.rego 1.1 KB

123456789101112131415161718192021222324252627282930313233343536
  1. package node.healthy
  2. import future.keywords
  3. POLICY_ID := sprintf("healthy_%s", [input.metadata.name])
  4. POLICY_VERSION := "v0.0.1"
  5. POLICY_SEVERITY := "critical"
  6. POLICY_TITLE := sprintf("The node %s should be healthy", [input.metadata.name])
  7. POLICY_SUCCESS_MESSAGE := sprintf("Success: this node is healthy or is younger than 10 minutes", [])
  8. # check if one of the node's conditions states that the kubelet is ready
  9. allow if {
  10. some condition in input.status.conditions
  11. condition.reason == "KubeletReady"
  12. condition.status = "True"
  13. }
  14. # if the node was started in the last 10 minutes, we do not track it - it may
  15. # be unhealthy while initializing the CNI
  16. allow if {
  17. rfc3339_is_younger_than_10_minutes(input.metadata.creationTimestamp)
  18. }
  19. FAILURE_MESSAGE contains msg if {
  20. not allow
  21. msg := sprintf("Failed: the node %s is not healthy", [input.metadata.name])
  22. }
  23. rfc3339_is_younger_than_10_minutes(a) if {
  24. # add 10 minutes (in nanoseconds) to the creation timestamp and see if it's greater than current time
  25. time.parse_rfc3339_ns(a) + ((((10 * 60) * 1000) * 1000) * 1000) > time.now_ns()
  26. }