From ea2c830f062d6fe07f70c4d5b4cf6eeb21956c72 Mon Sep 17 00:00:00 2001 From: Kavin <62742678+Kavinraja-G@users.noreply.github.com> Date: Sun, 24 Dec 2023 20:47:56 +0530 Subject: [PATCH 1/2] Added exec pod ttl flag --- pkg/cmd/nodes/exec.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pkg/cmd/nodes/exec.go b/pkg/cmd/nodes/exec.go index 52a3f43..aac797f 100644 --- a/pkg/cmd/nodes/exec.go +++ b/pkg/cmd/nodes/exec.go @@ -26,6 +26,7 @@ import ( var ( nodeshellPodNamespace string nodeshellPodImage string + nodeshellPodTTL string nodeshellPodNamePrefix = "nodeshell-" podSCPrivileged = true podTerminationGracePeriodSeconds = int64(0) @@ -63,6 +64,7 @@ func NewCmdNodeExec() *cobra.Command { // additional local flags cmd.Flags().StringVarP(&nodeshellPodNamespace, "namespace", "n", "kube-system", "Namespace where nsenter pod to be created") cmd.Flags().StringVarP(&nodeshellPodImage, "image", "i", "docker.io/alpine:3.18", "Image used by nsenter pod") + cmd.Flags().StringVarP(&nodeshellPodTTL, "ttl", "t", "3600", "Time to live (seconds) for the exec container. Defaults to 3600s") return cmd } @@ -103,7 +105,7 @@ func createExecPodInTargetedNode(nodeName string) error { Name: "nodeshell", Image: nodeshellPodImage, Command: []string{"nsenter"}, - Args: []string{"-t", "1", "-m", "-u", "-i", "-n", "sleep", "14000"}, + Args: []string{"-t", "1", "-m", "-u", "-i", "-n", "sleep", nodeshellPodTTL}, SecurityContext: &corev1.SecurityContext{ Privileged: &podSCPrivileged, }, From 7747307500a1d01a38411a5e2f3d20a2ff015024 Mon Sep 17 00:00:00 2001 From: Kavin <62742678+Kavinraja-G@users.noreply.github.com> Date: Sun, 24 Dec 2023 21:02:38 +0530 Subject: [PATCH 2/2] Refactor and update cobra docs --- README.md | 1 - docs/nodegizmo.md | 2 +- docs/nodegizmo_completion.md | 2 +- docs/nodegizmo_completion_bash.md | 2 +- docs/nodegizmo_completion_fish.md | 2 +- docs/nodegizmo_completion_powershell.md | 2 +- docs/nodegizmo_completion_zsh.md | 2 +- docs/nodegizmo_docs.md | 2 +- docs/nodegizmo_node.md | 2 +- docs/nodegizmo_node_capacity.md | 2 +- docs/nodegizmo_node_exec.md | 3 ++- docs/nodegizmo_nodepool.md | 2 +- pkg/cmd/nodes/exec.go | 13 ++++--------- 13 files changed, 16 insertions(+), 21 deletions(-) diff --git a/README.md b/README.md index a6de6f0..ccd7854 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,6 @@ # node-gizmo A CLI utility for your Kubernetes nodes. -[![Build](https://github.com/Kavinraja-G/node-gizmo/actions/workflows/pr.yaml/badge.svg)](https://github.com/Kavinraja-G/node-gizmo/actions/workflows/pr.yaml) [![Release](https://github.com/Kavinraja-G/node-gizmo/actions/workflows/release.yml/badge.svg)](https://github.com/Kavinraja-G/node-gizmo/actions/workflows/release.yml) [![Go Coverage](https://github.com/Kavinraja-G/node-gizmo/wiki/coverage.svg)](https://raw.githack.com/wiki/Kavinraja-G/node-gizmo/coverage.html) diff --git a/docs/nodegizmo.md b/docs/nodegizmo.md index e6d66aa..aa057c8 100644 --- a/docs/nodegizmo.md +++ b/docs/nodegizmo.md @@ -19,4 +19,4 @@ nodegizmo [flags] * [nodegizmo node](nodegizmo_node.md) - Displays generic node related information in the cluster * [nodegizmo nodepool](nodegizmo_nodepool.md) - Displays detailed information about Nodepool/Nodegroup -###### Auto generated by spf13/cobra on 21-Oct-2023 +###### Auto generated by spf13/cobra on 24-Dec-2023 diff --git a/docs/nodegizmo_completion.md b/docs/nodegizmo_completion.md index 241b74a..22f0c55 100644 --- a/docs/nodegizmo_completion.md +++ b/docs/nodegizmo_completion.md @@ -22,4 +22,4 @@ See each sub-command's help for details on how to use the generated script. * [nodegizmo completion powershell](nodegizmo_completion_powershell.md) - Generate the autocompletion script for powershell * [nodegizmo completion zsh](nodegizmo_completion_zsh.md) - Generate the autocompletion script for zsh -###### Auto generated by spf13/cobra on 21-Oct-2023 +###### Auto generated by spf13/cobra on 24-Dec-2023 diff --git a/docs/nodegizmo_completion_bash.md b/docs/nodegizmo_completion_bash.md index 4b71641..00e4ab7 100644 --- a/docs/nodegizmo_completion_bash.md +++ b/docs/nodegizmo_completion_bash.md @@ -41,4 +41,4 @@ nodegizmo completion bash * [nodegizmo completion](nodegizmo_completion.md) - Generate the autocompletion script for the specified shell -###### Auto generated by spf13/cobra on 21-Oct-2023 +###### Auto generated by spf13/cobra on 24-Dec-2023 diff --git a/docs/nodegizmo_completion_fish.md b/docs/nodegizmo_completion_fish.md index 371d739..a9553ee 100644 --- a/docs/nodegizmo_completion_fish.md +++ b/docs/nodegizmo_completion_fish.md @@ -32,4 +32,4 @@ nodegizmo completion fish [flags] * [nodegizmo completion](nodegizmo_completion.md) - Generate the autocompletion script for the specified shell -###### Auto generated by spf13/cobra on 21-Oct-2023 +###### Auto generated by spf13/cobra on 24-Dec-2023 diff --git a/docs/nodegizmo_completion_powershell.md b/docs/nodegizmo_completion_powershell.md index 6d9572c..406b1cd 100644 --- a/docs/nodegizmo_completion_powershell.md +++ b/docs/nodegizmo_completion_powershell.md @@ -29,4 +29,4 @@ nodegizmo completion powershell [flags] * [nodegizmo completion](nodegizmo_completion.md) - Generate the autocompletion script for the specified shell -###### Auto generated by spf13/cobra on 21-Oct-2023 +###### Auto generated by spf13/cobra on 24-Dec-2023 diff --git a/docs/nodegizmo_completion_zsh.md b/docs/nodegizmo_completion_zsh.md index 0597b53..4f26e75 100644 --- a/docs/nodegizmo_completion_zsh.md +++ b/docs/nodegizmo_completion_zsh.md @@ -43,4 +43,4 @@ nodegizmo completion zsh [flags] * [nodegizmo completion](nodegizmo_completion.md) - Generate the autocompletion script for the specified shell -###### Auto generated by spf13/cobra on 21-Oct-2023 +###### Auto generated by spf13/cobra on 24-Dec-2023 diff --git a/docs/nodegizmo_docs.md b/docs/nodegizmo_docs.md index 707d3eb..8de908a 100644 --- a/docs/nodegizmo_docs.md +++ b/docs/nodegizmo_docs.md @@ -16,4 +16,4 @@ nodegizmo docs [flags] * [nodegizmo](nodegizmo.md) - Nodegizmo - A CLI utility for your Kubernetes nodes -###### Auto generated by spf13/cobra on 21-Oct-2023 +###### Auto generated by spf13/cobra on 24-Dec-2023 diff --git a/docs/nodegizmo_node.md b/docs/nodegizmo_node.md index ca05e2e..c3c7c51 100644 --- a/docs/nodegizmo_node.md +++ b/docs/nodegizmo_node.md @@ -22,4 +22,4 @@ nodegizmo node [flags] * [nodegizmo node capacity](nodegizmo_node_capacity.md) - Displays Node capacity related information * [nodegizmo node exec](nodegizmo_node_exec.md) - Spawns a 'nsenter' pod to exec into the provided node -###### Auto generated by spf13/cobra on 21-Oct-2023 +###### Auto generated by spf13/cobra on 24-Dec-2023 diff --git a/docs/nodegizmo_node_capacity.md b/docs/nodegizmo_node_capacity.md index 665e54b..2cefb90 100644 --- a/docs/nodegizmo_node_capacity.md +++ b/docs/nodegizmo_node_capacity.md @@ -22,4 +22,4 @@ nodegizmo node capacity [flags] * [nodegizmo node](nodegizmo_node.md) - Displays generic node related information in the cluster -###### Auto generated by spf13/cobra on 21-Oct-2023 +###### Auto generated by spf13/cobra on 24-Dec-2023 diff --git a/docs/nodegizmo_node_exec.md b/docs/nodegizmo_node_exec.md index 00c7323..98324d1 100644 --- a/docs/nodegizmo_node_exec.md +++ b/docs/nodegizmo_node_exec.md @@ -12,6 +12,7 @@ nodegizmo node exec nodeName [flags] -h, --help help for exec -i, --image string Image used by nsenter pod (default "docker.io/alpine:3.18") -n, --namespace string Namespace where nsenter pod to be created (default "kube-system") + -t, --ttl string Time to live (seconds) for the exec container. Defaults to 3600s (default "3600") ``` ### Options inherited from parent commands @@ -24,4 +25,4 @@ nodegizmo node exec nodeName [flags] * [nodegizmo node](nodegizmo_node.md) - Displays generic node related information in the cluster -###### Auto generated by spf13/cobra on 21-Oct-2023 +###### Auto generated by spf13/cobra on 24-Dec-2023 diff --git a/docs/nodegizmo_nodepool.md b/docs/nodegizmo_nodepool.md index 294f1a2..2b32dce 100644 --- a/docs/nodegizmo_nodepool.md +++ b/docs/nodegizmo_nodepool.md @@ -17,4 +17,4 @@ nodegizmo nodepool [flags] * [nodegizmo](nodegizmo.md) - Nodegizmo - A CLI utility for your Kubernetes nodes -###### Auto generated by spf13/cobra on 21-Oct-2023 +###### Auto generated by spf13/cobra on 24-Dec-2023 diff --git a/pkg/cmd/nodes/exec.go b/pkg/cmd/nodes/exec.go index aac797f..90714fe 100644 --- a/pkg/cmd/nodes/exec.go +++ b/pkg/cmd/nodes/exec.go @@ -8,19 +8,15 @@ import ( "os" "time" - "github.com/docker/cli/cli/streams" - "github.com/Kavinraja-G/node-gizmo/utils" - + "github.com/docker/cli/cli/streams" + "github.com/spf13/cobra" + corev1 "k8s.io/api/core/v1" k8errors "k8s.io/apimachinery/pkg/api/errors" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/util/wait" - "k8s.io/client-go/kubernetes/scheme" "k8s.io/client-go/tools/remotecommand" - - "github.com/spf13/cobra" - corev1 "k8s.io/api/core/v1" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) var ( @@ -188,7 +184,6 @@ func execIntoNode(cmd *cobra.Command, nodeName string) error { req.VersionedParams(opts, scheme.ParameterCodec) - //TODO: Check if there is any way we can fetch the config from the clientset itself k8sConfig, err := utils.GetKubeConfig() if err != nil { log.Fatalf("Error while getting Kubeconfig: %v", err)