@@ -47,6 +47,7 @@ export class Kubectl {
4747 private customObjectsApi : CustomObjectsApi = { } as CustomObjectsApi ;
4848 private networkingV1Api : NetworkingV1Api = { } as NetworkingV1Api ;
4949 public kubeVersion : VersionInfo | void ;
50+ public kuberoOperatorVersion : string | undefined ;
5051 private patchUtils : PatchUtils = { } as PatchUtils ;
5152 public log : KubeLog ;
5253 //public config: IKuberoConfig;
@@ -100,6 +101,16 @@ export class Kubectl {
100101 . then ( v => {
101102 this . kubeVersion = v ;
102103 } )
104+ . catch ( error => {
105+ debug . log ( "❌ Error getting kube version" ) ;
106+ debug . log ( error ) ;
107+ } ) ;
108+
109+ this . getOperatorVersion ( )
110+ . then ( v => {
111+ debug . log ( "ℹ️ Operator version: " + v ) ;
112+ this . kuberoOperatorVersion = v || 'unknown' ;
113+ } )
103114
104115 }
105116
@@ -115,6 +126,29 @@ export class Kubectl {
115126 }
116127 }
117128
129+ private async getOperatorVersion ( ) : Promise < string | void > {
130+ const contextName = this . getCurrentContext ( ) ;
131+ const namespace = "kubero-operator-system" ;
132+
133+ if ( contextName ) {
134+ const pods = await this . getPods ( namespace , contextName )
135+ . catch ( error => {
136+ debug . log ( "Failed to get Operator Version" , error ) ;
137+ //return 'error';
138+ } ) ;
139+ if ( pods ) {
140+ for ( const pod of pods ) {
141+ if ( pod ?. metadata ?. name ?. startsWith ( 'kubero-operator-controller-manager' ) ) {
142+ const container = pod ?. spec ?. containers . filter ( ( c : any ) => c . name == 'manager' ) [ 0 ] ;
143+ return container ?. image ?. split ( ':' ) [ 1 ] || 'unknown' ;
144+ }
145+ }
146+ } else {
147+ return 'error getting operator version' ;
148+ }
149+ }
150+ }
151+
118152 public getContexts ( ) {
119153 return this . kc . getContexts ( )
120154 }
@@ -123,6 +157,10 @@ export class Kubectl {
123157 this . kc . setCurrentContext ( context )
124158 }
125159
160+ public getCurrentContext ( ) {
161+ return this . kc . getCurrentContext ( )
162+ }
163+
126164 public async getNamespaces ( ) : Promise < V1Namespace [ ] > {
127165 const namespaces = await this . coreV1Api . listNamespace ( ) ;
128166 return namespaces . body . items ;
0 commit comments