-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathconfigs.ts
125 lines (105 loc) · 4.02 KB
/
configs.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
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
115
116
117
118
119
120
121
122
123
124
125
/**
* Copyright (C) 2024 Hedera Hashgraph, LLC
*
* Licensed under the Apache License, Version 2.0 (the ""License"");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an ""AS IS"" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
import {type NodeAlias} from '../../types/aliases.js';
import {Flags as flags} from '../flags.js';
import * as constants from '../../core/constants.js';
import {ListrEnquirerPromptAdapter} from '@listr2/prompt-adapter-enquirer';
import {SoloError} from '../../core/errors.js';
export const CONNECT_CONFIGS_NAME = 'connectConfig';
export const connectConfigBuilder = async function (argv, ctx, task) {
const config = this.getConfig(CONNECT_CONFIGS_NAME, argv.flags, [
'currentDeploymentName',
]) as ClusterConnectConfigClass;
// set config in the context for later tasks to use
ctx.config = config;
return ctx.config;
};
export const setupConfigBuilder = async function (argv, ctx, task) {
const parent = this.parent;
const configManager = parent.getConfigManager();
configManager.update(argv);
flags.disablePrompts([flags.chartDirectory]);
await configManager.executePrompt(task, [
flags.chartDirectory,
flags.clusterSetupNamespace,
flags.deployCertManager,
flags.deployCertManagerCrds,
flags.deployMinio,
flags.deployPrometheusStack,
]);
ctx.config = {
chartDir: configManager.getFlag(flags.chartDirectory) as string,
clusterSetupNamespace: configManager.getFlag(flags.clusterSetupNamespace) as string,
deployCertManager: configManager.getFlag(flags.deployCertManager) as boolean,
deployCertManagerCrds: configManager.getFlag(flags.deployCertManagerCrds) as boolean,
deployMinio: configManager.getFlag(flags.deployMinio) as boolean,
deployPrometheusStack: configManager.getFlag(flags.deployPrometheusStack) as boolean,
soloChartVersion: configManager.getFlag(flags.soloChartVersion) as string,
} as ClusterSetupConfigClass;
parent.logger.debug('Prepare ctx.config', {config: ctx.config, argv});
ctx.isChartInstalled = await parent
.getChartManager()
.isChartInstalled(ctx.config.clusterSetupNamespace, constants.SOLO_CLUSTER_SETUP_CHART);
return ctx.config;
};
export const resetConfigBuilder = async function (argv, ctx, task) {
if (!argv[flags.force.name]) {
const confirm = await task.prompt(ListrEnquirerPromptAdapter).run({
type: 'toggle',
default: false,
message: 'Are you sure you would like to uninstall solo-cluster-setup chart?',
});
if (!confirm) {
// eslint-disable-next-line n/no-process-exit
process.exit(0);
}
}
this.parent.getConfigManager().update(argv);
ctx.config = {
clusterName: this.parent.getConfigManager().getFlag(flags.clusterName) as string,
clusterSetupNamespace: this.parent.getConfigManager().getFlag(flags.clusterSetupNamespace) as string,
} as ClusterResetConfigClass;
ctx.isChartInstalled = await this.parent
.getChartManager()
.isChartInstalled(ctx.config.clusterSetupNamespace, constants.SOLO_CLUSTER_SETUP_CHART);
if (!ctx.isChartInstalled) {
throw new SoloError('No chart found for the cluster');
}
return ctx.config;
};
export interface ClusterConnectConfigClass {
app: string;
cacheDir: string;
devMode: boolean;
namespace: string;
nodeAlias: NodeAlias;
context: string;
clusterName: string;
}
export interface ClusterSetupConfigClass {
chartDir: string;
clusterSetupNamespace: string;
deployCertManager: boolean;
deployCertManagerCrds: boolean;
deployMinio: boolean;
deployPrometheusStack: boolean;
soloChartVersion: string;
}
export interface ClusterResetConfigClass {
clusterName: string;
clusterSetupNamespace: string;
}