@@ -13,7 +13,7 @@ import { NodeApi } from "@k8slens/kube-api";
1313import { TerminalChannels } from "../../../common/terminal/channels" ;
1414import type { CreateKubeJsonApiForCluster } from "../../../common/k8s-api/create-kube-json-api-for-cluster.injectable" ;
1515import type { CreateKubeApi } from "../../../common/k8s-api/create-kube-api.injectable" ;
16- import { initialNodeShellImage } from "../../../common/cluster-types" ;
16+ import { initialNodeShellImage , initialNodeShellWindowsImage } from "../../../common/cluster-types" ;
1717import type { LoadProxyKubeconfig } from "../../cluster/load-proxy-kubeconfig.injectable" ;
1818import type { Pod } from "@k8slens/kube-object" ;
1919
@@ -71,7 +71,23 @@ export class NodeShellSession extends ShellSession {
7171 }
7272
7373 const env = await this . getCachedShellEnv ( ) ;
74- const args = [ "exec" , "-i" , "-t" , "-n" , "kube-system" , this . podName , "--" ] ;
74+ const args = [ "attach" , "-q" , "-i" , "-t" , "-n" , "kube-system" , this . podName ] ;
75+
76+ await this . openShellProcess ( await this . kubectl . getPath ( ) , args , env ) ;
77+ }
78+
79+ protected async createNodeShellPod ( coreApi : CoreV1Api ) {
80+ const {
81+ imagePullSecret,
82+ nodeShellImage,
83+ } = this . cluster . preferences ;
84+
85+ const imagePullSecrets = imagePullSecret
86+ ? [ {
87+ name : imagePullSecret ,
88+ } ]
89+ : undefined ;
90+
7591 const nodeApi = this . dependencies . createKubeApi ( NodeApi , {
7692 request : this . dependencies . createKubeJsonApiForCluster ( this . cluster . id ) ,
7793 } ) ;
@@ -82,34 +98,50 @@ export class NodeShellSession extends ShellSession {
8298 }
8399
84100 const nodeOs = node . getOperatingSystem ( ) ;
101+ const nodeOsImage = node . getOperatingSystemImage ( ) ;
102+ const nodeKernelVersion = node . getKernelVersion ( ) ;
103+
104+ let image : string ;
105+ let command : string [ ] ;
106+ let args : string [ ] ;
107+ let securityContext : any ;
85108
86109 switch ( nodeOs ) {
87110 default :
88111 this . dependencies . logger . warn ( `[NODE-SHELL-SESSION]: could not determine node OS, falling back with assumption of linux` ) ;
89112 // fallthrough
90113 case "linux" :
91- args . push ( "sh" , "-c" , "((clear && bash) || (clear && ash) || (clear && sh))" ) ;
114+ image = nodeShellImage || initialNodeShellImage ;
115+ command = [ "nsenter" ] ;
116+
117+ if ( nodeOsImage && nodeOsImage . startsWith ( "Bottlerocket OS" ) ) {
118+ args = [ "-t" , "1" , "-m" , "-u" , "-i" , "-n" , "-p" , "--" , "apiclient" , "exec" , "admin" , "bash" , "-l" ] ;
119+ } else {
120+ args = [ "-t" , "1" , "-m" , "-u" , "-i" , "-n" , "-p" , "--" , "bash" , "-l" ] ;
121+ }
122+
123+ securityContext = {
124+ privileged : true ,
125+ } ;
92126 break ;
93127 case "windows" :
94- args . push ( "powershell" ) ;
128+ if ( nodeKernelVersion ) {
129+ image = nodeShellImage || initialNodeShellWindowsImage ;
130+ } else {
131+ throw new Error ( `No status with kernel version for node ${ this . nodeName } found` ) ;
132+ }
133+ command = [ "cmd.exe" ] ;
134+ args = [ "/c" , "%CONTAINER_SANDBOX_MOUNT_POINT%\\Program Files\\PowerShell\\latest\\pwsh.exe" , "-nol" , "-wd" , "C:\\" ] ;
135+ securityContext = {
136+ privileged : true ,
137+ windowsOptions : {
138+ hostProcess : true ,
139+ runAsUserName : "NT AUTHORITY\\SYSTEM" ,
140+ } ,
141+ } ;
95142 break ;
96143 }
97144
98- await this . openShellProcess ( await this . kubectl . getPath ( ) , args , env ) ;
99- }
100-
101- protected createNodeShellPod ( coreApi : CoreV1Api ) {
102- const {
103- imagePullSecret,
104- nodeShellImage,
105- } = this . cluster . preferences ;
106-
107- const imagePullSecrets = imagePullSecret
108- ? [ {
109- name : imagePullSecret ,
110- } ]
111- : undefined ;
112-
113145 return coreApi
114146 . createNamespacedPod ( "kube-system" , {
115147 metadata : {
@@ -129,12 +161,13 @@ export class NodeShellSession extends ShellSession {
129161 priorityClassName : "system-node-critical" ,
130162 containers : [ {
131163 name : "shell" ,
132- image : nodeShellImage || initialNodeShellImage ,
133- securityContext : {
134- privileged : true ,
135- } ,
136- command : [ "nsenter" ] ,
137- args : [ "-t" , "1" , "-m" , "-u" , "-i" , "-n" , "sleep" , "14000" ] ,
164+ image,
165+ securityContext,
166+ command,
167+ args,
168+ stdin : true ,
169+ stdinOnce : true ,
170+ tty : true ,
138171 } ] ,
139172 imagePullSecrets,
140173 } ,
0 commit comments