(transient-setup 'kubed-transient-run nil nil
:scope '("run")))
+;;;###autoload
+(transient-define-prefix kubed-transient-apply ()
+ "Apply configuration to Kubernetes resource."
+ ["Options"
+ ("-f" "Definition file" "--filename="
+ :reader kubed-transient-read-resource-definition-file-name)]
+ ["Actions"
+ ("*" "apply" kubed-apply)
+ ("!" "Command line" kubed-kubectl-command)]
+ (interactive)
+ (transient-setup 'kubed-transient-apply nil nil
+ :scope '("apply")))
+
;;;###autoload
(transient-define-prefix kubed-transient-create ()
"Create Kubernetes resource."
:reader kubed-transient-read-resource-definition-file-name)]
["Kinds"
("d" "deployment" kubed-transient-create-deployment)
- ("n" "namespace" kubed-create-namespace)]
+ ("n" "namespace" kubed-create-namespace)
+ ("c" "cronjob" kubed-transient-create-cronjob)]
["Actions"
- ("c" "Create" kubed-create)
+ ("+" "Create" kubed-create)
("!" "Command line" kubed-kubectl-command)]
(interactive)
(transient-setup 'kubed-transient-create nil nil
:scope '("create")))
;;;###autoload
-(transient-define-prefix kubed-transient-apply ()
- "Apply configuration to Kubernetes resource."
+(transient-define-prefix kubed-transient-create-cronjob ()
+ "Create Kubernetes cronjob."
["Options"
- ("-f" "Definition file" "--filename="
- :reader kubed-transient-read-resource-definition-file-name)]
+ ("-n" "Namespace" "--namespace="
+ :prompt "Namespace" :reader kubed-transient-read-namespace)
+ ("-I" "Image" "--image="
+ :prompt "Image to run: ")
+ ("-S" "Schedule" "--schedule="
+ :prompt "Cron schedule: ")
+ ("--" "Command" "-- ="
+ :prompt "Command: ")]
["Actions"
- ("*" "apply" kubed-apply)
+ ("+" "Create" kubed-create-cronjob)
("!" "Command line" kubed-kubectl-command)]
(interactive)
- (transient-setup 'kubed-transient-apply nil nil
- :scope '("apply")))
+ (transient-setup 'kubed-transient-create-cronjob nil nil
+ :scope '("create" "cronjob")))
;;;###autoload
(transient-define-prefix kubed-transient-create-deployment ()
:prompt "Namespace" :reader kubed-transient-read-namespace)
("-r" "Replicas" "--replicas="
:prompt "Number of replicas: " :reader transient-read-number-N+)
- ("-i" "Image" "--image="
+ ("-I" "Image" "--image="
:prompt "Images to deploy: "
:multi-value repeat)
("-p" "Port" "--port="
("--" "Command" "-- ="
:prompt "Command: ")]
["Actions"
- ("c" "Create" kubed-create)
+ ("+" "Create" kubed-create-deployment)
("!" "Command line" kubed-kubectl-command)]
(interactive)
(transient-setup 'kubed-transient-create-deployment nil nil
(suspend ".spec.suspend" 20)
(lastschedule ".status.lastScheduleTime" 20)
(lastsuccess ".status.lastSuccessfulTime" 20)
- (activejob ".status.active[0].name" 36)))
+ (activejob ".status.active[0].name" 36))
+ :create
+ ((name image schedule &optional namespace command)
+ "Schedule IMAGE to run in a cronjon with name NAME according to SCHEDULE.
+
+Optional argument NAMESPACE is the namespace to use for the deployment,
+defaulting to the current namespace. COMMAND is a list of strings that
+represent a program followed by its arguments, if it non-nil then it
+overrides the default command IMAGE runs."
+ (interactive
+ (let ((name (read-string "Create cronjob with name: "))
+ (image nil)
+ (schedule nil)
+ (command nil)
+ (namespace nil))
+ (dolist (arg (kubed-transient-args 'kubed-transient-create-cronjob))
+ (cond
+ ((string-match "--image=\\(.+\\)" arg)
+ (setq image (match-string 1 arg)))
+ ((string-match "--schedule=\\(.+\\)" arg)
+ (setq schedule (match-string 1 arg)))
+ ((string-match "--namespace=\\(.+\\)" arg)
+ (setq namespace (match-string 1 arg)))
+ ((string-match "-- =\\(.+\\)" arg)
+ (setq command (split-string-and-unquote (match-string 1 arg))))))
+ (unless image
+ (setq image (read-string "Image to run: " nil 'kubed-container-images-history)))
+ (unless schedule
+ (setq schedule (read-string "Cron schedule: " "* * * * *")))
+ (list name image schedule namespace command)))
+ (unless (zerop
+ (apply #'call-process
+ kubed-kubectl-program nil nil nil
+ "create" "cronjob" name
+ "--image" image "--schedule" schedule
+ (append
+ (when namespace (list "--namespace" namespace))
+ (when command (cons "--" command)))))
+ (user-error "Failed to create Kubernetes cronjob `%s'" name))
+ (message "Created Kubernetes cronjob `%s'." name)
+ (kubed-update-cronjobs)))
;; TODO: Events may be numerous. Need to only get a few.
;; ;;;###autoload (autoload 'kubed-list-events "kubed" nil t)