Skip to content

Commit b449e8a

Browse files
committed
address pr comments
1 parent f0bf9f7 commit b449e8a

File tree

3 files changed

+26
-40
lines changed

3 files changed

+26
-40
lines changed

pkg/elemental/components/BuildMedia.vue

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { Banner } from '@components/Banner';
44
import AsyncButton from '@shell/components/AsyncButton';
55
import { randomStr, CHARSET } from '@shell/utils/string';
66
import { ELEMENTAL_SCHEMA_IDS } from '../config/elemental-types';
7-
import { semverVersionCheck, getOperatorVersion, getGatedFeature, BUILD_MEDIA_RAW_SUPPORT } from '../utils/feature-versioning';
7+
import { getOperatorVersion, checkGatedFeatureCompatibility, BUILD_MEDIA_RAW_SUPPORT } from '../utils/feature-versioning';
88
99
const MEDIA_TYPES = {
1010
RAW: {
@@ -54,17 +54,13 @@ export default {
5454
this.managedOsVersions = await this.$store.dispatch('management/findAll', { type: ELEMENTAL_SCHEMA_IDS.MANAGED_OS_VERSIONS });
5555
5656
this.operatorVersion = await getOperatorVersion(this.$store);
57-
this.gatedFeature = getGatedFeature(this.resource, this.mode, BUILD_MEDIA_RAW_SUPPORT);
58-
this.buildMediaGatingVersion = this.gatedFeature?.minOperatorVersion || '';
5957
},
6058
data() {
6159
return {
6260
seedImagesList: [],
6361
managedOsVersions: [],
6462
filteredManagedOsVersions: [],
6563
operatorVersion: '',
66-
gatedFeature: {},
67-
buildMediaGatingVersion: '',
6864
buildMediaOsVersions: [],
6965
buildMediaTypes: [
7066
{ label: MEDIA_TYPES.ISO.label, value: MEDIA_TYPES.ISO.type },
@@ -96,17 +92,13 @@ export default {
9692
},
9793
computed: {
9894
isRawDiskImageBuildSupported() {
99-
if (this.operatorVersion && this.buildMediaGatingVersion) {
100-
const check = semverVersionCheck(this.operatorVersion, this.buildMediaGatingVersion);
95+
const check = checkGatedFeatureCompatibility(this.resource, this.mode, BUILD_MEDIA_RAW_SUPPORT, this.operatorVersion);
10196
102-
if (!check) {
103-
this.buildMediaTypeSelected = MEDIA_TYPES.ISO.type; // eslint-disable-line vue/no-side-effects-in-computed-properties
104-
}
105-
106-
return check;
97+
if (!check) {
98+
this.buildMediaTypeSelected = MEDIA_TYPES.ISO.type; // eslint-disable-line vue/no-side-effects-in-computed-properties
10799
}
108100
109-
return false;
101+
return check;
110102
},
111103
registrationEndpointsOptions() {
112104
const activeRegEndpoints = this.registrationEndpointList.filter(item => item.state === 'active');

pkg/elemental/edit/elemental.cattle.io.machineregistration.vue

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import { exceptionToErrorsArray } from '@shell/utils/error';
1616
import Tabbed from '@shell/components/Tabbed/index.vue';
1717
import Tab from '@shell/components/Tabbed/Tab.vue';
1818
19-
import { semverVersionCheck, getOperatorVersion, getGatedFeature, MACH_REG_CONFIG_DEFAULTS } from '../utils/feature-versioning';
19+
import { getOperatorVersion, checkGatedFeatureCompatibility, MACH_REG_CONFIG_DEFAULTS } from '../utils/feature-versioning';
2020
import { OLD_DEFAULT_CREATION_YAML, DEFAULT_CREATION_YAML } from '../models/elemental.cattle.io.machineregistration';
2121
2222
export default {
@@ -51,10 +51,8 @@ export default {
5151
// in CREATE mode, since YAMLEditor doesn't live update, we need to force a re-render of the component for it to update
5252
if (this.mode === _CREATE) {
5353
const operatorVersion = await getOperatorVersion(this.$store);
54-
const gatedFeature = getGatedFeature(this.resource, this.mode, MACH_REG_CONFIG_DEFAULTS);
55-
const minOperatorVersion = gatedFeature?.minOperatorVersion || '';
5654
57-
this.newCloudConfigcompatibilityCheck = semverVersionCheck(operatorVersion, minOperatorVersion);
55+
this.newCloudConfigcompatibilityCheck = checkGatedFeatureCompatibility(this.resource, this.mode, MACH_REG_CONFIG_DEFAULTS, operatorVersion);
5856
5957
if (!this.value.spec) {
6058
this.value.spec = this.newCloudConfigcompatibilityCheck ? DEFAULT_CREATION_YAML : OLD_DEFAULT_CREATION_YAML;
@@ -70,8 +68,7 @@ export default {
7068
cloudConfig: typeof this.value.spec === 'string' ? this.value.spec : saferDump(this.value.spec),
7169
newCloudConfigcompatibilityCheck: false,
7270
yamlErrors: null,
73-
isFormValid: true,
74-
gatedFeature: {}
71+
isFormValid: true
7572
};
7673
},
7774
watch: {

pkg/elemental/utils/feature-versioning.ts

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ interface FeaturesGatingConfig {
1212
features: string[],
1313
}
1414

15+
// features to be gated to specific operator versions
1516
export const MACH_REG_CONFIG_DEFAULTS:string = 'machine-reg-config-defaults';
1617
export const BUILD_MEDIA_RAW_SUPPORT:string = 'build-media-raw-support';
1718

@@ -38,8 +39,7 @@ const FEATURES_GATING:FeaturesGatingConfig[] = [
3839

3940
/**
4041
* Get the current elemental-operator version
41-
* @param any store
42-
* @param any alreadyInstalledApps
42+
* @param any Vue store
4343
* @returns Promise<string | void>
4444
*/
4545
export async function getOperatorVersion(store: any): Promise<string | void> {
@@ -54,26 +54,23 @@ export async function getOperatorVersion(store: any): Promise<string | void> {
5454
}
5555

5656
/**
57-
* Get the gated feature based on resource + mode + string
58-
* @param string
59-
* @param string
60-
* @param string
61-
* @returns FeaturesGatingConfig | {} | void
57+
* Check the gated feature compatibility with the current Elemental Operator version installed
58+
* @param string resource type (ex: Deployment)
59+
* @param string UI mode (ex: edit, create, view)
60+
* @param string Elemental feature (ex: Build media, cloud config)
61+
* @param string Elemental Operator version
62+
* @returns Boolean
6263
*/
63-
export function getGatedFeature(resource: string, mode: string, feature: string): FeaturesGatingConfig | {} | void {
64-
if (resource && mode) {
65-
return FEATURES_GATING.find(feat => feat.area === resource && feat.mode.includes(mode) && feat.features.includes(feature));
66-
}
64+
export function checkGatedFeatureCompatibility(resource: string, mode: string, feature: string, operatorVersion: string): Boolean {
65+
if (resource && mode && feature) {
66+
const gatedFeature = FEATURES_GATING.find(feat => feat.area === resource && feat.mode.includes(mode) && feat.features.includes(feature));
6767

68-
return {};
69-
}
68+
if (!gatedFeature?.minOperatorVersion || !operatorVersion) {
69+
return false;
70+
}
7071

71-
/**
72-
* Determines if a given feature is enabled by doing a semver version comparison
73-
* @param string
74-
* @param string
75-
* @returns Boolean | void
76-
*/
77-
export function semverVersionCheck(operatorVersion: string, operatorMinVersion: string): Boolean | void {
78-
return semver.gte(operatorVersion, operatorMinVersion);
72+
return semver.gte(operatorVersion, gatedFeature?.minOperatorVersion);
73+
}
74+
75+
return false;
7976
}

0 commit comments

Comments
 (0)