kubernetesConfig.ts 6.19 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
/**
 * Copyright (c) Microsoft Corporation
 * All rights reserved.
 *
 * MIT License
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
 * documentation files (the "Software"), to deal in the Software without restriction, including without limitation
 * the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and
 * to permit persons to whom the Software is furnished to do so, subject to the following conditions:
 * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */

'use strict';

22
23
export type KubernetesStorageKind = 'nfs' | 'azureStorage';
import { MethodNotImplementedError } from '../../common/errors';
24

25
26
27
export abstract class KubernetesClusterConfig {
    public readonly storage?: KubernetesStorageKind;
    public readonly apiVersion: string;
SparkSnail's avatar
SparkSnail committed
28
    
29
30
    constructor(apiVersion: string, storage?: KubernetesStorageKind) {
        this.storage = storage;
31
        this.apiVersion = apiVersion;
32
33
34
35
36
37
38
39
40
41
42
    }

    public get storageType(): KubernetesStorageKind{
        throw new MethodNotImplementedError();
    }
}

export class StorageConfig {
    public readonly storage?: KubernetesStorageKind;

    constructor(storage?: KubernetesStorageKind) {
43
44
45
46
        this.storage = storage;
    }
}

47
export class KubernetesClusterConfigNFS extends KubernetesClusterConfig {
48
    public readonly nfs: NFSConfig;
49
50
51
52
53
54
55

    constructor(
            apiVersion: string, 
            nfs: NFSConfig,
            storage?: KubernetesStorageKind
        ) {
        super(apiVersion, storage);
56
57
        this.nfs = nfs;
    }
58
59
60
61
62
63
64
65
66
67
68
69
70

    public get storageType(): KubernetesStorageKind{
        return 'nfs';
    }

    public static getInstance(jsonObject: object): KubernetesClusterConfigNFS {
        let kubernetesClusterConfigObjectNFS = <KubernetesClusterConfigNFS>jsonObject;
        return new KubernetesClusterConfigNFS(
            kubernetesClusterConfigObjectNFS.apiVersion,
            kubernetesClusterConfigObjectNFS.nfs,
            kubernetesClusterConfigObjectNFS.storage
        );
    }
71
72
}

73
export class KubernetesClusterConfigAzure extends KubernetesClusterConfig {
74
75
76
    public readonly keyVault: keyVaultConfig;
    public readonly azureStorage: AzureStorage;
    
77
78
    constructor(
            apiVersion: string, 
79
80
            keyVault: keyVaultConfig, 
            azureStorage: AzureStorage, 
81
82
83
            storage?: KubernetesStorageKind
        ) {
        super(apiVersion, storage);
SparkSnail's avatar
SparkSnail committed
84
85
        this.keyVault = keyVault;
        this.azureStorage = azureStorage;
86
    }
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114

    public get storageType(): KubernetesStorageKind{
        return 'azureStorage';
    }

    public static getInstance(jsonObject: object): KubernetesClusterConfigAzure {
        let kubernetesClusterConfigObjectAzure = <KubernetesClusterConfigAzure>jsonObject;
        return new KubernetesClusterConfigAzure(
            kubernetesClusterConfigObjectAzure.apiVersion,
            kubernetesClusterConfigObjectAzure.keyVault,
            kubernetesClusterConfigObjectAzure.azureStorage,
            kubernetesClusterConfigObjectAzure.storage
        );
    }
}

export class KubernetesClusterConfigFactory {

    public static generateKubernetesClusterConfig(jsonObject: object): KubernetesClusterConfig {
         let storageConfig = <StorageConfig>jsonObject;
         switch(storageConfig.storage) {
            case 'azureStorage':
                return KubernetesClusterConfigAzure.getInstance(jsonObject);
            case  'nfs' || undefined :
                return KubernetesClusterConfigNFS.getInstance(jsonObject);
         }
         throw new Error(`Invalid json object ${jsonObject}`);
    }
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
}

/**
 * NFS configuration to store Kubeflow job related files
 */
export class NFSConfig {
    /** IP Adress of NFS server */
    public readonly server : string;
    /** exported NFS path on NFS server */
    public readonly path : string;

    constructor(server : string, path : string) {
        this.server = server;
        this.path = path;
    }
}

SparkSnail's avatar
SparkSnail committed
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
/**
 * KeyVault configuration to store the key of Azure Storage Service
 * Refer https://docs.microsoft.com/en-us/azure/key-vault/key-vault-manage-with-cli2
 */
export class keyVaultConfig {
    /**The vault-name to specify vault */
    public readonly vaultName : string;
    /**The name to specify private key */
    public readonly name : string;

    constructor(vaultName : string, name : string){
        this.vaultName = vaultName;
        this.name = name;
    }
}

/**
 * Azure Storage Service
 */
export class AzureStorage {
    /**The azure share to storage files */
    public readonly azureShare : string;
    
    /**The account name of sotrage service */
    public readonly accountName: string;
    constructor(azureShare : string, accountName: string){
        this.azureShare = azureShare;
        this.accountName = accountName;
    }
}

163
/**
164
 * Trial job configuration for Kubernetes
165
 */
166
export class KubernetesTrialConfigTemplate {
167
    /** CPU number */
168
    public readonly cpuNum: number;
169
170

    /** Memory  */
171
    public readonly memoryMB: number;
172
173

    /** Docker image */
174
    public readonly image: string;
175
176
177
178
179
180

    /** Trail command */
    public readonly command : string;

    /** Required GPU number for trial job. The number should be in [0,100] */
    public readonly gpuNum : number;
181
    
182
    constructor(command : string, gpuNum : number, 
183
184
185
        cpuNum: number, memoryMB: number, image: string) {
        this.command = command;
        this.gpuNum = gpuNum;
186
187
188
189
        this.cpuNum = cpuNum;
        this.memoryMB = memoryMB;
        this.image = image;
    }
190
191
}

192
export class KubernetesTrialConfig {
193
    public readonly codeDir: string;
194
195
196
197

    constructor(codeDir: string) {
        this.codeDir = codeDir;
    }
198
}