MCPcopy
hub / github.com/kubernetes/kubectl / debugByCopy

Method debugByCopy

pkg/cmd/debug/debug.go:613–639  ·  view source on GitHub ↗

debugByCopy runs a copy of the target Pod with a debug container added or an original container modified

(ctx context.Context, pod *corev1.Pod)

Source from the content-addressed store, hash-verified

611
612// debugByCopy runs a copy of the target Pod with a debug container added or an original container modified
613func (o *DebugOptions) debugByCopy(ctx context.Context, pod *corev1.Pod) (*corev1.Pod, string, error) {
614 copied, dc, err := o.generatePodCopyWithDebugContainer(pod)
615 if err != nil {
616 return nil, "", err
617 }
618
619 var debugContainer *corev1.Container
620 for i := range copied.Spec.Containers {
621 if copied.Spec.Containers[i].Name == dc {
622 debugContainer = &copied.Spec.Containers[i]
623 break
624 }
625 }
626 o.displayWarning(debugContainer, copied)
627
628 created, err := o.podClient.Pods(copied.Namespace).Create(ctx, copied, metav1.CreateOptions{})
629 if err != nil {
630 return nil, "", err
631 }
632 if o.Replace {
633 err := o.podClient.Pods(pod.Namespace).Delete(ctx, pod.Name, *metav1.NewDeleteOptions(0))
634 if err != nil {
635 return nil, "", err
636 }
637 }
638 return created, dc, nil
639}
640
641// Display warning message if some capabilities are set by profile and non-root user is specified in .Spec.SecurityContext.RunAsUser.(#1650)
642func (o *DebugOptions) displayWarning(container *corev1.Container, pod *corev1.Pod) {

Callers 1

visitPodMethod · 0.95

Calls 4

displayWarningMethod · 0.95
PodsMethod · 0.80
DeleteMethod · 0.65

Tested by

no test coverage detected