Skip to content

Commit 53893c4

Browse files
committed
improvements
Signed-off-by: Abhishek Kumar <abhishek.mrt22@gmail.com>
1 parent 32681bb commit 53893c4

File tree

2 files changed

+94
-8
lines changed

2 files changed

+94
-8
lines changed

ui/src/config/section/compute.js

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import { shallowRef, defineAsyncComponent } from 'vue'
1919
import store from '@/store'
2020
import { isZoneCreated } from '@/utils/zone'
2121
import { getAPI, postAPI, getBaseUrl } from '@/api'
22+
import { getLatestKubernetesIsoParams } from '@/utils/acsrepo'
2223

2324
export default {
2425
name: 'compute',
@@ -614,7 +615,6 @@ export default {
614615
run: async () => {
615616
const params = {
616617
name: 'CKS Instance',
617-
displaytext: 'CKS Instance',
618618
cpunumber: 2,
619619
cpuspeed: 1000,
620620
memory: 2048,
@@ -667,13 +667,15 @@ export default {
667667
loadingLabel: 'message.adding.latest.kubernetes.iso',
668668
show: (store) => { return ('addKubernetesSupportedVersion' in store.getters.apis) },
669669
run: async () => {
670-
const params = {
671-
semanticversion: '1.33.1',
672-
url: 'https://download.cloudstack.org/cks/setup-v1.33.1-calico-x86_64.iso',
673-
displaytext: 'CKS Instance',
674-
mincpunumber: 2,
675-
minmemory: 2048
670+
let arch = 'x86_64'
671+
if ('listClusters' in store.getters.apis) {
672+
try {
673+
const json = await getAPI('listClusters', { allocationstate: 'Enabled', page: 1, pagesize: 1 })
674+
const cluster = json?.listclustersresponse?.cluster?.[0] || {}
675+
arch = cluster.architecture || 'x86_64'
676+
} catch (error) {}
676677
}
678+
const params = await getLatestKubernetesIsoParams(arch)
677679
try {
678680
const json = await postAPI('addKubernetesSupportedVersion', params)
679681
if (json?.addkubernetessupportedversionresponse?.kubernetessupportedversion) {
@@ -731,7 +733,7 @@ export default {
731733
if (baseUrl.startsWith('/')) {
732734
url = window.location.origin + baseUrl
733735
}
734-
var params = {
736+
const params = {
735737
name: 'endpoint.url',
736738
value: url
737739
}

ui/src/utils/acsrepo/index.js

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
// Licensed to the Apache Software Foundation (ASF) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The ASF licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
18+
const BASE_KUBERNETES_ISO_URL = 'https://download.cloudstack.org/cks/'
19+
20+
function getDefaultLatestKubernetesIsoParams (arch) {
21+
return {
22+
name: 'v1.33.1-calico-' + arch,
23+
semanticversion: '1.33.1',
24+
url: BASE_KUBERNETES_ISO_URL + 'setup-v1.33.1-calico-' + arch + '.iso',
25+
arch: arch,
26+
mincpunumber: 2,
27+
minmemory: 2048
28+
}
29+
}
30+
31+
/**
32+
* Returns the latest Kubernetes ISO info for the given architecture.
33+
* Falls back to a hardcoded default if fetching fails.
34+
* @param {string} arch
35+
* @returns {Promise<{name: string, semanticversion: string, url: string, arch: string}>}
36+
*/
37+
export async function getLatestKubernetesIsoParams (arch) {
38+
arch = arch || 'x86_64'
39+
try {
40+
const html = await fetch(BASE_KUBERNETES_ISO_URL, { cache: 'no-store' }).then(r => r.text())
41+
42+
// Grab all .iso hrefs from the index page
43+
const hrefs = [...html.matchAll(/href="([^"]+\.iso)"/gi)].map(m => m[1])
44+
45+
// Prefer files that explicitly include the arch (e.g. ...-x86_64.iso)
46+
let isoHrefs = hrefs.filter(h => new RegExp(`${arch}\\.iso$`, 'i').test(h))
47+
48+
// Fallback: older files without arch suffix (e.g. setup-1.28.4.iso)
49+
if (isoHrefs.length === 0) {
50+
isoHrefs = hrefs.filter(h => /setup-\d+\.\d+\.\d+\.iso$/i.test(h))
51+
}
52+
53+
// Map to { name, semanticversion, url, arch }
54+
const entries = isoHrefs.map(h => {
55+
const m = h.match(/setup-(?:v)?(\d+\.\d+\.\d+)(?:-calico)?(?:-(x86_64|arm64))?/i)
56+
return m
57+
? {
58+
name: h.replace('.iso', ''),
59+
semanticversion: m[1],
60+
url: new URL(h, BASE_KUBERNETES_ISO_URL).toString(),
61+
arch: m[2] || arch,
62+
mincpunumber: 2,
63+
minmemory: 2048
64+
}
65+
: null
66+
}).filter(Boolean)
67+
68+
if (entries.length === 0) throw new Error('No matching ISOs found')
69+
70+
// Semver-style sort descending
71+
entries.sort((a, b) => {
72+
const pa = a.semanticversion.split('.').map(Number)
73+
const pb = b.semanticversion.split('.').map(Number)
74+
for (let i = 0; i < 3; i++) {
75+
if ((pb[i] ?? 0) !== (pa[i] ?? 0)) return (pb[i] ?? 0) - (pa[i] ?? 0)
76+
}
77+
return 0
78+
})
79+
80+
return entries[0]
81+
} catch {
82+
return { ...getDefaultLatestKubernetesIsoParams(arch) }
83+
}
84+
}

0 commit comments

Comments
 (0)