Skip to content

Commit eb8411a

Browse files
committed
inject script instead of baking into image
1 parent 150d35b commit eb8411a

File tree

2 files changed

+26
-7
lines changed

2 files changed

+26
-7
lines changed

main.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ func main() {
4343
},
4444
}
4545

46-
rootCmd.Flags().StringVarP(&image, "image", "i", "clbx/kubectl-browse-pvc", "Image to mount job to")
46+
rootCmd.Flags().StringVarP(&image, "image", "i", "alpine", "Image to mount job to")
4747
kubeConfigFlags.AddFlags(rootCmd.Flags())
4848

4949
if err := rootCmd.Execute(); err != nil {
@@ -134,7 +134,7 @@ func browseCommand(kubeConfigFlags *genericclioptions.ConfigFlags, pvcName strin
134134
image: image,
135135
namespace: *kubeConfigFlags.Namespace,
136136
pvc: *targetPvc,
137-
cmd: []string{"/bin/bash", "-c", "--"},
137+
cmd: []string{"/bin/sh", "-c", "--"},
138138
}
139139

140140
// Build the Job
@@ -208,7 +208,7 @@ func browseCommand(kubeConfigFlags *genericclioptions.ConfigFlags, pvcName strin
208208
Namespace(options.namespace).
209209
SubResource("exec").
210210
VersionedParams(&corev1.PodExecOptions{
211-
Command: []string{"bash", "-c", "cd /mnt && /bin/bash"},
211+
Command: []string{"sh", "-c", "cd /mnt && (ash || bash || sh)"},
212212
Stdin: true,
213213
Stdout: true,
214214
Stderr: true,

util.go

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,24 @@ type PodOptions struct {
1313
cmd []string
1414
}
1515

16+
var script = `
17+
base_processes=$(ps aux | grep -E "ash|bash|sh" | grep -v grep | wc -l)
18+
echo "Processes: $base_processes"
19+
sleep 2
20+
21+
while :; do
22+
shell_processes=$(ps aux | grep -E "ash|bash|sh" | grep -v grep | wc -l)
23+
if [ "$shell_processes" -gt "$base_processes" ]; then
24+
echo "Found an additional process"
25+
while [ "$shell_processes" -gt "$base_processes" ]; do
26+
sleep 2
27+
shell_processes=$(ps aux | grep -E "ash|bash|sh" | grep -v grep | wc -l)
28+
done
29+
exit 0
30+
fi
31+
done
32+
`
33+
1634
// Finds if a pod that attached to a PVC
1735
func findPodByPVC(podList corev1.PodList, pvc corev1.PersistentVolumeClaim) *corev1.Pod {
1836
for _, pod := range podList.Items {
@@ -33,24 +51,25 @@ func buildPvcbGetJob(options PodOptions) *batchv1.Job {
3351

3452
job := &batchv1.Job{
3553
ObjectMeta: metav1.ObjectMeta{
36-
Name: "pvcb-edit-" + options.pvc.Name,
54+
Name: "browse-pvc" + options.pvc.Name,
3755
Namespace: options.namespace,
3856
},
3957
Spec: batchv1.JobSpec{
4058
TTLSecondsAfterFinished: TTLSecondsAfterFinished,
4159
Template: corev1.PodTemplateSpec{
4260
ObjectMeta: metav1.ObjectMeta{
43-
Name: "pvcb-edit",
61+
Name: "browse-pvc",
4462
},
4563
Spec: corev1.PodSpec{
4664
RestartPolicy: "Never",
4765
Containers: []corev1.Container{
4866
{
49-
Name: "pvcb-edit",
67+
Name: "browser",
5068
Image: image,
5169
//Command: []string{"/bin/bash", "-c", "--"},
5270
Command: options.cmd,
53-
Args: []string{"/entrypoint.sh"},
71+
//Args: []string{"/entrypoint.sh"},
72+
Args: []string{script},
5473
VolumeMounts: []corev1.VolumeMount{
5574
{
5675
Name: "target-pvc",

0 commit comments

Comments
 (0)