Skip to content

Latest commit

 

History

47 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Clojure Kubectl

A Clojure wrapper for the kubectl CLI.

cljdoc badge

Clojars Project

Usage

Commands are represented as a map. Valid keys are:

  • :path: the path to the kubectl binary.
  • :command: the kubectl command to execute (get for example).
  • :type: the resource type (:pods for example).
  • :resource: the resource name.
  • :flags: a vector of flags. Flags can be a keyword (:--dry-run) or a vector ([:-n :backend]).

For example, the command kubectl get pods -n backend -o json my-pod can be described as:

{:path "kubectl"
 :command :get
 :type :pods
 :resource :my-pod
 :flags [[:-n :backend]
         [:-o :json]]}

Helper functions

The exoscale.kubectl.helpers namespace contains helper functions to build command maps. For example, the previous command can be generated with:

(require '[exoscale.kubectl.helpers :as h])

(-> (h/kubectl)
    (h/command :get)
    (h/type :pods)
    (h/resource :my-pod)
    (h/namespace :backend)
    h/json)

The namespace also provides some high level functions. For example the previous command can also be generated by:

(h/get-pods {:namespace :backend :resource :my-pod :json? true})

You can even pass a manifest as a string to apply with the apply-stdin helper:

(h/apply-stdin {:stdin "blablabla" :json? true})

Running the command

The command map can be run with exoscale.kubectl/run-command. If the command is successful (i.e the status code is 0), the stdout of the command will be returned. If the command fails, an exception will be thrown. The exception data will contain the executed command, the stdout, stderr, and the status code.

About

Clojure wrapper for the Kubectl CLI

Resources

Stars

7 stars

Watchers

17 watching

Forks

Releases

Packages

Contributors

Languages