From 3e9a0a4377b48612adefba850aa66b7b8bcf1f3f Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Mon, 26 May 2025 15:19:28 +0800 Subject: [PATCH] Refactor feature flags structure (backport #276) (#314) * Refactor feature flags structure (#276) * refactor feature flags structure Signed-off-by: Andy Lee * Replace with FEATURE_FLAGS and valid and sort versions Signed-off-by: Andy Lee --------- Signed-off-by: Andy Lee (cherry picked from commit f8079c592485c51155f59037b395c611c04d327a) # Conflicts: # pkg/harvester/config/feature-flags.js * resolve conflict Signed-off-by: Andy Lee --------- Signed-off-by: Andy Lee Co-authored-by: Andy Lee --- pkg/harvester/config/feature-flags.js | 120 ++++++++++++-------------- 1 file changed, 53 insertions(+), 67 deletions(-) diff --git a/pkg/harvester/config/feature-flags.js b/pkg/harvester/config/feature-flags.js index 61638d17..e30f75dc 100644 --- a/pkg/harvester/config/feature-flags.js +++ b/pkg/harvester/config/feature-flags.js @@ -1,69 +1,55 @@ -// https://github.com/harvester/dashboard/releases/tag/v1.3.0 -const featuresV130 = [ - 'supportHarvesterClusterVersion' -]; +import semver from 'semver'; -// https://github.com/harvester/dashboard/releases/tag/v1.3.1 -const featuresV131 = [ - ...featuresV130, - 'autoRotateRke2CertsSetting', - 'supportBundleNodeCollectionTimeoutSetting' -]; - -// https://github.com/harvester/dashboard/releases/tag/v1.3.2 -const featuresV132 = [ - ...featuresV131, - 'kubeconfigDefaultTokenTTLMinutesSetting', - 'improveMaintenanceMode', -]; - -// TODO: add v1.3.3 official release note -// https://github.com/harvester/dashboard/releases/tag/v1.3.3-dev-20250105 -const featuresV133 = [ - ...featuresV132, -]; - -// https://github.com/harvester/dashboard/releases/tag/v1.4.0 -const featuresV140 = [ - ...featuresV133, - 'cpuPinning', - 'usbPassthrough', - 'volumeEncryption', - 'schedulingVMBackup', - 'vmSnapshotQuota', - 'longhornV2LVMSupport', - 'improveMaintenanceMode', -]; - -// https://github.com/harvester/dashboard/releases/tag/v1.4.1 -const featuresV141 = [ - ...featuresV140 -]; - -// TODO: add v1.4.2 official release note -const featuresV142 = [ - ...featuresV141, - 'refreshIntervalInSecond', - 'allowEmptySnapshotClassName' -]; - -// TODO: add v1.5.0 official release note -const featuresV150 = [ - ...featuresV142, - 'tpmPersistentState', - 'efiPersistentState', - 'untaggedNetworkSetting', - 'skipSingleReplicaDetachedVol', - 'thirdPartyStorage' -]; - -export const RELEASE_FEATURES = { - 'v1.3.0': featuresV130, - 'v1.3.1': featuresV131, - 'v1.3.2': featuresV132, - 'v1.3.3': featuresV133, - 'v1.4.0': featuresV140, - 'v1.4.1': featuresV141, - 'v1.4.2': featuresV142, - 'v1.5.0': featuresV150 +const FEATURE_FLAGS = { + 'v1.3.0': [ + 'supportHarvesterClusterVersion' + ], + 'v1.3.1': [ + 'autoRotateRke2CertsSetting', + 'supportBundleNodeCollectionTimeoutSetting' + ], + 'v1.3.2': [ + 'kubeconfigDefaultTokenTTLMinutesSetting', + 'improveMaintenanceMode', + ], + 'v1.3.3': [], + 'v1.4.0': [ + 'cpuPinning', + 'usbPassthrough', + 'volumeEncryption', + 'schedulingVMBackup', + 'vmSnapshotQuota', + 'longhornV2LVMSupport', + 'improveMaintenanceMode', + ], + 'v1.4.1': [], + 'v1.4.2': [ + 'refreshIntervalInSecond', + 'allowEmptySnapshotClassName' + ], + 'v1.4.3': [], + 'v1.5.0': [ + 'tpmPersistentState', + 'efiPersistentState', + 'untaggedNetworkSetting', + 'skipSingleReplicaDetachedVol', + 'thirdPartyStorage' + ], + 'v1.5.1': [], }; + +const generateFeatureFlags = () => { + const versions = [...Object.keys(FEATURE_FLAGS)].filter((version) => semver.valid(version)).sort(semver.compare); + + const generatedFlags = {}; + + versions.forEach((version, index) => { + const previousVersion = versions[index - 1]; + + generatedFlags[version] = previousVersion ? [...generatedFlags[previousVersion], ...FEATURE_FLAGS[version]] : [...FEATURE_FLAGS[version]]; + }); + + return generatedFlags; +}; + +export const RELEASE_FEATURES = generateFeatureFlags();