Skip to content

Commit 435629f

Browse files
authored
fix: ignore v prefix in kubernetes version (#686)
* fix: check for v prefix on kubernetes version
1 parent 9a23a77 commit 435629f

File tree

2 files changed

+22
-8
lines changed

2 files changed

+22
-8
lines changed

src/utils/helpers.test.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,10 @@ describe('checkAgainstK8sVersion', () => {
163163
expect(checkAgainstK8sVersion(update, '1.26.1')).toBe(true)
164164
})
165165

166+
it('returns true if currentVersion is in supported_k8s_versions with patch version and has prefix', () => {
167+
expect(checkAgainstK8sVersion(update, 'v1.26.1')).toBe(true)
168+
})
169+
166170
it('returns false if currentVersion is not in supported_k8s_versions', () => {
167171
expect(checkAgainstK8sVersion(update, '1.28')).toBe(false)
168172
})

src/utils/helpers.ts

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,6 @@ export function selectDisplayUpdates(allUpdates: DisplayUpdate[], currentVersion
6363
return filteredUpdates
6464
}
6565

66-
export function latestApplicableUpdateVersion(versions: VersionInfo[], clusterK8sVersion: string) {
67-
const applicableUpdates = versions.filter((update) => update.supported_k8s_versions.includes(clusterK8sVersion))
68-
return applicableUpdates.length > 0 ? applicableUpdates[applicableUpdates.length - 1] : undefined
69-
}
70-
7166
export function valueArrayToObject(
7267
array?:
7368
| {
@@ -92,13 +87,28 @@ export function mapObjectToKeyValueArray(obj?: Record<string, string>): { key: s
9287
return Object.entries(obj).map(([key, value]) => ({ key, value }))
9388
}
9489

90+
function normalizeVersion(version: string): string {
91+
return version.replace(/^v/, '')
92+
}
93+
94+
function stripPatchVersion(version: string): string {
95+
const parts = normalizeVersion(version).split('.')
96+
return parts.slice(0, 2).join('.')
97+
}
98+
99+
export function latestApplicableUpdateVersion(versions: VersionInfo[], clusterK8sVersion: string) {
100+
const applicableUpdates = versions.filter((update) =>
101+
update.supported_k8s_versions.includes(stripPatchVersion(clusterK8sVersion)),
102+
)
103+
return applicableUpdates.length > 0 ? applicableUpdates[applicableUpdates.length - 1] : undefined
104+
}
105+
95106
export function checkAgainstK8sVersion(update: VersionInfo, currentVersion: string) {
96107
const supportedVersions = update.supported_k8s_versions
97108

98109
if (!supportedVersions || supportedVersions.length === 0) return false
99-
100-
// Check for exact match or match ignoring patch version
101-
const currentVersionMajorMinor = currentVersion.split('.').slice(0, 2).join('.')
110+
// Remove 'v' prefix if present and extract major.minor version
111+
const currentVersionMajorMinor = stripPatchVersion(currentVersion)
102112

103113
return supportedVersions.includes(currentVersionMajorMinor)
104114
}

0 commit comments

Comments
 (0)