From: Eshel Yaron Date: Wed, 24 Jul 2024 05:33:36 +0000 (+0200) Subject: Specialize 'kubed-create-deployment' X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=f2a13e24269b4bf5d06b98726a9709fb4742a00d;p=emacs.git Specialize 'kubed-create-deployment' --- diff --git a/lisp/net/kubed.el b/lisp/net/kubed.el index 7cce3c0106a..b3ac36e4bbd 100644 --- a/lisp/net/kubed.el +++ b/lisp/net/kubed.el @@ -887,7 +887,52 @@ Optional argument DEFAULT is the minibuffer default argument." resource) ((reps ".status.replicas" 4 (lambda (l r) (< (string-to-number l) (string-to-number r))) :right-align t) - (creationtimestamp ".metadata.creationTimestamp" 20))) + (creationtimestamp ".metadata.creationTimestamp" 20)) + :create + ((name images &optional namespace replicas port command) + "Deploy IMAGES to Kubernetes in deployment with name NAME. + +Optional argument NAMESPACE is the namespace to use for the deployment, +defaulting to the current namespace, REPLICAS in the number of replicas +to create for each image, PORT is the port to expose, and COMMAND is an +optional command to run in the images." + (interactive + (let ((name (read-string "Create deployment with name: ")) + (images nil) + (replicas (prefix-numeric-value current-prefix-arg)) + (port nil) + (command nil) + (namespace nil)) + (dolist (arg (when (and (fboundp 'transient-args) + (fboundp 'kubed-transient-create-deployment)) + (transient-args 'kubed-transient-create-deployment))) + (cond + ((string-match "--replicas=\\(.+\\)" arg) + (setq replicas (string-to-number (match-string 1 arg)))) + ((string-match "--image=\\(.+\\)" arg) + (push (match-string 1 arg) images)) + ((string-match "--port=\\(.+\\)" arg) + (setq port (string-to-number (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 images + (setq images (kubed-read-container-images "Images to deploy"))) + (list name images namespace replicas port command))) + (unless (zerop + (apply #'call-process + kubed-kubectl-executable nil nil nil + "create" "deployment" name + (append + (mapcar (lambda (image) (concat "--image=" image)) images) + (when namespace (list (concat "--namespace=" namespace))) + (when replicas (list (format "--replicas=%d" replicas))) + (when port (list (format "--port=%d" port))) + (when command (cons "--" command))))) + (user-error "Failed to create Kubernetes deployment `%s'" name)) + (message "Created Kubernetes deployment `%s'." name) + (kubed-update-deployments))) ;;;###autoload (autoload 'kubed-display-replicaset "kubed" nil t) ;;;###autoload (autoload 'kubed-edit-replicaset "kubed" nil t) @@ -1165,5 +1210,16 @@ one port-forwarding process, stop that process without prompting." (error "No port-forwarding for %s" descriptor)) (message "Stopped port-forwarding for %s" descriptor)) +(defvar kubed-container-images-history nil + "Minibuffer history for `kubed-read-container-images'.") + +(defun kubed-read-container-images (prompt &optional default) + "Prompt with PROMPT for names of container images. + +Optional argument DEFAULT is the minibuffer default argument." + (completing-read-multiple + (format-prompt prompt default) nil nil nil nil + 'kubed-container-images-history default)) + (provide 'kubed) ;;; kubed.el ends here