forked from rancher/dashboard
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcatalog.js
More file actions
813 lines (661 loc) · 23.2 KB
/
catalog.js
File metadata and controls
813 lines (661 loc) · 23.2 KB
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
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
import { CATALOG, EXPERIMENTAL, DEPRECATED, CATALOG_SORT_OPTIONS } from '@shell/config/types';
import { CATALOG as CATALOG_ANNOTATIONS } from '@shell/config/labels-annotations';
import { addParams } from '@shell/utils/url';
import { allHash, allHashSettled } from '@shell/utils/promise';
import { clone } from '@shell/utils/object';
import { findBy, addObject, filterBy, isArray } from '@shell/utils/array';
import { stringify } from '@shell/utils/error';
import { classify } from '@shell/plugins/dashboard-store/classify';
import { sortBy } from '@shell/utils/sort';
import { ensureRegex } from '@shell/utils/string';
import { isPrerelease } from '@shell/utils/version';
import difference from 'lodash/difference';
import { lookup } from '@shell/plugins/dashboard-store/model-loader';
const ALLOWED_CATEGORIES = [
'Storage',
'Monitoring',
'Database',
'Repository',
'Security',
'Networking',
'PaaS',
'Infrastructure',
'Applications',
];
const CERTIFIED_SORTS = {
[CATALOG_ANNOTATIONS._RANCHER]: 1,
[CATALOG_ANNOTATIONS._EXPERIMENTAL]: 1,
[CATALOG_ANNOTATIONS._PARTNER]: 2,
other: 3,
};
export const APP_STATUS = {
INSTALLED: 'installed',
DEPRECATED: 'deprecated',
UPGRADEABLE: 'upgradeable'
};
export const APP_UPGRADE_STATUS = {
NOT_APPLICABLE: 'not_applicable', // managed by fleet
NO_UPGRADE: 'no_upgrade', // no upgrade found
SINGLE_UPGRADE: 'single_upgrade', // a version available to upgrade to
MULTIPLE_UPGRADES: 'multiple_upgrades' // more than one match found
};
export const WINDOWS = 'windows';
export const LINUX = 'linux';
export const state = function() {
return {
loaded: {},
clusterRepos: [],
namespacedRepos: [],
charts: {},
versionInfos: {},
config: { namespace: 'catalog' },
inStore: undefined,
};
};
export const getters = {
isLoaded(state) {
return (repo) => {
return !!state.loaded[repo._key];
};
},
repos(state) {
const clustered = state.clusterRepos || [];
const namespaced = state.namespacedRepos || [];
return [...clustered, ...namespaced].filter((r) => r.spec?.enabled !== false);
},
// Raw charts
rawCharts(state) {
return state.charts;
},
repo(state, getters) {
return ({ repoType, repoName }) => {
const ary = (repoType === 'cluster' ? state.clusterRepos : state.namespacedRepos);
return findBy(ary, 'metadata.name', repoName);
};
},
charts(state, getters, rootState, rootGetters) {
const repoKeys = getters.repos.map((x) => x._key);
let cluster = rootGetters['currentCluster'];
if ( rootGetters['currentProduct']?.inStore === 'management' ) {
cluster = null;
}
// Filter out charts for repos that are no longer in the store, rather
// than trying to clear them when a repo is removed.
// And ones that are for the wrong kind of cluster
const out = Object.values(state.charts).filter((chart) => {
if ( !repoKeys.includes(chart.repoKey) ) {
return false;
}
if ( cluster && chart.scope && chart.scope !== cluster.scope ) {
return false;
}
return true;
});
return sortBy(out, ['certifiedSort', 'repoName', 'chartName']);
},
chart(state, getters) {
return ({
key, repoType, repoName, chartName, includeHidden, showDeprecated, multiple
}) => {
if ( key && !repoType && !repoName && !chartName) {
const parsed = parseKey(key);
repoType = parsed.repoType;
repoName = parsed.repoName;
chartName = parsed.chartName;
}
let matchingCharts = filterBy(getters.charts, {
repoType,
repoName,
chartName,
deprecated: !!showDeprecated,
});
if ( includeHidden === false ) {
matchingCharts = matchingCharts.filter((x) => !x.hidden);
}
if ( !matchingCharts.length ) {
return;
}
if (multiple) {
return matchingCharts;
}
return matchingCharts[0];
};
},
isInstalled(state, getters, rootState, rootGetters) {
return ({ gvr }) => {
let name, version;
const idx = gvr.indexOf('/');
if ( idx > 0 ) {
name = gvr.substr(0, idx);
version = gvr.substr(idx + 1);
} else {
name = gvr;
}
const inStore = rootGetters['currentProduct'].inStore;
const schema = rootGetters[`${ inStore }/schemaFor`](name);
if ( schema && (!version || schema.attributes.version === version) ) {
return true;
}
return false;
};
},
versionSatisfying(state, getters) {
return ({
repoType, repoName, constraint, chartVersion
}) => {
let name, wantVersion;
const idx = constraint.indexOf('=');
if ( idx > 0 ) {
name = constraint.substr(0, idx);
wantVersion = normalizeVersion(constraint.substr(idx + 1));
} else {
name = constraint;
wantVersion = 'latest';
}
name = name.toLowerCase().trim();
chartVersion = normalizeVersion(chartVersion);
const matching = getters.charts.filter((chart) => chart.chartName.toLowerCase().trim() === name);
if ( !matching.length ) {
return;
}
if ( repoType && repoName ) {
preferSameRepo(matching, repoType, repoName);
}
const chart = matching[0];
let version;
if ( wantVersion === 'latest' ) {
version = chart.versions[0];
} else if ( wantVersion === 'match' || wantVersion === 'matching' ) {
version = chart.versions.find((v) => normalizeVersion(v.version) === chartVersion);
} else {
version = chart.versions.find((v) => normalizeVersion(v.version) === wantVersion);
}
if ( version ) {
return clone(version);
}
};
},
versionProviding(state, getters) {
return ({ repoType, repoName, gvr }) => {
const matching = getters.charts.filter((chart) => chart.provides.includes(gvr) );
if ( !matching.length ) {
return;
}
if ( repoType && repoName ) {
preferSameRepo(matching, repoType, repoName);
}
const version = matching[0].versions.find((version) => version.annotations?.[CATALOG_ANNOTATIONS.PROVIDES] === gvr);
if ( version ) {
return clone(version);
}
};
},
version(state, getters) {
return ({
repoType, repoName, chartName, versionName, showDeprecated
}) => {
const chart = getters['chart']({
repoType, repoName, chartName, showDeprecated
});
if ( !chart ) {
return null;
}
let version;
if ( versionName ) {
version = findBy(chart.versions, 'version', versionName);
} else {
version = chart.versions[0];
}
if ( version ) {
return clone(version);
}
};
},
errors(state) {
return state.errors || [];
},
haveComponent() {
return (name) => {
return getters['type-map/hasCustomChart'](name);
};
},
importComponent(state, getters) {
return (name) => {
return getters['type-map/importChart'](name);
};
},
inStore(state) {
return state.inStore;
},
classify: (state, getters, rootState) => (obj) => {
return lookup(state.config.namespace, obj?.type, obj?.metadata?.name, rootState);
},
};
export const mutations = {
reset(currentState) {
const newState = state();
Object.assign(currentState, newState);
},
setInStore(state, inStore) {
state.inStore = inStore;
},
setRepos(state, { cluster, namespaced }) {
state.clusterRepos = cluster;
state.namespacedRepos = namespaced;
},
setCharts(state, { charts, errors = [], loaded = [] }) {
state.charts = charts;
state.errors = errors;
for ( const repo of loaded ) {
state.loaded[repo._key] = true;
}
},
setVersions(state, versions) {
state.versionInfos = versions;
},
cacheVersion(state, { key, info }) {
state.versionInfos[key] = info;
}
};
export const actions = {
/**
* force: Always refresh catalog's helm repo by re-fetching index.yaml
*
* reset: clear existing charts and version cache
*
* repoKeys: Optional array of specific repo keys (IDs) to refresh. When provided, only these specific
* repos will be fetched, and only their existing charts will be cleared from the cache to avoid
* duplicate chart entries or wiping out unrelated chart data.
*/
async load(ctx, { force, reset, repoKeys = [] } = {}) {
const {
state, getters, rootGetters, commit, dispatch
} = ctx;
let promises = {};
// Installing an app? This is fine (in cluster store)
// Fetching list of cluster templates? This is fine (in management store)
// Installing a cluster template? This isn't fine (in cluster store as per installing app, but if there is no cluster we need to default to management)
const inStore = rootGetters['currentCluster'] ? rootGetters['currentProduct'].inStore : 'management';
if ( rootGetters[`${ inStore }/schemaFor`](CATALOG.CLUSTER_REPO) ) {
promises.cluster = dispatch(`${ inStore }/findAll`, { type: CATALOG.CLUSTER_REPO }, { root: true });
}
if ( rootGetters[`${ inStore }/schemaFor`](CATALOG.REPO) ) {
promises.namespaced = dispatch(`${ inStore }/findAll`, { type: CATALOG.REPO }, { root: true });
}
const hash = await allHash(promises);
// As per comment above, when there are no clusters this will be management. Store it such that it can be used for those cases
commit('setInStore', inStore);
hash.cluster = hash.cluster?.filter((repo) => !(repo?.metadata?.annotations?.[CATALOG_ANNOTATIONS.HIDDEN_REPO] === 'true'));
commit('setRepos', hash);
const repos = getters['repos'];
const loaded = [];
promises = {};
for ( const repo of repos ) {
let shouldLoad = false;
if (repoKeys.length) {
// If repoKeys are explicitly provided (e.g. refreshing a single repo from the UI),
// we ONLY want to load the repos in that array. We intentionally ignore `!getters.isLoaded(repo)`
// here so we don't accidentally fetch other unrelated repos just because they haven't loaded yet.
shouldLoad = repoKeys.includes(repo._key);
} else {
// Default behavior: load if explicitly forced, OR if the repo hasn't been loaded into state yet.
shouldLoad = force === true || !getters.isLoaded(repo);
}
if ( shouldLoad && repo.canLoad ) {
console.info('Loading index for repo', repo.name, `(${ repo._key })`); // eslint-disable-line no-console
promises[repo._key] = repo.followLink('index');
}
}
const res = await allHashSettled(promises);
const charts = reset ? {} : { ...state.charts };
let versionInfos = null;
if (reset) {
versionInfos = {};
} else if (repoKeys.length) {
versionInfos = { ...state.versionInfos };
}
const errors = [];
for ( const key of Object.keys(res) ) {
const obj = res[key];
const repo = findBy(repos, '_key', key);
if ( obj.status === 'rejected' ) {
errors.push(stringify(obj.reason));
continue;
}
// We are targeting specific repos. To prevent duplicate chart versions from appearing,
// we must remove the old charts for this specific repo before appending the newly fetched ones,
// but ONLY if the fetch was successful.
if (repoKeys.length && repoKeys.includes(key)) {
for (const chartKey in charts) {
if (charts[chartKey].repoKey === key) {
delete charts[chartKey];
}
}
// Also clear out cached version info for this repo so we don't display stale READMEs/values
const repoType = repo.type === CATALOG.CLUSTER_REPO ? 'cluster' : 'namespace';
const repoName = repo.metadata.name;
const versionPrefix = `${ repoType }/${ repoName }/`;
for (const versionKey in versionInfos) {
if (versionKey.startsWith(versionPrefix)) {
delete versionInfos[versionKey];
}
}
}
for ( const k in obj.value.entries ) {
for ( const entry of obj.value.entries[k] ) {
addChart(ctx, charts, entry, repo);
}
}
loaded.push(repo);
}
commit('setCharts', {
charts,
errors,
loaded,
});
if (versionInfos) {
commit('setVersions', versionInfos);
}
},
/**
* Globally refreshes all loaded repositories by triggering their refresh actions concurrently,
* bypassing individual catalog loads, and then performs a single, global catalog/load.
*/
async refresh({ getters, commit, dispatch }) {
const promises = getters.repos.map((x) => x.refresh(false));
// @TODO wait for repo state to indicate they're done once the API has that
await Promise.allSettled(promises);
await dispatch('load', { force: true, reset: true });
},
/*
Fetch full information about a specific version of a Helm chart,
including the standard values and README.
*/
async getVersionInfo({ state, getters, commit }, {
repoType, repoName, chartName, versionName
}) {
const key = `${ repoType }/${ repoName }/${ chartName }/${ versionName }`;
let info = state.versionInfos[key];
if ( !info ) {
const repo = getters['repo']({ repoType, repoName });
if ( !repo ) {
throw new Error('Repo not found');
}
info = await repo.followLink('info', {
url: addParams(repo.links.info, {
chartName,
version: versionName
})
});
commit('cacheVersion', { key, info });
}
return info;
},
rehydrate(ctx) {
const { state, commit } = ctx;
const charts = state.charts || {};
Object.entries(state.charts).forEach(([key, chart]) => {
if (chart.__rehydrate) {
charts[key] = classify(ctx, chart);
}
});
commit('setCharts', {
charts,
errors: state.errors,
});
}
};
export function generateKey(repoType, repoName, chartName) {
return `${ repoType }/${ repoName }/${ chartName }`;
}
export function parseKey(key) {
const parts = key.split('/');
return {
repoType: parts[0],
repoName: parts[1],
chartName: parts[2],
};
}
function addChart(ctx, map, chart, repo) {
const repoType = (repo.type === CATALOG.CLUSTER_REPO ? 'cluster' : 'namespace');
const repoName = repo.metadata.name;
const key = generateKey(repoType, repoName, chart.name);
let obj = map[key];
const certifiedAnnotation = chart.annotations?.[CATALOG_ANNOTATIONS.CERTIFIED];
let certified = null;
let sideLabel = null;
if ( repo.isRancher ) {
certified = CATALOG_ANNOTATIONS._RANCHER;
} else if ( repo.isPartner ) {
certified = CATALOG_ANNOTATIONS._PARTNER;
} else {
certified = CATALOG_ANNOTATIONS._OTHER;
}
const isDeprecated = !!chart.deprecated || chart.annotations?.[CATALOG_ANNOTATIONS.DEPRECATED] === 'true';
if ( isDeprecated ) {
sideLabel = DEPRECATED;
} else if ( chart.annotations?.[CATALOG_ANNOTATIONS.EXPERIMENTAL] ) {
sideLabel = EXPERIMENTAL;
} else if (
!repo.isRancherSource &&
certifiedAnnotation &&
certifiedAnnotation !== CATALOG_ANNOTATIONS._RANCHER &&
certified === CATALOG_ANNOTATIONS._OTHER
) {
// But anybody can set the side label
sideLabel = certifiedAnnotation;
}
if ( !obj ) {
if ( ctx ) { }
const primeOnly = chart.annotations?.[CATALOG_ANNOTATIONS.PRIME_ONLY] === 'true';
const experimental = !!chart.annotations?.[CATALOG_ANNOTATIONS.EXPERIMENTAL];
const isRancherRepoFlag = isRancherRepo(repo, chart);
const permittedSystems = getPermittedOSs(chart.annotations, isRancherRepoFlag);
const windowsIncompatible = permittedSystems.length > 0 && !permittedSystems.includes('windows');
const deploysOnWindows = (chart.annotations?.[CATALOG_ANNOTATIONS.DEPLOYED_OS] || '').includes('windows');
const tags = [];
if (primeOnly) {
tags.push(ctx.rootGetters['i18n/withFallback']('generic.primeOnly'));
}
if (experimental) {
tags.push(ctx.rootGetters['i18n/withFallback']('generic.experimental'));
}
if (windowsIncompatible) {
tags.push(ctx.rootGetters['i18n/withFallback']('catalog.charts.windowsIncompatible'));
}
if (deploysOnWindows) {
tags.push(ctx.rootGetters['i18n/withFallback']('catalog.charts.deploysOnWindows'));
}
obj = classify(ctx, {
key,
type: 'chart',
id: key,
certified,
sideLabel,
repoType,
repoName,
repoNameDisplay: ctx.rootGetters['i18n/withFallback'](`catalog.repo.name."${ repoName }"`, null, repoName),
certifiedSort: CERTIFIED_SORTS[certified] || 99,
icon: chart.icon,
color: repo.color,
chartType: chart.annotations?.[CATALOG_ANNOTATIONS.TYPE] || CATALOG_ANNOTATIONS._APP,
chartName: chart.name,
chartNameDisplay: chart.annotations?.[CATALOG_ANNOTATIONS.DISPLAY_NAME] || chart.name,
chartDescription: chart.description,
featured: chart.annotations?.[CATALOG_ANNOTATIONS.FEATURED],
featuredIndex: chart.annotations?.[CATALOG_ANNOTATIONS.FEATURED] ? Number(chart.annotations?.[CATALOG_ANNOTATIONS.FEATURED]) : Number.MAX_SAFE_INTEGER,
repoKey: repo._key,
versions: [],
keywords: chart.keywords || [],
categories: filterCategories(chart.keywords),
deprecated: isDeprecated,
primeOnly,
experimental,
hidden: !!chart.annotations?.[CATALOG_ANNOTATIONS.HIDDEN],
targetNamespace: chart.annotations?.[CATALOG_ANNOTATIONS.NAMESPACE],
targetName: chart.annotations?.[CATALOG_ANNOTATIONS.RELEASE_NAME],
scope: chart.annotations?.[CATALOG_ANNOTATIONS.SCOPE],
provides: [],
windowsIncompatible,
deploysOnWindows,
isRancherRepo: isRancherRepoFlag,
tags
});
map[key] = obj;
}
chart.key = `${ key }/${ chart.version }`;
chart.repoType = repoType;
chart.repoName = repoName;
const provides = chart.annotations?.[CATALOG_ANNOTATIONS.PROVIDES];
if ( provides ) {
addObject(obj.provides, provides);
}
obj.versions.push(chart);
if (!obj.durationSinceRelease) {
obj.durationSinceRelease = Date.now() - new Date(obj.versions[0].created).getTime();
}
}
function preferSameRepo(matching, repoType, repoName) {
matching.sort((a, b) => {
const aSameRepo = a.repoType === repoType && a.repoName === repoName ? 1 : 0;
const bSameRepo = b.repoType === repoType && b.repoName === repoName ? 1 : 0;
if ( aSameRepo && !bSameRepo ) {
return -1;
} else if ( !aSameRepo && bSameRepo ) {
return 1;
}
return 0;
});
}
function normalizeVersion(v) {
return v.replace(/^v/i, '').toLowerCase().trim();
}
function filterCategories(categories) {
categories = (categories || []).map((x) => normalizeCategory(x));
const out = [];
for ( const c of ALLOWED_CATEGORIES ) {
if ( categories.includes(normalizeCategory(c)) ) {
addObject(out, c);
}
}
return out;
}
function normalizeCategory(c) {
return c.replace(/\s+/g, '').toLowerCase();
}
export function normalizeFilterQuery(value) {
if (Array.isArray(value)) {
return value.map((v) => v.toLowerCase());
} else if (value) {
return [value.toLowerCase()];
}
return undefined;
}
/*
catalog.cattle.io/deplys-on-os: OS -> requires global.cattle.OS.enabled: true
default: nothing
catalog.cattle.io/permits-os: OS -> will break on clusters containing nodes that are not OS
default if not found: catalog.cattle.io/permits-os: linux
*/
export function compatibleVersionsFor(chart, os, includePrerelease = true) {
const versions = chart.versions;
if (os && !isArray(os)) {
os = [os];
}
return versions.filter((ver) => {
const osPermitted = getPermittedOSs(ver?.annotations, chart?.isRancherRepo);
if ( !includePrerelease && isPrerelease(ver.version) ) {
return false;
}
if ( !os || osPermitted.length === 0 || difference(os, osPermitted).length === 0) {
return true;
}
return false;
});
}
export function filterAndArrangeCharts(charts, {
clusterProvider = '',
operatingSystems,
category,
tag,
searchQuery,
sort,
showDeprecated = false,
showHidden = false,
showPrerelease = true,
hideRepos = [],
showRepos = [],
showTypes = [],
hideTypes = [],
} = {}) {
const out = charts.filter((c) => {
if (
( c.deprecated && !showDeprecated ) ||
( c.hidden && !showHidden ) ||
( hideRepos?.length && hideRepos.includes(c.repoKey) ) ||
( showRepos?.length && !showRepos.includes(c.repoKey) ) ||
( hideTypes?.length && hideTypes.includes(c.chartType) ) ||
( showTypes?.length && !showTypes.includes(c.chartType) ) ||
(c.chartName === 'rancher-wins-upgrader' && clusterProvider === 'rke2')
) {
return false;
}
if (compatibleVersionsFor(c, operatingSystems, showPrerelease).length <= 0) {
// There's no versions compatible with the specified os
return false;
}
if (category?.length && !c.categories.some((cat) => category.includes(cat.toLowerCase()))) {
// The category filter doesn't match
return false;
}
if (tag?.length && !c.tags.some((t) => tag.includes(t.toLowerCase()))) {
// The tag filter doesn't match
return false;
}
if ( searchQuery ) {
// The search filter doesn't match
const searchTokens = searchQuery.split(/\s*[, ]\s*/).map((x) => ensureRegex(x, false));
const chartDescription = c.chartDescription || '';
const keywords = c.keywords || [];
for (const token of searchTokens) {
const nameMatch = c.chartNameDisplay.match(token);
const descMatch = chartDescription.match(token);
const keywordMatch = keywords.some((k) => k.match(token));
if (!nameMatch && !descMatch && !keywordMatch) {
return false;
}
}
}
return true;
});
if (sort === CATALOG_SORT_OPTIONS.RECOMMENDED) {
return sortBy(out, ['featuredIndex', 'certifiedSort', 'repoName', 'chartNameDisplay']);
}
if (sort === CATALOG_SORT_OPTIONS.LAST_UPDATED_DESC) {
return sortBy(out, ['durationSinceRelease', 'featuredIndex', 'certifiedSort', 'repoName', 'chartNameDisplay']);
}
if (sort === CATALOG_SORT_OPTIONS.ALPHABETICAL_ASC) {
return sortBy(out, ['chartNameDisplay', 'featuredIndex', 'certifiedSort', 'repoName']);
}
if (sort === CATALOG_SORT_OPTIONS.ALPHABETICAL_DESC) {
return sortBy(out, ['chartNameDisplay'], true);
}
return sortBy(out, ['certifiedSort', 'repoName', 'chartNameDisplay']);
}
/**
* Detects if a repository is a Rancher repository.
*/
export function isRancherRepo(repo, chart) {
return !!(chart?.isRancherRepo || repo?.isRancherSource);
}
/**
* Returns an array of permitted operating systems for a given chart or version.
* If the chart explicitly defines permitted OSs via annotation, those are returned.
* Otherwise, if the chart is from a Rancher repository, it defaults to Linux.
* External charts with no annotations have no OS restrictions (returns empty array).
*/
export function getPermittedOSs(annotations, isRancher) {
const permittedOs = annotations?.[CATALOG_ANNOTATIONS.PERMITTED_OS];
const fallbackOs = isRancher ? LINUX : '';
return (permittedOs || fallbackOs).split(',').filter(Boolean);
}