((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)
(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