-
Notifications
You must be signed in to change notification settings - Fork 266
/
Copy pathcatalog.cattle.io.app.js
238 lines (188 loc) · 5.67 KB
/
catalog.cattle.io.app.js
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
126
127
128
129
130
131
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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
import Vue from 'vue';
import {
NAMESPACE, NAME, REPO, REPO_TYPE, CHART, VERSION, _VIEW, FROM_TOOLS, _FLAGGED
} from '@/config/query-params';
import { CATALOG as CATALOG_ANNOTATIONS, FLEET } from '@/config/labels-annotations';
import { compare, isPrerelease, sortable } from '@/utils/version';
import { filterBy } from '@/utils/array';
import { CATALOG } from '@/config/types';
import { SHOW_PRE_RELEASE } from '@/store/prefs';
export default {
showMasthead() {
return (mode) => {
return mode === _VIEW;
};
},
applyDefaults() {
return () => {
Vue.set(this, 'disableOpenApiValidation', false);
Vue.set(this, 'noHooks', false);
Vue.set(this, 'skipCRDs', false);
Vue.set(this, 'timeout', 300);
Vue.set(this, 'wait', true);
};
},
_availableActions() {
const out = this._standardActions;
const upgrade = {
action: 'goToUpgrade',
enabled: true,
icon: 'icon icon-fw icon-edit',
label: this.t('catalog.install.action.goToUpgrade'),
};
out.unshift(upgrade);
return out;
},
matchingChart() {
return (includeHidden) => {
const chart = this.spec?.chart;
if ( !chart ) {
return;
}
const chartName = chart.metadata?.name;
const preferRepoType = chart.metadata?.annotations?.[CATALOG_ANNOTATIONS.SOURCE_REPO_TYPE];
const preferRepoName = chart.metadata?.annotations?.[CATALOG_ANNOTATIONS.SOURCE_REPO_NAME];
const match = this.$rootGetters['catalog/chart']({
chartName,
preferRepoType,
preferRepoName,
includeHidden
});
return match;
};
},
currentVersion() {
return this.spec?.chart?.metadata?.version;
},
upgradeAvailable() {
// false = does not apply (managed by fleet)
// null = no upgrade found
// object = version available to upgrade to
if ( this.spec?.chart?.metadata?.annotations?.[FLEET.BUNDLE_ID] ) {
// Things managed by fleet shouldn't show ugrade available even if there might be.
return false;
}
const chart = this.matchingChart(false);
if ( !chart ) {
return null;
}
const isWindows = this.$rootGetters['currentCluster'].providerOs === 'windows';
const showPreRelease = this.$rootGetters['prefs/get'](SHOW_PRE_RELEASE);
const thisVersion = this.spec?.chart?.metadata?.version;
let versions = chart.versions;
if (!showPreRelease) {
versions = chart.versions.filter(v => !isPrerelease(v.version));
}
const newestChart = versions?.[0];
const newestVersion = newestChart?.version;
if ( !thisVersion || !newestVersion ) {
return null;
}
if (isWindows && newestChart?.annotations?.['catalog.cattle.io/os'] === 'linux') {
return null;
} else if (!isWindows && newestChart?.annotations?.['catalog.cattle.io/os'] === 'windows') {
return null;
}
if ( compare(thisVersion, newestVersion) < 0 ) {
return cleanupVersion(newestVersion);
}
return null;
},
upgradeAvailableSort() {
const version = this.upgradeAvailable;
if ( !version ) {
return '~'; // Tilde sorts after all numbers and letters
}
return sortable(version);
},
goToUpgrade() {
return (forceVersion, fromTools) => {
const match = this.matchingChart(true);
const versionName = this.spec?.chart?.metadata?.version;
const query = {
[NAMESPACE]: this.metadata.namespace,
[NAME]: this.metadata.name,
[VERSION]: forceVersion || versionName,
};
if ( match ) {
query[REPO] = match.repoName;
query[REPO_TYPE] = match.repoType;
query[CHART] = match.chartName;
}
if ( fromTools ) {
query[FROM_TOOLS] = _FLAGGED;
}
this.currentRouter().push({
name: 'c-cluster-apps-charts-install',
params: {
product: this.$rootGetters['productId'],
cluster: this.$rootGetters['clusterId'],
},
query,
});
};
},
details() {
const t = this.$rootGetters['i18n/t'];
const first = this.spec?.info?.firstDeployed;
const last = this.spec?.info?.lastDeployed;
if ( first && last && first !== last ) {
return [
{
label: t('model."catalog.cattle.io.app".lastDeployed'),
formatter: 'LiveDate',
content: last,
},
];
}
return [];
},
nameDisplay() {
const out = this.spec?.name || this.metadata?.name || this.id || '';
return out;
},
chartDisplay() {
const name = this.spec?.chart?.metadata?.name || '?';
return `${ name }:${ this.versionDisplay }`;
},
versionDisplay() {
return cleanupVersion(this.spec?.chart?.metadata?.version);
},
versionSort() {
return sortable(this.versionDisplay);
},
remove() {
return async(opt = {}) => {
const res = await this.doAction('uninstall', opt);
const operation = await this.$dispatch('find', {
type: CATALOG.OPERATION,
id: `${ res.operationNamespace }/${ res.operationName }`
});
try {
await operation.waitForLink('logs');
operation.openLogs();
} catch (e) {
// The wait times out eventually, move on...
}
};
},
canDelete() {
return this.hasAction('uninstall');
},
deployedResources() {
return filterBy(this.metadata?.relationships || [], 'rel', 'helmresource');
},
};
function cleanupVersion(version) {
if ( !version ) {
return '?';
}
if ( version.match(/^v/i) ) {
version = version.substr(1);
}
const hash = version.match(/[0-9a-f]{32,}/);
if ( hash ) {
version = version.replace(hash[0], hash[0].substr(0, 7));
}
return version;
}