Skip to content

Commit

Permalink
Allow optional namespaces value when calling kubectl apply.
Browse files Browse the repository at this point in the history
  • Loading branch information
olymk2 committed Oct 9, 2019
1 parent c33cbf1 commit 7e2d0dd
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions src/lambdakube/core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -358,14 +358,20 @@
(map #(yaml/generate-string % :dumper-options {:flow-style :block :scalar-style :plain}))
(str/join "---\n")))

(defn kube-apply [content file]
(when-not (and (.exists file)
(= (slurp file) content))
(spit file content)
(let [res (sh/sh "kubectl" "apply" "-f" (str file))]
(when-not (= (:exit res) 0)
(.delete file)
(throw (Exception. (:err res)))))))

(defn kube-apply
([content file]
(kube-apply content file nil))
([content file namespace]
(let [namespace-arg (if (nil? namespace) nil (str "--namespace=" namespace))]
(when-not (and (.exists file)
(= (slurp file) content))
(spit file content)
(let [res (apply sh/sh (remove nil? ["kubectl" "apply" namespace-arg "-f" (str file)]))]
(when-not (= (:exit res) 0)
(.delete file)
(throw (Exception. (:err res)))))))))


(defn port
([cont portname podport]
Expand Down

0 comments on commit 7e2d0dd

Please sign in to comment.