@@ -85,6 +85,7 @@ You may set default configuration such as image and command in the config file,
85
85
86
86
defaultPortForward = true
87
87
defaultAgentless = true
88
+ defaultLxcfsEnable = true
88
89
)
89
90
90
91
// DebugOptions specify how to run debug container in a running pod
@@ -114,6 +115,8 @@ type DebugOptions struct {
114
115
AgentPodNamespace string
115
116
AgentPodNode string
116
117
AgentPodResource agentPodResources
118
+ // enable lxcfs
119
+ IsLxcfsEnabled bool
117
120
118
121
Flags * genericclioptions.ConfigFlags
119
122
CoreClient coreclient.CoreV1Interface
@@ -214,6 +217,8 @@ func NewDebugCmd(streams genericclioptions.IOStreams) *cobra.Command {
214
217
fmt .Sprintf ("Agentless mode, agent pod cpu limits, default is not set" ))
215
218
cmd .Flags ().StringVar (& opts .AgentPodResource .MemoryLimits , "agent-pod-memory-limits" , "" ,
216
219
fmt .Sprintf ("Agentless mode, agent pod memory limits, default is not set" ))
220
+ cmd .Flags ().BoolVarP (& opts .IsLxcfsEnabled , "enable-lxcfs" , "" , true ,
221
+ fmt .Sprintf ("Enable Lxcfs, the target container can use its proc files, default to %t" , defaultLxcfsEnable ))
217
222
opts .Flags .AddFlags (cmd .Flags ())
218
223
219
224
return cmd
@@ -372,6 +377,12 @@ func (o *DebugOptions) Complete(cmd *cobra.Command, args []string, argsLenAtDash
372
377
}
373
378
}
374
379
380
+ if o .IsLxcfsEnabled {
381
+ o .IsLxcfsEnabled = config .IsLxcfsEnabled
382
+ } else {
383
+ o .IsLxcfsEnabled = defaultLxcfsEnable
384
+ }
385
+
375
386
if config .PortForward {
376
387
o .PortForward = true
377
388
}
@@ -534,6 +545,11 @@ func (o *DebugOptions) Run() error {
534
545
params := url.Values {}
535
546
params .Add ("image" , o .Image )
536
547
params .Add ("container" , containerID )
548
+ if o .IsLxcfsEnabled {
549
+ params .Add ("lxcfsEnabled" , "true" )
550
+ } else {
551
+ params .Add ("lxcfsEnabled" , "false" )
552
+ }
537
553
var authStr string
538
554
registrySecret , err := o .CoreClient .Secrets (o .RegistrySecretNamespace ).Get (o .RegistrySecretName , v1.GetOptions {})
539
555
if err != nil {
@@ -725,6 +741,9 @@ func (o *DebugOptions) launchPod(pod *corev1.Pod) (*corev1.Pod, error) {
725
741
726
742
// getAgentPod construnct agentPod from agent pod template
727
743
func (o * DebugOptions ) getAgentPod () * corev1.Pod {
744
+ prop := corev1 .MountPropagationBidirectional
745
+ directoryCreate := corev1 .HostPathDirectoryOrCreate
746
+ priveleged := true
728
747
agentPod := & corev1.Pod {
729
748
TypeMeta : v1.TypeMeta {
730
749
Kind : "Pod" ,
@@ -735,6 +754,7 @@ func (o *DebugOptions) getAgentPod() *corev1.Pod {
735
754
Namespace : o .AgentPodNamespace ,
736
755
},
737
756
Spec : corev1.PodSpec {
757
+ HostPID : true ,
738
758
NodeName : o .AgentPodNode ,
739
759
Containers : []corev1.Container {
740
760
{
@@ -754,12 +774,24 @@ func (o *DebugOptions) getAgentPod() *corev1.Pod {
754
774
TimeoutSeconds : 1 ,
755
775
FailureThreshold : 3 ,
756
776
},
777
+ SecurityContext : & corev1.SecurityContext {
778
+ Privileged : & priveleged ,
779
+ },
757
780
Resources : o .buildAgentResourceRequirements (),
758
781
VolumeMounts : []corev1.VolumeMount {
759
782
{
760
783
Name : "docker" ,
761
784
MountPath : "/var/run/docker.sock" ,
762
785
},
786
+ {
787
+ Name : "cgroup" ,
788
+ MountPath : "/sys/fs/cgroup" ,
789
+ },
790
+ {
791
+ Name : "lxcfs" ,
792
+ MountPath : "/var/lib/lxc/lxcfs" ,
793
+ MountPropagation : & prop ,
794
+ },
763
795
},
764
796
Ports : []corev1.ContainerPort {
765
797
{
@@ -779,6 +811,23 @@ func (o *DebugOptions) getAgentPod() *corev1.Pod {
779
811
},
780
812
},
781
813
},
814
+ {
815
+ Name : "cgroup" ,
816
+ VolumeSource : corev1.VolumeSource {
817
+ HostPath : & corev1.HostPathVolumeSource {
818
+ Path : "/sys/fs/cgroup" ,
819
+ },
820
+ },
821
+ },
822
+ {
823
+ Name : "lxcfs" ,
824
+ VolumeSource : corev1.VolumeSource {
825
+ HostPath : & corev1.HostPathVolumeSource {
826
+ Path : "/var/lib/lxc/lxcfs" ,
827
+ Type : & directoryCreate ,
828
+ },
829
+ },
830
+ },
782
831
},
783
832
RestartPolicy : corev1 .RestartPolicyNever ,
784
833
},
0 commit comments