M NEWS.org => NEWS.org +8 -0
@@ 10,6 10,14 @@ for Kubernetes.
For further details, see the Kubed manual:
[[https://eshelyaron.com/sweep.html][https://eshelyaron.com/kubed.html]].
+* Version 0.4.1 on in development
+
+** New command and transient menu for scaling deployments
+
+You can now scale Kubernetes deployment with Kubed, directly with
+~kubed-scale-deployment~, from the deployments table buffer, or via
+the new transient menu ~kubed-transient-scale-deployment~.
+
* Version 0.4.0 on 2024-08-23
** ~kubed-list-update~ is now bound to ~g~ in resource table buffers.
M kubed-transient.el => kubed-transient.el +20 -1
@@ 69,7 69,8 @@ Return an RFC3339 string representation of the selected date."
("d" "Diff" kubed-transient-diff)
("P" "Patch" kubed-transient-patch)
("R" "Rollout" kubed-transient-rollout)]
- [("E" "Explain" kubed-explain)
+ [("$" "Scale" kubed-transient-scale-deployment)
+ ("E" "Explain" kubed-explain)
("!" "Command line" kubed-kubectl-command)]])
(defmacro kubed-transient-logs-for-resource (resource &optional plural)
@@ 157,6 158,24 @@ defaults to \"RESOURCEs\"."
(transient-setup 'kubed-transient-logs nil nil
:scope '("logs")))
+;;;###autoload (autoload 'kubed-transient-scale-deployment "kubed-transient" nil t)
+(transient-define-prefix kubed-transient-scale-deployment ()
+ "Scale Kubernetes deployments."
+ ["Kubernetes Scale Deployment\n"
+ ["Action"
+ ("$" "Scale" kubed-scale-deployment)
+ ("!" "Command line" kubed-kubectl-command)]
+ ["Options"
+ ("-n" "Namespace" "--namespace="
+ :prompt "Namespace" :reader kubed-transient-read-namespace)
+ ("-C" "Context" "--context="
+ :prompt "Context" :reader kubed-transient-read-context)
+ ("-r" "Replicas" "--replicas="
+ :prompt "Number of replicas: " :reader transient-read-number-N+)]]
+ (interactive)
+ (transient-setup 'kubed-transient-scale-deployment nil nil
+ :scope '("scale" "deployment")))
+
;;;###autoload (autoload 'kubed-transient-rollout "kubed-transient" nil t)
(transient-define-prefix kubed-transient-rollout ()
"Manage Kubernetes deployments."
M kubed.el => kubed.el +53 -3
@@ 1966,6 1966,49 @@ NAMESPACE too. With a double prefix argument, also prompt for CONTEXT."
:type 'boolean)
;;;###autoload
+(defun kubed-scale-deployment (dep reps &optional context namespace)
+ "Scale deployment DEP in namespace NAMESPACE via CONTEXT to REPS replicas.
+
+Optional argument CONTEXT is the `kubectl' context to use, defaulting to
+the current context; NAMESPACE is the namespace of DEP, defaulting to
+the current namespace.
+
+Interactively, prompt for DEP. With a prefix argument, prompt for
+NAMESPACE too. With a double prefix argument, also prompt for CONTEXT."
+ (interactive
+ (let (reps context namespace)
+ (dolist (arg (kubed-transient-args 'kubed-transient-rollout))
+ (cond
+ ((string-match "--context=\\(.+\\)" arg)
+ (setq context (match-string 1 arg)))
+ ((string-match "--namespace=\\(.+\\)" arg)
+ (setq namespace (match-string 1 arg)))
+ ((string-match "--replicas=\\(.+\\)" arg)
+ (setq reps (string-to-number (match-string 1 arg))))))
+ (unless context
+ (setq context
+ (let ((cxt (kubed-local-context)))
+ (if (equal current-prefix-arg '(16))
+ (kubed-read-context "Context" cxt)
+ cxt))))
+ (unless namespace
+ (setq namespace (kubed--namespace context current-prefix-arg)))
+ (list (kubed-read-deployment "Scale deployment" nil nil context namespace)
+ (or reps (read-number "Number of replicas: ")) context namespace)))
+ (let* ((context (or context (kubed-local-context)))
+ (namespace (or namespace (kubed--namespace context))))
+ (unless (zerop
+ (apply #'call-process
+ kubed-kubectl-program nil nil nil
+ "scale" "deployment" dep
+ "--replicas" (number-to-string reps)
+ (append
+ (when namespace (list "-n" namespace))
+ (when context (list "--context" context)))))
+ (user-error "Failed to scale Kubernetes deployment `%s'" dep))
+ (message "Scaled Kubernetes deployment `%s' to %d replicas." dep reps)))
+
+;;;###autoload
(defun kubed-restart-deployment (dep &optional context namespace)
"Restart Kubernetes deployment DEP in namespace NAMESPACE via CONTEXT.
@@ 2038,11 2081,13 @@ NAMESPACE too. With a double prefix argument, also prompt for CONTEXT."
:right-align t)
( creationtimestamp ".metadata.creationTimestamp" 20))
:prefix (("R" "Restart" kubed-restart-deployment)
- ("W" "Watch" kubed-watch-deployment-status))
+ ("W" "Watch" kubed-watch-deployment-status)
+ ("$" "Scale" kubed-scale-deployment))
:logs t
:suffixes ([("L" "Logs" kubed-transient-logs-for-deployment)
("W" "Watch" kubed-deployments-watch)
- ("R" "Restart" kubed-deployments-restart)])
+ ("R" "Restart" kubed-deployments-restart)
+ ("$" "Scale" kubed-deployments-scale)])
:create
((name images &optional context namespace replicas port command)
"Deploy IMAGES to Kubernetes in deployment with name NAME.
@@ 2102,7 2147,12 @@ optional command to run in the images."
(message "Deployment restarting")
(kubed-list-update t)))
(watch "W" "Watch" (kubed-watch-deployment-status
- deployment kubed-list-context kubed-list-namespace)))
+ deployment kubed-list-context kubed-list-namespace))
+ (scale "$" "Scale" (kubed-scale-deployment
+ deployment (if current-prefix-arg
+ (prefix-numeric-value current-prefix-arg)
+ (read-number "Number of replicas: "))
+ kubed-list-context kubed-list-namespace)))
;;;###autoload (autoload 'kubed-display-replicaset "kubed" nil t)
;;;###autoload (autoload 'kubed-edit-replicaset "kubed" nil t)
M kubed.texi => kubed.texi +30 -0
@@ 176,6 176,7 @@ The following sections describe in detail the various Kubed commands.
* Browse Resources::
* Context and Namespace::
* Transient Menus::
+* Scale Deployment::
@end menu
@node Display Resource
@@ 604,6 605,35 @@ In Kubed resource list buffers, type @kbd{?} to pop up a transient
menu with commands that are specific to the type of resources the
buffer displays. @xref{Browse Resources}.
+@node Scale Deployment
+@section Scale Deployment
+
+You can use Kubed to @dfn{scale} Kubernetes a deployment, which means
+setting the size of the deployment in terms of the number of replicas
+it governs.
+
+@deffn Command kubed-scale-deployment
+Scale a Kubernetes deployment.
+@end deffn
+
+@code{kubed-scale-deployment} is bound to @kbd{$} in the
+@code{kubed-deployment-prefix-map}, so if you have
+@code{kubed-prefix-map} bound to @kbd{C-c k} then you can invoke it
+with @kbd{C-c k d $}. @xref{Definition of kubed-prefix-map}. This
+command prompts you for a deployment and then lets you select a new
+number of replicas for that deployment. By default you are prompted
+for deployment in the local context and namespace (@pxref{Context and
+Namespace}); with a prefix argument, you can specify a different
+namespace; with a double prefix argument (@kbd{C-u C-u}), you can
+specify a different context too.
+
+In the deployments list buffer, you can scale the deployment at point
+by simply typing @kbd{$}. @xref{Browse Resources}.
+
+Lastly, you can scale deployments using the transient menu
+@code{kubed-transient-scale-deployment}, which is available from the
+main Kubed transient by pressing @kbd{$}. @xref{Transient Menus}.
+
@node Extending Kubed
@chapter Extending Kubed