"vscode:/vscode.git/clone" did not exist on "ceaa85c9e6aa0720f78619886dfcbbed0a74048b"
kubernetesConfig.ts 6.36 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
// tslint:disable: completed-docs function-name
26
27
28
export abstract class KubernetesClusterConfig {
    public readonly storage?: KubernetesStorageKind;
    public readonly apiVersion: string;
29

30
31
    constructor(apiVersion: string, storage?: KubernetesStorageKind) {
        this.storage = storage;
32
        this.apiVersion = apiVersion;
33
34
    }

35
    public get storageType(): KubernetesStorageKind {
36
37
38
39
40
41
42
43
        throw new MethodNotImplementedError();
    }
}

export class StorageConfig {
    public readonly storage?: KubernetesStorageKind;

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

48
export class KubernetesClusterConfigNFS extends KubernetesClusterConfig {
49
    public readonly nfs: NFSConfig;
50
51

    constructor(
52
            apiVersion: string,
53
54
55
56
            nfs: NFSConfig,
            storage?: KubernetesStorageKind
        ) {
        super(apiVersion, storage);
57
58
        this.nfs = nfs;
    }
59

60
    public get storageType(): KubernetesStorageKind {
61
62
63
64
        return 'nfs';
    }

    public static getInstance(jsonObject: object): KubernetesClusterConfigNFS {
65
66
        const kubernetesClusterConfigObjectNFS: KubernetesClusterConfigNFS = <KubernetesClusterConfigNFS>jsonObject;

67
68
69
70
71
72
        return new KubernetesClusterConfigNFS(
            kubernetesClusterConfigObjectNFS.apiVersion,
            kubernetesClusterConfigObjectNFS.nfs,
            kubernetesClusterConfigObjectNFS.storage
        );
    }
73
74
}

75
export class KubernetesClusterConfigAzure extends KubernetesClusterConfig {
76
    public readonly keyVault: KeyVaultConfig;
77
    public readonly azureStorage: AzureStorage;
78

79
    constructor(
80
            apiVersion: string,
81
            keyVault: KeyVaultConfig,
82
            azureStorage: AzureStorage,
83
84
85
            storage?: KubernetesStorageKind
        ) {
        super(apiVersion, storage);
SparkSnail's avatar
SparkSnail committed
86
87
        this.keyVault = keyVault;
        this.azureStorage = azureStorage;
88
    }
89

90
    public get storageType(): KubernetesStorageKind {
91
92
93
94
        return 'azureStorage';
    }

    public static getInstance(jsonObject: object): KubernetesClusterConfigAzure {
95
96
        const kubernetesClusterConfigObjectAzure: KubernetesClusterConfigAzure = <KubernetesClusterConfigAzure>jsonObject;

97
98
99
100
101
102
103
104
105
        return new KubernetesClusterConfigAzure(
            kubernetesClusterConfigObjectAzure.apiVersion,
            kubernetesClusterConfigObjectAzure.keyVault,
            kubernetesClusterConfigObjectAzure.azureStorage,
            kubernetesClusterConfigObjectAzure.storage
        );
    }
}

106
// tslint:disable-next-line:no-unnecessary-class
107
108
109
export class KubernetesClusterConfigFactory {

    public static generateKubernetesClusterConfig(jsonObject: object): KubernetesClusterConfig {
110
111
         const storageConfig: StorageConfig = <StorageConfig>jsonObject;
         switch (storageConfig.storage) {
112
113
            case 'azureStorage':
                return KubernetesClusterConfigAzure.getInstance(jsonObject);
114
115
            case 'nfs':
            case undefined:
116
                return KubernetesClusterConfigNFS.getInstance(jsonObject);
117
118
            default:
                throw new Error(`Invalid json object ${jsonObject}`);
119
120
         }
    }
121
122
123
124
125
126
}

/**
 * NFS configuration to store Kubeflow job related files
 */
export class NFSConfig {
127
    // IP Adress of NFS server
128
    public readonly server : string;
129
    // exported NFS path on NFS server
130
131
132
133
134
135
136
137
    public readonly path : string;

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

SparkSnail's avatar
SparkSnail committed
138
139
140
141
/**
 * 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
 */
142
143
export class KeyVaultConfig {
    // The vault-name to specify vault
SparkSnail's avatar
SparkSnail committed
144
    public readonly vaultName : string;
145
    // The name to specify private key
SparkSnail's avatar
SparkSnail committed
146
147
    public readonly name : string;

148
    constructor(vaultName : string, name : string) {
SparkSnail's avatar
SparkSnail committed
149
150
151
152
153
154
155
156
157
        this.vaultName = vaultName;
        this.name = name;
    }
}

/**
 * Azure Storage Service
 */
export class AzureStorage {
158
    // The azure share to storage files
SparkSnail's avatar
SparkSnail committed
159
    public readonly azureShare : string;
160

161
    // The account name of sotrage service
SparkSnail's avatar
SparkSnail committed
162
    public readonly accountName: string;
163
    constructor(azureShare : string, accountName: string) {
SparkSnail's avatar
SparkSnail committed
164
165
166
167
168
        this.azureShare = azureShare;
        this.accountName = accountName;
    }
}

169
/**
170
 * Trial job configuration for Kubernetes
171
 */
172
export class KubernetesTrialConfigTemplate {
173
    // CPU number
174
    public readonly cpuNum: number;
175

176
    // Memory
177
    public readonly memoryMB: number;
178

179
    // Docker image
180
    public readonly image: string;
181

182
    // Trail command
183
184
    public readonly command : string;

185
    // Required GPU number for trial job. The number should be in [0,100]
186
    public readonly gpuNum : number;
187
188

    constructor(command : string, gpuNum : number,
189
                cpuNum: number, memoryMB: number, image: string) {
190
191
        this.command = command;
        this.gpuNum = gpuNum;
192
193
194
195
        this.cpuNum = cpuNum;
        this.memoryMB = memoryMB;
        this.image = image;
    }
196
197
}

198
export class KubernetesTrialConfig {
199
    public readonly codeDir: string;
200
201
202
203

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