Skip to content

Commit 383826a

Browse files
momesginMo Mesgin
andauthored
[backport v2.14.2] Refine matching charts for apps (#17531)
Backports PR #16568 to release-2.14. Refines the logic for identifying matching charts for installed applications to improve the accuracy of upgrade status detection. Co-authored-by: Mo Mesgin <mmesgin@Mos-M2-MacBook-Pro.local>
1 parent 4212397 commit 383826a

2 files changed

Lines changed: 36 additions & 18 deletions

File tree

shell/models/__tests__/catalog.cattle.io.app.test.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,19 @@ const certManagerOfficialMatchingChart2 = {
8787
}]
8888
};
8989

90+
// Simulates the chart data fetched from the repository where the home URL has changed in newer versions
91+
// AND the older installed version has been dropped/replaced from the repository index.
92+
const certManagerOfficialMatchingChartNewHomeOnly = {
93+
name: chartName,
94+
repoName: certManagerOfficial.repoName,
95+
versions: [{
96+
version: latestVersion,
97+
home: certManagerOfficial.home,
98+
repoName: certManagerOfficial.repoName,
99+
annotations: {},
100+
}]
101+
};
102+
90103
const installedCertManagerAppCoFromRancherUI = {
91104
metadata: {
92105
annotations: { [CATALOG_ANNOTATIONS.SOURCE_REPO_NAME]: appCo.repoName },
@@ -130,7 +143,8 @@ describe('class CatalogApp', () => {
130143
[installedCertManagerOfficialFromRancherUI, [], APP_UPGRADE_STATUS.NO_UPGRADE],
131144
[installedCertManagerOfficialFromRancherUI, [certManagerOfficialMatchingChart1], APP_UPGRADE_STATUS.SINGLE_UPGRADE],
132145
[installedCertManagerOfficialFromRancherUI, [certManagerOfficialMatchingChart1, appCoMatchingChart1], APP_UPGRADE_STATUS.SINGLE_UPGRADE],
133-
[installedCertManagerOfficialFromRancherUI, [certManagerOfficialMatchingChart1, certManagerOfficialMatchingChart2], APP_UPGRADE_STATUS.MULTIPLE_UPGRADES]
146+
[installedCertManagerOfficialFromRancherUI, [certManagerOfficialMatchingChart1, certManagerOfficialMatchingChart2], APP_UPGRADE_STATUS.MULTIPLE_UPGRADES],
147+
[installedCertManagerOfficialFromRancherUI, [certManagerOfficialMatchingChartNewHomeOnly], APP_UPGRADE_STATUS.SINGLE_UPGRADE]
134148
];
135149

136150
it.each(testCases)('should return the correct upgrade status', (installedChart: Object, matchingCharts: any, expected: any) => {

shell/models/catalog.cattle.io.app.js

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -78,28 +78,32 @@ export default class CatalogApp extends SteveModel {
7878
return [];
7979
}
8080

81-
// Filtering matches by verifying if the current version is in the matched chart's available versions, and that the home value matches as well
82-
const thisHome = chart?.metadata?.home;
83-
const bestMatches = matchingCharts.filter(({ versions }) => {
84-
// First checking if the latest version has the same home value
85-
if (thisHome === versions[0]?.home) {
86-
return true;
87-
}
81+
if (!repoName || matchingCharts.length > 1) {
82+
// Filtering matches by verifying if the current version is in the matched chart's available versions, and that the home value matches as well
83+
const thisHome = chart?.metadata?.home;
84+
const bestMatches = matchingCharts.filter(({ versions }) => {
85+
// First checking if the latest version has the same home value
86+
if (thisHome === versions[0]?.home) {
87+
return true;
88+
}
8889

89-
for (let i = 1; i < versions.length; i++) {
90-
const { version, home } = versions[i];
90+
for (let i = 1; i < versions.length; i++) {
91+
const { version, home } = versions[i];
9192

92-
// Finding the exact version, if the version is not there, then most likely it's not a match
93-
// if the exact version is found, then we can compare the home value
94-
if (version === this.currentVersion && (home === thisHome)) {
95-
return true;
93+
// Finding the exact version, if the version is not there, then most likely it's not a match
94+
// if the exact version is found, then we can compare the home value
95+
if (version === this.currentVersion && (home === thisHome)) {
96+
return true;
97+
}
9698
}
97-
}
9899

99-
return false;
100-
});
100+
return false;
101+
});
102+
103+
return bestMatches;
104+
}
101105

102-
return bestMatches;
106+
return matchingCharts;
103107
}
104108

105109
get currentVersion() {

0 commit comments

Comments
 (0)