Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added --ttl flag for exec containers #27

Merged
merged 2 commits into from
Dec 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -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)

Expand Down
2 changes: 1 addition & 1 deletion docs/nodegizmo.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion docs/nodegizmo_completion.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion docs/nodegizmo_completion_bash.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion docs/nodegizmo_completion_fish.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion docs/nodegizmo_completion_powershell.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion docs/nodegizmo_completion_zsh.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion docs/nodegizmo_docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion docs/nodegizmo_node.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion docs/nodegizmo_node_capacity.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 2 additions & 1 deletion docs/nodegizmo_node_exec.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
2 changes: 1 addition & 1 deletion docs/nodegizmo_nodepool.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
17 changes: 7 additions & 10 deletions pkg/cmd/nodes/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,21 @@ 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 (
nodeshellPodNamespace string
nodeshellPodImage string
nodeshellPodTTL string
nodeshellPodNamePrefix = "nodeshell-"
podSCPrivileged = true
podTerminationGracePeriodSeconds = int64(0)
Expand Down Expand Up @@ -63,6 +60,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
}
Expand Down Expand Up @@ -103,7 +101,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,
},
Expand Down Expand Up @@ -186,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)
Expand Down
Loading