1- import { CoreV1Api , V1PersistentVolume } from '@kubernetes/client-node' ;
1+ import { V1PersistentVolume } from '@kubernetes/client-node' ;
22import * as ApiK8s from './api' ;
33import {
44 Metalk8sV1alpha1VolumeClient ,
@@ -22,18 +22,24 @@ export type LocalPersistentVolume = V1PersistentVolume & {
2222} ;
2323
2424export default class Metalk8sLocalVolumeProvider {
25- volumeClient : Metalk8sV1alpha1VolumeClient ;
26- k8sClient : CoreV1Api ;
27- constructor ( url : string , token : string ) {
28- const { coreV1, customObjects } = ApiK8s . updateApiServerConfig ( url , token ) ;
29- this . volumeClient = new Metalk8sV1alpha1VolumeClient ( customObjects ) ;
30- this . k8sClient = coreV1 ;
25+ apiUrl : string ;
26+ constructor ( apiUrl : string , private getToken : ( ) => Promise < string > ) {
27+ this . apiUrl = apiUrl ;
3128 }
29+
3230 public listLocalPersistentVolumes = async (
3331 serverName : string ,
3432 ) : Promise < LocalPersistentVolume [ ] > => {
3533 try {
36- const nodes = await this . k8sClient . listNode ( ) ;
34+ const token = await this . getToken ( ) ;
35+ const { coreV1, customObjects } = ApiK8s . updateApiServerConfig (
36+ this . apiUrl ,
37+ token ,
38+ ) ;
39+ const volumeClient = new Metalk8sV1alpha1VolumeClient ( customObjects ) ;
40+ const k8sClient = coreV1 ;
41+
42+ const nodes = await k8sClient . listNode ( ) ;
3743 const nodeIP = nodes . body . items
3844 . find ( ( node ) => node . metadata . name === serverName )
3945 ?. status . addresses . find ( ( address ) => address . type === 'InternalIP' ) ;
@@ -42,13 +48,13 @@ export default class Metalk8sLocalVolumeProvider {
4248 throw new Error ( `Failed to find IP for node ${ serverName } ` ) ;
4349 }
4450
45- const volumes = await this . volumeClient . getMetalk8sV1alpha1VolumeList ( ) ;
51+ const volumes = await volumeClient . getMetalk8sV1alpha1VolumeList ( ) ;
4652
4753 if ( ! isError ( volumes ) ) {
4854 const nodeVolumes = volumes . body . items . filter (
4955 ( volume ) => volume . spec . nodeName === serverName ,
5056 ) ;
51- const pv = await this . k8sClient . listPersistentVolume ( ) ;
57+ const pv = await k8sClient . listPersistentVolume ( ) ;
5258
5359 const localPv = nodeVolumes . reduce ( ( acc , item ) => {
5460 const isLocalPv = pv . body . items . find (
0 commit comments