From bf799bc5c328c6e5b262e0342d4ee6201cf1c672 Mon Sep 17 00:00:00 2001 From: donniean Date: Mon, 6 Nov 2023 11:45:39 +0800 Subject: [PATCH] fix: HPA api response 404 (#4249) fix: hpa api response 404 Signed-off-by: donniean --- server/services/session.js | 1 + src/stores/workload/hpa.js | 18 ++++++++++++++++++ src/utils/constants.js | 1 + src/utils/workload.js | 1 - 4 files changed, 20 insertions(+), 1 deletion(-) diff --git a/server/services/session.js b/server/services/session.js index 522b791516c..ba8801cb3ef 100644 --- a/server/services/session.js +++ b/server/services/session.js @@ -295,6 +295,7 @@ const getKSConfig = async token => { resp = { ...config } if (version) { resp.ksVersion = version.gitVersion + resp.k8sVersion = get(version, 'kubernetes.gitVersion') } } catch (error) { console.error(error) diff --git a/src/stores/workload/hpa.js b/src/stores/workload/hpa.js index d5207ca991d..39f2e4a3289 100644 --- a/src/stores/workload/hpa.js +++ b/src/stores/workload/hpa.js @@ -18,13 +18,31 @@ import { action } from 'mobx' +import { compareVersion } from 'utils' +import { API_VERSIONS } from 'utils/constants' import { getHpaFormattedData } from 'utils/workload' import Base from '../base' +const VERSION = 'v1.23.0' + export default class HpaStore extends Base { module = 'horizontalpodautoscalers' + get apiVersion() { + const k8sVersion = globals?.ksConfig?.k8sVersion + const result = compareVersion(VERSION, k8sVersion) + let module = '' + + if (result > 0) { + module = 'horizontalpodautoscalers_outdated' + } else { + module = this.module + } + + return API_VERSIONS[module] || '' + } + @action create(data, params) { return this.submitting( diff --git a/src/utils/constants.js b/src/utils/constants.js index 2d6c2ef66ef..873b4006d43 100644 --- a/src/utils/constants.js +++ b/src/utils/constants.js @@ -985,6 +985,7 @@ export const API_VERSIONS = { strategies: 'apis/servicemesh.kubesphere.io/v1alpha2', servicepolicies: 'apis/servicemesh.kubesphere.io/v1alpha2', horizontalpodautoscalers: 'apis/autoscaling/v2', + horizontalpodautoscalers_outdated: 'apis/autoscaling/v2beta2', customresourcedefinitions: 'apis/apiextensions.k8s.io/v1', clusters: 'apis/cluster.kubesphere.io/v1alpha1', workspaces: 'apis/tenant.kubesphere.io/v1alpha2', diff --git a/src/utils/workload.js b/src/utils/workload.js index cd6b2c00b98..4c160e45f25 100644 --- a/src/utils/workload.js +++ b/src/utils/workload.js @@ -73,7 +73,6 @@ export const getHpaFormattedData = (formData = {}) => { : [] const data = merge(formData, { - apiVersion: 'autoscaling/v2', kind: 'HorizontalPodAutoscaler', metadata: { annotations: {