debugByCopy runs a copy of the target Pod with a debug container added or an original container modified
(ctx context.Context, pod *corev1.Pod)
| 611 | |
| 612 | // debugByCopy runs a copy of the target Pod with a debug container added or an original container modified |
| 613 | func (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) |
| 642 | func (o *DebugOptions) displayWarning(container *corev1.Container, pod *corev1.Pod) { |
no test coverage detected