@@ -29,6 +29,8 @@ import {type K8} from './k8.js';
29
29
import { type TDirectoryData } from './t_directory_data.js' ;
30
30
import { type Namespaces } from './namespaces.js' ;
31
31
import { NamespaceName } from './namespace_name.js' ;
32
+ import K8ClientClusters from './k8_client/k8_client_clusters.js' ;
33
+ import { type Clusters } from './clusters.js' ;
32
34
33
35
/**
34
36
* A kubernetes API wrapper class providing custom functionalities required by solo
@@ -45,11 +47,14 @@ export class K8Client implements K8 {
45
47
constants . POD_CONDITION_READY ,
46
48
constants . POD_CONDITION_STATUS_TRUE ,
47
49
) ;
50
+
48
51
private kubeConfig ! : k8s . KubeConfig ;
49
52
kubeClient ! : k8s . CoreV1Api ;
50
53
private coordinationApiClient : k8s . CoordinationV1Api ;
51
54
private networkingApi : k8s . NetworkingV1Api ;
52
55
56
+ private k8Clusters : K8ClientClusters ;
57
+
53
58
constructor (
54
59
@inject ( ConfigManager ) private readonly configManager ?: ConfigManager ,
55
60
@inject ( SoloLogger ) private readonly logger ?: SoloLogger ,
@@ -77,6 +82,8 @@ export class K8Client implements K8 {
77
82
this . networkingApi = this . kubeConfig . makeApiClient ( k8s . NetworkingV1Api ) ;
78
83
this . coordinationApiClient = this . kubeConfig . makeApiClient ( k8s . CoordinationV1Api ) ;
79
84
85
+ this . k8Clusters = new K8ClientClusters ( this . kubeConfig ) ;
86
+
80
87
return this ; // to enable chaining
81
88
}
82
89
@@ -85,6 +92,14 @@ export class K8Client implements K8 {
85
92
return null ;
86
93
}
87
94
95
+ /**
96
+ * Fluent accessor for reading and manipulating cluster information from the kubeconfig file.
97
+ * returns an object instance providing cluster operations
98
+ */
99
+ public clusters ( ) : Clusters {
100
+ return this . k8Clusters ;
101
+ }
102
+
88
103
/**
89
104
* Apply filters to metadata
90
105
* @param items - list of items
@@ -246,13 +261,8 @@ export class K8Client implements K8 {
246
261
return this . filterItem ( resp . body . items , { name} ) ;
247
262
}
248
263
249
- public getClusters ( ) {
250
- const clusters : string [ ] = [ ] ;
251
- for ( const cluster of this . kubeConfig . getClusters ( ) ) {
252
- clusters . push ( cluster . name ) ;
253
- }
254
-
255
- return clusters ;
264
+ public getClusters ( ) : string [ ] {
265
+ return this . clusters ( ) . list ( ) ;
256
266
}
257
267
258
268
public getContextNames ( ) : string [ ] {
@@ -1590,9 +1600,7 @@ export class K8Client implements K8 {
1590
1600
}
1591
1601
1592
1602
public getCurrentClusterName ( ) : string {
1593
- const currentCluster = this . kubeConfig . getCurrentCluster ( ) ;
1594
- if ( ! currentCluster ) return '' ;
1595
- return currentCluster . name ;
1603
+ return this . clusters ( ) . readCurrent ( ) ;
1596
1604
}
1597
1605
1598
1606
public async listSvcs ( namespace : NamespaceName , labels : string [ ] ) : Promise < k8s . V1Service [ ] > {
0 commit comments