diff --git a/go.mod b/go.mod index ddb5a0a..99676e4 100644 --- a/go.mod +++ b/go.mod @@ -2,7 +2,6 @@ module github.com/clbx/kubectl-browse-pvc go 1.22.0 - require ( github.com/briandowns/spinner v1.23.0 github.com/spf13/cobra v1.7.0 @@ -18,7 +17,7 @@ require ( github.com/davecgh/go-spew v1.1.1 // indirect github.com/emicklei/go-restful/v3 v3.11.0 // indirect github.com/evanphx/json-patch v4.12.0+incompatible // indirect - github.com/fatih/color v1.15.0 // indirect + github.com/fatih/color v1.7.0 // indirect github.com/go-errors/errors v1.4.2 // indirect github.com/go-logr/logr v1.4.1 // indirect github.com/go-openapi/jsonpointer v0.19.6 // indirect @@ -40,7 +39,7 @@ require ( github.com/liggitt/tabwriter v0.0.0-20181228230101-89fcab3d43de // indirect github.com/mailru/easyjson v0.7.7 // indirect github.com/mattn/go-colorable v0.1.13 // indirect - github.com/mattn/go-isatty v0.0.17 // indirect + github.com/mattn/go-isatty v0.0.16 // indirect github.com/moby/spdystream v0.2.0 // indirect github.com/moby/term v0.0.0-20221205130635-1aeaba878587 // indirect github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect diff --git a/go.sum b/go.sum index c0dedd3..71edb13 100644 --- a/go.sum +++ b/go.sum @@ -24,8 +24,8 @@ github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.m github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c= github.com/evanphx/json-patch v4.12.0+incompatible h1:4onqiflcdA9EOZ4RxV643DvftH5pOlLGNtQ5lPWQu84= github.com/evanphx/json-patch v4.12.0+incompatible/go.mod h1:50XU6AFN0ol/bzJsmQLiYLvXMP4fmwYFNcr97nuDLSk= -github.com/fatih/color v1.15.0 h1:kOqh6YHBtK8aywxGerMG2Eq3H6Qgoqeo13Bk2Mv/nBs= -github.com/fatih/color v1.15.0/go.mod h1:0h5ZqXfHYED7Bhv2ZJamyIOUej9KtShiJESRwBDUSsw= +github.com/fatih/color v1.7.0 h1:DkWD4oS2D8LGGgTQ6IvwJJXSL5Vp2ffcQg58nFV38Ys= +github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4= github.com/go-errors/errors v1.4.2 h1:J6MZopCL4uSllY1OfXM374weqZFFItUbrImctkmUxIA= github.com/go-errors/errors v1.4.2/go.mod h1:sIVyrIiJhuEF+Pj9Ebtd6P/rEYROXFi3BopGUQ5a5Og= github.com/go-logr/logr v1.4.1 h1:pKouT5E8xu9zeFC39JXRDukb6JFQPXM5p5I91188VAQ= @@ -103,9 +103,8 @@ github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0 github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc= github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA= github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg= +github.com/mattn/go-isatty v0.0.16 h1:bq3VjFmv/sOjHtdEhmkEV4x1AJtvUvOJ2PFAZ5+peKQ= github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= -github.com/mattn/go-isatty v0.0.17 h1:BTarxUcIeDqL27Mc+vyvdWYSL28zpIhv3RoTdsLMPng= -github.com/mattn/go-isatty v0.0.17/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= github.com/moby/spdystream v0.2.0 h1:cjW1zVyyoiM0T7b6UoySUFqzXMoqRckQtXwGPiBhOM8= github.com/moby/spdystream v0.2.0/go.mod h1:f7i0iNDQJ059oMTcWxx8MA/zKFIuD/lY+0GqbN2Wy8c= github.com/moby/term v0.0.0-20221205130635-1aeaba878587 h1:HfkjXDfhgVaN5rmueG8cL8KKeFNecRCXFhaJ2qZ5SKA= diff --git a/main.go b/main.go index 2328557..32499ec 100644 --- a/main.go +++ b/main.go @@ -186,7 +186,7 @@ func browseCommand(kubeConfigFlags *genericclioptions.ConfigFlags, pvcName strin podSpinner := spinner.New(spinner.CharSets[11], 100*time.Millisecond) podSpinner.Suffix = " Waiting for Pod to Start\n" - podSpinner.FinalMSG = "✓ Pod Started\n" + podSpinner.FinalMSG = "✓ Attached to " + pod.Name + "\n" podSpinner.Start() for pod.Status.Phase != corev1.PodRunning && timeout > 0 { diff --git a/util.go b/util.go index d3e8b74..f8aa08b 100644 --- a/util.go +++ b/util.go @@ -14,21 +14,22 @@ type PodOptions struct { } var script = ` -base_processes=$(ls /proc | grep -E '^[0-9]+$' | xargs -I {} sh -c 'cat /proc/{}/comm 2>/dev/null' | grep -E "ash|bash|sh" | wc -l) +base_processes=$(ls /proc | grep -E '^[0-9]+$' | while read -r pid; do cat /proc/"$pid"/comm 2>/dev/null; done | grep -E "ash|bash|sh" | wc -l) echo "Processes: $base_processes" sleep 2 while :; do - shell_processes=$(ls /proc | grep -E '^[0-9]+$' | xargs -I {} sh -c 'cat /proc/{}/comm 2>/dev/null' | grep -E "ash|bash|sh" | wc -l) + shell_processes=$(ls /proc | grep -E '^[0-9]+$' | while read -r pid; do cat /proc/"$pid"/comm 2>/dev/null; done | grep -E "ash|bash|sh" | wc -l) if [ "$shell_processes" -gt "$base_processes" ]; then echo "Found an additional process" while [ "$shell_processes" -gt "$base_processes" ]; do sleep 2 - shell_processes=$(ls /proc | grep -E '^[0-9]+$' | xargs -I {} sh -c 'cat /proc/{}/comm 2>/dev/null' | grep -E "ash|bash|sh" | wc -l) + shell_processes=$(ls /proc | grep -E '^[0-9]+$' | while read -r pid; do cat /proc/"$pid"/comm 2>/dev/null; done | grep -E "ash|bash|sh" | wc -l) done exit 0 fi done + ` // Finds if a pod that attached to a PVC @@ -51,7 +52,7 @@ func buildPvcbGetJob(options PodOptions) *batchv1.Job { job := &batchv1.Job{ ObjectMeta: metav1.ObjectMeta{ - Name: "browse-pvc" + options.pvc.Name, + Name: "browse-" + options.pvc.Name, Namespace: options.namespace, }, Spec: batchv1.JobSpec{