@@ -17,7 +17,7 @@ import {inject, injectable} from 'tsyringe-neo';
17
17
import { patchInject } from './../container_helper.js' ;
18
18
import { type K8 } from './k8.js' ;
19
19
import { type Namespaces } from './namespaces.js' ;
20
- import { NamespaceName } from './namespace_name.js' ;
20
+ import { type NamespaceName } from './namespace_name.js' ;
21
21
import { K8ClientClusters } from './k8_client/k8_client_clusters.js' ;
22
22
import { type Clusters } from './clusters.js' ;
23
23
import { type ConfigMaps } from './config_maps.js' ;
@@ -38,6 +38,7 @@ import {type Pvcs} from './pvcs.js';
38
38
import { K8ClientPvcs } from './k8_client/k8_client_pvcs.js' ;
39
39
import { type Leases } from './leases.js' ;
40
40
import { K8ClientLeases } from './k8_client/k8_client_leases.js' ;
41
+ import { K8ClientNamespaces } from './k8_client/k8_client_namespaces.js' ;
41
42
42
43
/**
43
44
* A kubernetes API wrapper class providing custom functionalities required by solo
@@ -63,6 +64,7 @@ export class K8Client extends K8ClientBase implements K8 {
63
64
private k8Contexts : Contexts ;
64
65
private k8Services : Services ;
65
66
private k8Pvcs : Pvcs ;
67
+ private k8Namespaces : Namespaces ;
66
68
67
69
constructor (
68
70
@inject ( ConfigManager ) private readonly configManager ?: ConfigManager ,
@@ -100,46 +102,27 @@ export class K8Client extends K8ClientBase implements K8 {
100
102
this . k8Pods = new K8ClientPods ( this . kubeClient , this . kubeConfig ) ;
101
103
this . k8Pvcs = new K8ClientPvcs ( this . kubeClient ) ;
102
104
this . k8Leases = new K8ClientLeases ( this . coordinationApiClient ) ;
105
+ this . k8Namespaces = new K8ClientNamespaces ( this . kubeClient ) ;
103
106
104
107
return this ; // to enable chaining
105
108
}
106
109
107
- /**
108
- * Fluent accessor for reading and manipulating namespaces in the kubernetes cluster.
109
- * @returns an object instance providing namespace operations
110
- */
111
110
public namespaces ( ) : Namespaces {
112
- return null ;
111
+ return this . k8Namespaces ;
113
112
}
114
113
115
- /**
116
- * Fluent accessor for reading and manipulating cluster information from the kubeconfig file.
117
- * @returns an object instance providing cluster operations
118
- */
119
114
public clusters ( ) : Clusters {
120
115
return this . k8Clusters ;
121
116
}
122
117
123
- /**
124
- * Fluent accessor for reading and manipulating config maps in the kubernetes cluster.
125
- * @returns an object instance providing config map operations
126
- */
127
118
public configMaps ( ) : ConfigMaps {
128
119
return this . k8ConfigMaps ;
129
120
}
130
121
131
- /**
132
- * Fluent accessor for reading and manipulating containers.
133
- * returns an object instance providing container operations
134
- */
135
122
public containers ( ) : Containers {
136
123
return this . k8Containers ;
137
124
}
138
125
139
- /**
140
- * Fluent accessor for reading and manipulating contexts in the kubeconfig file.
141
- * @returns an object instance providing context operations
142
- */
143
126
public contexts ( ) : Contexts {
144
127
return this . k8Contexts ;
145
128
}
@@ -173,38 +156,19 @@ export class K8Client extends K8ClientBase implements K8 {
173
156
}
174
157
175
158
public async createNamespace ( namespace : NamespaceName ) {
176
- const payload = {
177
- metadata : {
178
- name : namespace . name ,
179
- } ,
180
- } ;
181
-
182
- const resp = await this . kubeClient . createNamespace ( payload ) ;
183
- return resp . response . statusCode === StatusCodes . CREATED ;
159
+ return this . namespaces ( ) . create ( namespace ) ;
184
160
}
185
161
186
162
public async deleteNamespace ( namespace : NamespaceName ) {
187
- const resp = await this . kubeClient . deleteNamespace ( namespace . name ) ;
188
- return resp . response . statusCode === StatusCodes . OK ;
163
+ return this . namespaces ( ) . delete ( namespace ) ;
189
164
}
190
165
191
166
public async getNamespaces ( ) {
192
- const resp = await this . kubeClient . listNamespace ( ) ;
193
- if ( resp . body && resp . body . items ) {
194
- const namespaces : NamespaceName [ ] = [ ] ;
195
- resp . body . items . forEach ( item => {
196
- namespaces . push ( NamespaceName . of ( item . metadata ! . name ) ) ;
197
- } ) ;
198
-
199
- return namespaces ;
200
- }
201
-
202
- throw new SoloError ( 'incorrect response received from kubernetes API. Unable to list namespaces' ) ;
167
+ return this . namespaces ( ) . list ( ) ;
203
168
}
204
169
205
170
public async hasNamespace ( namespace : NamespaceName ) {
206
- const namespaces = await this . getNamespaces ( ) ;
207
- return namespaces . some ( namespaces => namespaces . equals ( namespace ) ) ;
171
+ return this . namespaces ( ) . has ( namespace ) ;
208
172
}
209
173
210
174
public async getPodByName ( podRef : PodRef ) : Promise < k8s . V1Pod > {
0 commit comments