-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.clj
54 lines (40 loc) · 1.1 KB
/
utils.clj
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
(ns clj-k8s.utils
(:require [clojure.string :as str]))
;;; =====================================
;;; Utils
;;; ====================================
(defn find-named [x xs]
(some #(when (= (:name %) x) %) xs))
(defmacro not-found->nil
[& body]
`(try
~@body
(catch Throwable t#
(if (= 404 (-> t# ex-data :status))
nil
(throw t#)))))
(defn ->label-selector
[labels]
(if (string? labels)
labels
(->> labels
(map (fn [[k v]] (format "%s=%s" (name k) v)))
(str/join ","))))
;;; Kubernetes Related Predicates
(defn- current-condition
[{:keys [conditions]}]
(->> conditions
(filter #(= (:status %) "True"))
first))
(defn running?
"Returns true if the job is still running"
[{:keys [status]}]
(boolean (and status (nil? (current-condition status)))))
(defn succeeded?
"Returns true if the job was successful"
[{:keys [status]}]
(= (:type (current-condition status)) "Complete"))
(defn failed?
"Returns true if the job failed"
[{:keys [status]}]
(or (nil? status) (= (:type (current-condition status)) "Failed")))