INNER CODE UNIT · Go

copyAndStripPod

aylei/kubectl-debug · pkg/plugin/cmd.go:859

func copyAndStripPod(pod *corev1.Pod, targetContainer string, podLabels map[string]string) *corev1.Pod {
	copied := &corev1.Pod{
		ObjectMeta: *pod.ObjectMeta.DeepCopy(),
		Spec:       *pod.Spec.DeepCopy(),
	}
	// Using original pod name + xid + debug ad copied pod name. To ensure a
	// valid pod name we truncate original pod name to keep the total chars <64
	copied.Name = fmt.Sprintf("%.34s-%s-debug", pod.Name, xid.New().String())
	copied.Labels = podLabels
	copied.Spec.RestartPolicy = corev1.RestartPolicyNever
	for i, c := range copied.Spec.Containers {
		copied.Spec.Containers[i].LivenessProbe = nil
		copied.Spec.Containers[i].ReadinessProbe = nil
		if c.Name == targetContainer {
			// Hack, infinite sleep command to keep the container running
			copied.Spec.Containers[i].Command = []string{"sh", "-c", "--"}
			copied.Spec.Containers[i].Args = []string{"while true; do sleep 30; done;"}
		}

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…