@@ -65,20 +65,21 @@ export class Kubectl {
6565 //this.kc.loadFromDefault(); // should not be used since we want also load from base64 ENV var
6666
6767 if ( process . env . KUBECONFIG_BASE64 ) {
68- debug . log ( "Use kubectl config from base64" ) ;
6968 let buff = Buffer . from ( process . env . KUBECONFIG_BASE64 , 'base64' ) ;
7069 const kubeconfig = buff . toString ( 'ascii' ) ;
7170 this . kc . loadFromString ( kubeconfig ) ;
71+
72+ debug . log ( "ℹ️ Kubeconfig loaded from base64" ) ;
7273 } else if ( process . env . KUBECONFIG_PATH ) {
73- debug . log ( "Use kubectl config from file " + process . env . KUBECONFIG_PATH ) ;
7474 this . kc . loadFromFile ( process . env . KUBECONFIG_PATH ) ;
75+ debug . log ( "ℹ️ Kubeconfig loaded from file " + process . env . KUBECONFIG_PATH ) ;
7576 } else {
7677 try {
7778 this . kc . loadFromCluster ( ) ;
78- debug . log ( "Kubeconfig loaded from cluster" ) ;
79+ debug . log ( "ℹ️ Kubeconfig loaded from cluster" ) ;
7980 } catch ( error ) {
8081 debug . log ( "❌ Error loading from cluster" ) ;
81- debug . log ( error ) ;
82+ // debug.log(error);
8283 }
8384 }
8485
@@ -95,19 +96,25 @@ export class Kubectl {
9596 this . exec = new Exec ( this . kc )
9697 this . customObjectsApi = this . kc . makeApiClient ( CustomObjectsApi ) ;
9798 } catch ( error ) {
98- debug . log ( "❌ Error creating api clients. Check kubeconfig, cluster connectivity and context" ) ;
99- debug . log ( error ) ;
99+ console . log ( "❌ Error creating api clients. Check kubeconfig, cluster connectivity and context" ) ;
100+ // debug.log(error);
100101 this . kubeVersion = void 0 ;
101102 return ;
102103 }
103104
104105 this . getKubeVersion ( )
105106 . then ( v => {
107+ if ( v && v . gitVersion ) {
108+ console . log ( "ℹ️ Kube version: " + v . gitVersion ) ;
109+ } else {
110+ console . log ( "❌ Failed to get Kubernetes version" ) ;
111+ process . env . KUBERO_SETUP = 'enabled' ;
112+ }
106113 this . kubeVersion = v ;
107114 } )
108115 . catch ( error => {
109- debug . log ( "❌ Error getting kube version" ) ;
110- debug . log ( error ) ;
116+ console . log ( "❌ Failed to get Kubernetes version" ) ;
117+ // debug.log(error);
111118 } ) ;
112119
113120 this . getOperatorVersion ( )
@@ -121,7 +128,7 @@ export class Kubectl {
121128 // TODO and WARNING: This does not respect the context set by the user!
122129 try {
123130 let versionInfo = await this . versionApi . getCode ( )
124- debug . debug ( JSON . stringify ( versionInfo . body ) ) ;
131+ // debug.debug(JSON.stringify(versionInfo.body));
125132 return versionInfo . body ;
126133 } catch ( error ) {
127134 debug . log ( "getKubeVersion: error getting kube version" ) ;
@@ -136,7 +143,8 @@ export class Kubectl {
136143 if ( contextName ) {
137144 const pods = await this . getPods ( namespace , contextName )
138145 . catch ( error => {
139- debug . log ( "Failed to get Operator Version" , error ) ;
146+ debug . log ( "❌ Failed to get Operator Version" ) ;
147+ //debug.log(error);
140148 //return 'error';
141149 } ) ;
142150 if ( pods ) {
@@ -180,8 +188,8 @@ export class Kubectl {
180188 )
181189 return pipelines . body as IKubectlPipelineList ;
182190 } catch ( error ) {
183- debug . log ( error ) ;
184- debug . log ( "getPipelinesList: error getting pipelines" ) ;
191+ // debug.log(error);
192+ debug . log ( "❌ getPipelinesList: error getting pipelines" ) ;
185193 }
186194 const pipelines = { } as IKubectlPipelineList ;
187195 pipelines . items = [ ] ;
@@ -200,7 +208,8 @@ export class Kubectl {
200208 "kuberopipelines" ,
201209 pipeline
202210 ) . catch ( error => {
203- debug . log ( error ) ;
211+ debug . log ( "❌ Error creating pipeline: " + pl . name ) ;
212+ //debug.log(error);
204213 } ) ;
205214 }
206215
@@ -218,7 +227,8 @@ export class Kubectl {
218227 pl . name ,
219228 pipeline
220229 ) . catch ( error => {
221- debug . log ( error ) ;
230+ debug . log ( "❌ Error updating pipeline: " + pl . name ) ;
231+ //debug.log(error);
222232 } ) ;
223233 }
224234
@@ -246,7 +256,8 @@ export class Kubectl {
246256 "kuberopipelines" ,
247257 pipelineName
248258 ) . catch ( error => {
249- debug . log ( error ) ;
259+ //debug.log(error);
260+ debug . log ( "getPipeline: error getting pipeline" ) ;
250261 throw error ;
251262 } ) ;
252263 if ( pipeline ) {
@@ -346,7 +357,7 @@ export class Kubectl {
346357 )
347358 return appslist . body as IKubectlAppList ;
348359 } catch ( error ) {
349- debug . log ( error ) ;
360+ // debug.log(error);
350361 debug . log ( "getAppsList: error getting apps" ) ;
351362 }
352363 const appslist = { } as IKubectlAppList ;
@@ -412,7 +423,7 @@ export class Kubectl {
412423 //let operators = response.body as KubernetesListObject<KubernetesObject>;
413424 operators = response . body as any // TODO : fix type. This is a hacky way to get the type to work
414425 } catch ( error ) {
415- debug . log ( error ) ;
426+ // debug.log(error);
416427 debug . log ( "error getting operators" ) ;
417428 }
418429
@@ -1077,7 +1088,7 @@ export class Kubectl {
10771088 //console.log(config.body);
10781089 return config . body ;
10791090 } catch ( error ) {
1080- debug . log ( error ) ;
1091+ // debug.log(error);
10811092 debug . log ( "getKuberoConfig: error getting config" ) ;
10821093 }
10831094 }
@@ -1306,4 +1317,20 @@ export class Kubectl {
13061317 }
13071318 }
13081319
1320+ public async createNamespace ( namespace : string ) : Promise < any > {
1321+ const ns = {
1322+ apiVersion : 'v1' ,
1323+ kind : 'Namespace' ,
1324+ metadata : {
1325+ name : namespace
1326+ }
1327+ }
1328+ try {
1329+ return await this . coreV1Api . createNamespace ( ns ) ;
1330+ } catch ( error ) {
1331+ //console.log(error);
1332+ console . log ( 'ERROR creating namespace' ) ;
1333+ }
1334+ }
1335+
13091336}
0 commit comments