@rancher/shell 2.0.2-rc.1 → 2.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/assets/translations/en-us.yaml +44 -30
- package/components/PromptRemove.vue +8 -3
- package/components/ResourceDetail/Masthead.vue +1 -0
- package/components/fleet/FleetClusters.vue +0 -3
- package/components/formatter/CloudCredExpired.vue +69 -0
- package/components/formatter/Date.vue +1 -1
- package/components/nav/Header.vue +9 -5
- package/components/nav/TopLevelMenu.vue +115 -51
- package/components/nav/__tests__/TopLevelMenu.test.ts +53 -27
- package/config/labels-annotations.js +2 -0
- package/detail/catalog.cattle.io.app.vue +17 -4
- package/detail/fleet.cattle.io.cluster.vue +11 -9
- package/detail/fleet.cattle.io.gitrepo.vue +1 -1
- package/edit/provisioning.cattle.io.cluster/rke2.vue +13 -0
- package/list/provisioning.cattle.io.cluster.vue +56 -5
- package/mixins/chart.js +6 -2
- package/models/catalog.cattle.io.app.js +108 -21
- package/models/cloudcredential.js +159 -2
- package/models/fleet.cattle.io.gitrepo.js +4 -13
- package/models/management.cattle.io.cluster.js +13 -2
- package/models/provisioning.cattle.io.cluster.js +37 -3
- package/package.json +1 -1
- package/pages/c/_cluster/apps/charts/install.vue +2 -1
- package/pages/c/_cluster/explorer/__tests__/index.test.ts +1 -1
- package/pages/c/_cluster/explorer/index.vue +1 -2
- package/pages/c/_cluster/fleet/index.vue +11 -5
- package/pages/c/_cluster/manager/cloudCredential/index.vue +68 -4
- package/pages/c/_cluster/uiplugins/index.vue +4 -2
- package/pages/home.vue +1 -0
- package/scripts/extension/bundle +1 -1
- package/scripts/publish-shell.sh +3 -4
- package/scripts/typegen.sh +26 -23
- package/types/shell/index.d.ts +4595 -0
- package/utils/cluster.js +1 -1
- package/utils/string.js +9 -0
- package/utils/v-sphere.ts +251 -0
- package/shell/types/shell/index.d.ts +0 -2
package/utils/cluster.js
CHANGED
|
@@ -94,7 +94,7 @@ export function abbreviateClusterName(input) {
|
|
|
94
94
|
|
|
95
95
|
export function labelForAddon(name, configuration = true) {
|
|
96
96
|
const addon = camelToTitle(name.replace(/^(rke|rke2|rancher)-/, ''));
|
|
97
|
-
const fallback = `${
|
|
97
|
+
const fallback = `${ configuration ? '' : 'Add-on: ' }${ addon }`;
|
|
98
98
|
const key = `cluster.addonChart."${ name }"${ configuration ? '.configuration' : '.label' }`;
|
|
99
99
|
|
|
100
100
|
return this.$store.getters['i18n/withFallback'](key, null, fallback);
|
package/utils/string.js
CHANGED
|
@@ -321,3 +321,12 @@ export function sanitizeValue(v) {
|
|
|
321
321
|
export function sanitizeIP(v) {
|
|
322
322
|
return (v || '').replace(/[^a-z0-9.:_-]/ig, '');
|
|
323
323
|
}
|
|
324
|
+
|
|
325
|
+
/**
|
|
326
|
+
* Return the string `<x> / <y>`
|
|
327
|
+
*
|
|
328
|
+
* Each param should be a number, otherwise `?` is used
|
|
329
|
+
*/
|
|
330
|
+
export function xOfy(x, y) {
|
|
331
|
+
return `${ typeof x === 'number' ? x : '?' }/${ typeof y === 'number' ? y : '?' }`;
|
|
332
|
+
}
|
|
@@ -0,0 +1,251 @@
|
|
|
1
|
+
import merge from 'lodash/merge';
|
|
2
|
+
import { SECRET } from '@shell/config/types';
|
|
3
|
+
|
|
4
|
+
type Rke2Component = {
|
|
5
|
+
versionInfo: any;
|
|
6
|
+
userChartValues: any;
|
|
7
|
+
chartVersionKey: (chartName: string) => string;
|
|
8
|
+
value: any;
|
|
9
|
+
isEdit: boolean;
|
|
10
|
+
$store: any,
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
type SecretDetails = {
|
|
14
|
+
generateName: string,
|
|
15
|
+
upstreamClusterName: string,
|
|
16
|
+
upstreamNamespace: string,
|
|
17
|
+
downstreamName: string,
|
|
18
|
+
downstreamNamespace: string,
|
|
19
|
+
json?: object,
|
|
20
|
+
}
|
|
21
|
+
type Values = any;
|
|
22
|
+
|
|
23
|
+
type ChartValues = {
|
|
24
|
+
defaultValues: Values,
|
|
25
|
+
userValues: Values,
|
|
26
|
+
combined: Values,
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
const rootGenerateName = 'vsphere-secret-';
|
|
30
|
+
|
|
31
|
+
type SecretJson = any;
|
|
32
|
+
|
|
33
|
+
class VSphereUtils {
|
|
34
|
+
private async findSecret(
|
|
35
|
+
{ $store }: Rke2Component, {
|
|
36
|
+
generateName, upstreamClusterName, upstreamNamespace, downstreamName, downstreamNamespace
|
|
37
|
+
}: SecretDetails): Promise<SecretJson | undefined> {
|
|
38
|
+
const secrets = await $store.dispatch('management/request', { url: `/v1/${ SECRET }/${ upstreamNamespace }?filter=metadata.name=${ generateName }` });
|
|
39
|
+
|
|
40
|
+
const applicableSecret = secrets.data?.filter((s: any) => {
|
|
41
|
+
return s.metadata.annotations['provisioning.cattle.io/sync-target-namespace'] === downstreamNamespace &&
|
|
42
|
+
s.metadata.annotations['provisioning.cattle.io/sync-target-name'] === downstreamName &&
|
|
43
|
+
s.metadata.annotations['rke.cattle.io/object-authorized-for-clusters'].includes(upstreamClusterName);
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
if (applicableSecret.length > 1) {
|
|
47
|
+
return Promise.reject(new Error(`Found multiple matching secrets (${ upstreamNamespace }/${ upstreamNamespace } for ${ upstreamClusterName }), this will cause synchronizing mishaps. Consider removing stale secrets from old clusters`));
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
return applicableSecret[0];
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
private async findOrCreateSecret(
|
|
54
|
+
rke2Component: Rke2Component,
|
|
55
|
+
{
|
|
56
|
+
generateName, upstreamClusterName, upstreamNamespace, downstreamName, downstreamNamespace, json
|
|
57
|
+
}: SecretDetails
|
|
58
|
+
) {
|
|
59
|
+
const { $store } = rke2Component;
|
|
60
|
+
|
|
61
|
+
const secretJson = await this.findSecret(rke2Component, {
|
|
62
|
+
generateName,
|
|
63
|
+
upstreamClusterName,
|
|
64
|
+
upstreamNamespace,
|
|
65
|
+
downstreamName,
|
|
66
|
+
downstreamNamespace
|
|
67
|
+
}) || json;
|
|
68
|
+
|
|
69
|
+
return await $store.dispatch('management/create', secretJson);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
private findChartValues({
|
|
73
|
+
versionInfo,
|
|
74
|
+
userChartValues,
|
|
75
|
+
chartVersionKey,
|
|
76
|
+
}: Rke2Component, chartName: string): ChartValues | undefined {
|
|
77
|
+
const chartValues = versionInfo[chartName]?.values;
|
|
78
|
+
|
|
79
|
+
if (!chartValues) {
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
const userValues = userChartValues[chartVersionKey(chartName)];
|
|
83
|
+
|
|
84
|
+
return {
|
|
85
|
+
defaultValues: chartValues,
|
|
86
|
+
userValues,
|
|
87
|
+
combined: merge({}, chartValues || {}, userValues || {})
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Create upstream vsphere cpi secret to sync downstream
|
|
93
|
+
*/
|
|
94
|
+
async handleVsphereCpiSecret(rke2Component: Rke2Component) {
|
|
95
|
+
const generateName = `${ rootGenerateName }cpi-`;
|
|
96
|
+
const downstreamName = 'rancher-vsphere-cpi-credentials';
|
|
97
|
+
const downstreamNamespace = 'kube-system';
|
|
98
|
+
const { value } = rke2Component;
|
|
99
|
+
|
|
100
|
+
// check values for cpi chart has 'use our method' checkbox
|
|
101
|
+
const { userValues, combined } = this.findChartValues(rke2Component, 'rancher-vsphere-cpi') || {};
|
|
102
|
+
|
|
103
|
+
if (!combined?.vCenter?.credentialsSecret?.generate) {
|
|
104
|
+
if (userValues?.vCenter?.username) {
|
|
105
|
+
userValues.vCenter.username = '';
|
|
106
|
+
}
|
|
107
|
+
if (userValues?.vCenter?.password) {
|
|
108
|
+
userValues.vCenter.password = '';
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
// find values needed in cpi chart value - https://github.com/rancher/vsphere-charts/blob/main/charts/rancher-vsphere-cpi/questions.yaml#L16-L42
|
|
115
|
+
const { username, password, host } = combined.vCenter;
|
|
116
|
+
|
|
117
|
+
if (!username || !password || !host) {
|
|
118
|
+
throw new Error('vSphere CPI username, password and host are all required when generating a new secret');
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
// create secret as per https://github.com/rancher/vsphere-charts/blob/main/charts/rancher-vsphere-cpi/templates/secret.yaml
|
|
122
|
+
const upstreamClusterName = value.metadata.name;
|
|
123
|
+
const upstreamNamespace = value.metadata.namespace;
|
|
124
|
+
const secret = await this.findOrCreateSecret(rke2Component, {
|
|
125
|
+
generateName,
|
|
126
|
+
upstreamClusterName,
|
|
127
|
+
upstreamNamespace,
|
|
128
|
+
downstreamName,
|
|
129
|
+
downstreamNamespace,
|
|
130
|
+
json: {
|
|
131
|
+
type: SECRET,
|
|
132
|
+
metadata: {
|
|
133
|
+
namespace: upstreamNamespace,
|
|
134
|
+
generateName,
|
|
135
|
+
labels: {
|
|
136
|
+
'vsphere-cpi-infra': 'secret',
|
|
137
|
+
component: 'rancher-vsphere-cpi-cloud-controller-manager'
|
|
138
|
+
},
|
|
139
|
+
annotations: {
|
|
140
|
+
'provisioning.cattle.io/sync-target-namespace': downstreamNamespace,
|
|
141
|
+
'provisioning.cattle.io/sync-target-name': downstreamName,
|
|
142
|
+
'rke.cattle.io/object-authorized-for-clusters': upstreamClusterName,
|
|
143
|
+
'provisioning.cattle.io/sync-bootstrap': 'true'
|
|
144
|
+
}
|
|
145
|
+
},
|
|
146
|
+
}
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
secret.setData(`${ host }.username`, username);
|
|
150
|
+
secret.setData(`${ host }.password`, password);
|
|
151
|
+
|
|
152
|
+
await secret.save();
|
|
153
|
+
|
|
154
|
+
// reset cpi chart values
|
|
155
|
+
if (!userValues.vCenter.credentialsSecret) {
|
|
156
|
+
userValues.vCenter.credentialsSecret = {};
|
|
157
|
+
}
|
|
158
|
+
userValues.vCenter.credentialsSecret.generate = false;
|
|
159
|
+
userValues.vCenter.credentialsSecret.name = downstreamName;
|
|
160
|
+
userValues.vCenter.username = '';
|
|
161
|
+
userValues.vCenter.password = '';
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* Create upstream vsphere csi secret to sync downstream
|
|
166
|
+
*/
|
|
167
|
+
async handleVsphereCsiSecret(rke2Component: Rke2Component) {
|
|
168
|
+
const generateName = `${ rootGenerateName }csi-`;
|
|
169
|
+
const downstreamName = 'rancher-vsphere-csi-credentials';
|
|
170
|
+
const downstreamNamespace = 'kube-system';
|
|
171
|
+
const { value } = rke2Component;
|
|
172
|
+
|
|
173
|
+
// check values for cpi chart has 'use our method' checkbox
|
|
174
|
+
const { userValues, combined } = this.findChartValues(rke2Component, 'rancher-vsphere-csi') || {};
|
|
175
|
+
|
|
176
|
+
if (!combined?.vCenter?.configSecret?.generate) {
|
|
177
|
+
if (userValues?.vCenter?.username) {
|
|
178
|
+
userValues.vCenter.username = '';
|
|
179
|
+
}
|
|
180
|
+
if (userValues?.vCenter?.password) {
|
|
181
|
+
userValues.vCenter.password = '';
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
return;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
// find values needed in cpi chart value - https://github.com/rancher/vsphere-charts/blob/main/charts/rancher-vsphere-csi/questions.yaml#L1-L36
|
|
188
|
+
const {
|
|
189
|
+
username, password, host, datacenters, port, insecureFlag
|
|
190
|
+
} = combined.vCenter;
|
|
191
|
+
|
|
192
|
+
if (!username || !password || !host || !datacenters) {
|
|
193
|
+
throw new Error('vSphere CSI username, password, host and datacenters are all required when generating a new secret');
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
// This is a copy of https://github.com/rancher/vsphere-charts/blob/a5c99d716df960dc50cf417d9ecffad6b55ca0ad/charts/rancher-vsphere-csi/values.yaml#L12-L21
|
|
197
|
+
// Which makes it's way into the secret via https://github.com/rancher/vsphere-charts/blob/main/charts/rancher-vsphere-csi/templates/secret.yaml#L8
|
|
198
|
+
let configTemplateString = ' [Global]\n cluster-id = {{ required \".Values.vCenter.clusterId must be provided\" (default .Values.vCenter.clusterId .Values.global.cattle.clusterId) | quote }}\n user = {{ .Values.vCenter.username | quote }}\n password = {{ .Values.vCenter.password | quote }}\n port = {{ .Values.vCenter.port | quote }}\n insecure-flag = {{ .Values.vCenter.insecureFlag | quote }}\n\n [VirtualCenter {{ .Values.vCenter.host | quote }}]\n datacenters = {{ .Values.vCenter.datacenters | quote }}';
|
|
199
|
+
|
|
200
|
+
configTemplateString = configTemplateString.replace('{{ required \".Values.vCenter.clusterId must be provided\" (default .Values.vCenter.clusterId .Values.global.cattle.clusterId) | quote }}', `"{{clusterId}}"`);
|
|
201
|
+
configTemplateString = configTemplateString.replace('{{ .Values.vCenter.username | quote }}', `"${ username }"`);
|
|
202
|
+
configTemplateString = configTemplateString.replace('{{ .Values.vCenter.password | quote }}', `"${ password }"`);
|
|
203
|
+
configTemplateString = configTemplateString.replace('{{ .Values.vCenter.port | quote }}', `"${ port }"`);
|
|
204
|
+
configTemplateString = configTemplateString.replace('{{ .Values.vCenter.insecureFlag | quote }}', `"${ insecureFlag }"`);
|
|
205
|
+
configTemplateString = configTemplateString.replace('{{ .Values.vCenter.host | quote }}', `"${ host }"`);
|
|
206
|
+
configTemplateString = configTemplateString.replace('{{ .Values.vCenter.datacenters | quote }}', `"${ datacenters }"`);
|
|
207
|
+
// create secret as per https://github.com/rancher/vsphere-charts/blob/main/charts/rancher-vsphere-csi/templates/secret.yaml
|
|
208
|
+
const upstreamClusterName = value.metadata.name;
|
|
209
|
+
const upstreamNamespace = value.metadata.namespace;
|
|
210
|
+
|
|
211
|
+
const secret = await this.findOrCreateSecret(rke2Component, {
|
|
212
|
+
generateName,
|
|
213
|
+
upstreamClusterName,
|
|
214
|
+
upstreamNamespace,
|
|
215
|
+
downstreamName,
|
|
216
|
+
downstreamNamespace,
|
|
217
|
+
json: {
|
|
218
|
+
type: SECRET,
|
|
219
|
+
metadata: {
|
|
220
|
+
namespace: upstreamNamespace,
|
|
221
|
+
generateName,
|
|
222
|
+
annotations: {
|
|
223
|
+
'provisioning.cattle.io/sync-target-namespace': downstreamNamespace,
|
|
224
|
+
'provisioning.cattle.io/sync-target-name': downstreamName,
|
|
225
|
+
'rke.cattle.io/object-authorized-for-clusters': upstreamClusterName,
|
|
226
|
+
'provisioning.cattle.io/sync-bootstrap': 'true'
|
|
227
|
+
}
|
|
228
|
+
},
|
|
229
|
+
}
|
|
230
|
+
});
|
|
231
|
+
|
|
232
|
+
secret.setData(`csi-vsphere.conf`, configTemplateString);
|
|
233
|
+
|
|
234
|
+
await secret.save();
|
|
235
|
+
|
|
236
|
+
// reset csi chart values
|
|
237
|
+
if (!userValues.vCenter.configSecret) {
|
|
238
|
+
userValues.vCenter.configSecret = {};
|
|
239
|
+
}
|
|
240
|
+
userValues.vCenter.configSecret.generate = false;
|
|
241
|
+
userValues.vCenter.configSecret.name = downstreamName;
|
|
242
|
+
userValues.vCenter.username = '';
|
|
243
|
+
userValues.vCenter.password = '';
|
|
244
|
+
userValues.vCenter.host = '';
|
|
245
|
+
userValues.vCenter.datacenters = '';
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
const utils = new VSphereUtils();
|
|
250
|
+
|
|
251
|
+
export default utils;
|