From 0a1c5d8f57495e6d746802a13177d8f76bc02733 Mon Sep 17 00:00:00 2001 From: Mo Mesgin Date: Thu, 7 Nov 2024 09:52:35 -0800 Subject: [PATCH 1/4] return when prebootstrap flag is active --- shell/utils/v-sphere.ts | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/shell/utils/v-sphere.ts b/shell/utils/v-sphere.ts index 47c3e7ac8bd..245bca2ce7e 100644 --- a/shell/utils/v-sphere.ts +++ b/shell/utils/v-sphere.ts @@ -1,5 +1,5 @@ import merge from 'lodash/merge'; -import { SECRET } from '@shell/config/types'; +import { SECRET, MANAGEMENT } from '@shell/config/types'; type Rke2Component = { versionInfo: any; @@ -91,10 +91,24 @@ class VSphereUtils { }; } + private async findPrebootstrapFeatureFlag({ $store }: Rke2Component) { + const featureFlag = await $store.dispatch('management/find', { + type: MANAGEMENT.FEATURE, id: 'provisioningprebootstrap', opt: { url: `/v1/${ MANAGEMENT.FEATURE }/provisioningprebootstrap` } + }); + + return featureFlag?.spec?.value; + } + /** * Create upstream vsphere cpi secret to sync downstream */ async handleVsphereCpiSecret(rke2Component: Rke2Component) { + const isPrebootstrapEnabled = await this.findPrebootstrapFeatureFlag(rke2Component); + + if (!isPrebootstrapEnabled) { + return; + } + const generateName = `${ rootGenerateName }cpi-`; const downstreamName = 'rancher-vsphere-cpi-credentials'; const downstreamNamespace = 'kube-system'; @@ -168,6 +182,12 @@ class VSphereUtils { * Create upstream vsphere csi secret to sync downstream */ async handleVsphereCsiSecret(rke2Component: Rke2Component) { + const isPrebootstrapEnabled = await this.findPrebootstrapFeatureFlag(rke2Component); + + if (!isPrebootstrapEnabled) { + return; + } + const generateName = `${ rootGenerateName }csi-`; const downstreamName = 'rancher-vsphere-csi-credentials'; const downstreamNamespace = 'kube-system'; From 1d759c363c4c378f239d1c8e3fb1a9f6bc0a4790 Mon Sep 17 00:00:00 2001 From: Mo Mesgin Date: Thu, 7 Nov 2024 10:22:04 -0800 Subject: [PATCH 2/4] refactor getting feature flag + check provider before running the logic --- .../provisioning.cattle.io.cluster/rke2.vue | 4 +-- shell/store/features.js | 1 + shell/utils/v-sphere.ts | 29 ++++++++++--------- 3 files changed, 18 insertions(+), 16 deletions(-) diff --git a/shell/edit/provisioning.cattle.io.cluster/rke2.vue b/shell/edit/provisioning.cattle.io.cluster/rke2.vue index a7675d4f881..d78f773a470 100644 --- a/shell/edit/provisioning.cattle.io.cluster/rke2.vue +++ b/shell/edit/provisioning.cattle.io.cluster/rke2.vue @@ -65,14 +65,12 @@ import Advanced from '@shell/edit/provisioning.cattle.io.cluster/tabs/Advanced'; import { DEFAULT_COMMON_BASE_PATH, DEFAULT_SUBDIRS } from '@shell/edit/provisioning.cattle.io.cluster/tabs/DirectoryConfig'; import ClusterAppearance from '@shell/components/form/ClusterAppearance'; import AddOnAdditionalManifest from '@shell/edit/provisioning.cattle.io.cluster/tabs/AddOnAdditionalManifest'; -import VsphereUtils from '@shell/utils/v-sphere'; +import VsphereUtils, { VMWARE_VSPHERE } from '@shell/utils/v-sphere'; const HARVESTER = 'harvester'; const HARVESTER_CLOUD_PROVIDER = 'harvester-cloud-provider'; const NETBIOS_TRUNCATION_LENGTH = 15; -const VMWARE_VSPHERE = 'vmwarevsphere'; - /** * Classes to be adopted by the node badges in Machine pools */ diff --git a/shell/store/features.js b/shell/store/features.js index 6789ecfd8a5..35df2b09cb6 100644 --- a/shell/store/features.js +++ b/shell/store/features.js @@ -35,6 +35,7 @@ export const HARVESTER_CONTAINER = create('harvester-baremetal-container-workloa export const FLEET_WORKSPACE_BACK = create('provisioningv2-fleet-workspace-back-population', false); export const STEVE_CACHE = create('ui-sql-cache', false); export const UIEXTENSION = create('uiextension', true); +export const PROVISIONING_PRE_BOOTSTRAP = create('provisioningprebootstrap', false); // Not currently used.. no point defining ones we don't use // export const EMBEDDED_CLUSTER_API = create('embedded-cluster-api', true); diff --git a/shell/utils/v-sphere.ts b/shell/utils/v-sphere.ts index 245bca2ce7e..8a51b67ea12 100644 --- a/shell/utils/v-sphere.ts +++ b/shell/utils/v-sphere.ts @@ -1,5 +1,8 @@ import merge from 'lodash/merge'; -import { SECRET, MANAGEMENT } from '@shell/config/types'; +import { SECRET } from '@shell/config/types'; +import { PROVISIONING_PRE_BOOTSTRAP } from '@shell/store/features'; + +export const VMWARE_VSPHERE = 'vmwarevsphere'; type Rke2Component = { versionInfo: any; @@ -91,19 +94,15 @@ class VSphereUtils { }; } - private async findPrebootstrapFeatureFlag({ $store }: Rke2Component) { - const featureFlag = await $store.dispatch('management/find', { - type: MANAGEMENT.FEATURE, id: 'provisioningprebootstrap', opt: { url: `/v1/${ MANAGEMENT.FEATURE }/provisioningprebootstrap` } - }); - - return featureFlag?.spec?.value; - } - /** * Create upstream vsphere cpi secret to sync downstream */ - async handleVsphereCpiSecret(rke2Component: Rke2Component) { - const isPrebootstrapEnabled = await this.findPrebootstrapFeatureFlag(rke2Component); + async handleVsphereCpiSecret(rke2Component: Rke2Component, provider: String) { + if (provider !== VMWARE_VSPHERE) { + return; + } + + const isPrebootstrapEnabled = rke2Component.$store.getters['features/get'](PROVISIONING_PRE_BOOTSTRAP); if (!isPrebootstrapEnabled) { return; @@ -181,8 +180,12 @@ class VSphereUtils { /** * Create upstream vsphere csi secret to sync downstream */ - async handleVsphereCsiSecret(rke2Component: Rke2Component) { - const isPrebootstrapEnabled = await this.findPrebootstrapFeatureFlag(rke2Component); + async handleVsphereCsiSecret(rke2Component: Rke2Component, provider: String) { + if (provider !== VMWARE_VSPHERE) { + return; + } + + const isPrebootstrapEnabled = rke2Component.$store.getters['features/get'](PROVISIONING_PRE_BOOTSTRAP); if (!isPrebootstrapEnabled) { return; From 7df3a617f120f18b082fc2cb1da91d8e40b2d6ec Mon Sep 17 00:00:00 2001 From: Mo Mesgin Date: Thu, 7 Nov 2024 11:43:19 -0800 Subject: [PATCH 3/4] refactor accessing provider --- shell/utils/v-sphere.ts | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/shell/utils/v-sphere.ts b/shell/utils/v-sphere.ts index 8a51b67ea12..7c917a666cc 100644 --- a/shell/utils/v-sphere.ts +++ b/shell/utils/v-sphere.ts @@ -10,6 +10,7 @@ type Rke2Component = { chartVersionKey: (chartName: string) => string; value: any; isEdit: boolean; + provider: String; $store: any, } @@ -97,12 +98,14 @@ class VSphereUtils { /** * Create upstream vsphere cpi secret to sync downstream */ - async handleVsphereCpiSecret(rke2Component: Rke2Component, provider: String) { + async handleVsphereCpiSecret(rke2Component: Rke2Component) { + const { $store, provider, value } = rke2Component; + if (provider !== VMWARE_VSPHERE) { return; } - const isPrebootstrapEnabled = rke2Component.$store.getters['features/get'](PROVISIONING_PRE_BOOTSTRAP); + const isPrebootstrapEnabled = $store.getters['features/get'](PROVISIONING_PRE_BOOTSTRAP); if (!isPrebootstrapEnabled) { return; @@ -111,7 +114,6 @@ class VSphereUtils { const generateName = `${ rootGenerateName }cpi-`; const downstreamName = 'rancher-vsphere-cpi-credentials'; const downstreamNamespace = 'kube-system'; - const { value } = rke2Component; // check values for cpi chart has 'use our method' checkbox const { userValues, combined } = this.findChartValues(rke2Component, 'rancher-vsphere-cpi') || {}; @@ -180,12 +182,14 @@ class VSphereUtils { /** * Create upstream vsphere csi secret to sync downstream */ - async handleVsphereCsiSecret(rke2Component: Rke2Component, provider: String) { + async handleVsphereCsiSecret(rke2Component: Rke2Component) { + const { $store, provider, value } = rke2Component; + if (provider !== VMWARE_VSPHERE) { return; } - const isPrebootstrapEnabled = rke2Component.$store.getters['features/get'](PROVISIONING_PRE_BOOTSTRAP); + const isPrebootstrapEnabled = $store.getters['features/get'](PROVISIONING_PRE_BOOTSTRAP); if (!isPrebootstrapEnabled) { return; @@ -194,7 +198,6 @@ class VSphereUtils { const generateName = `${ rootGenerateName }csi-`; const downstreamName = 'rancher-vsphere-csi-credentials'; const downstreamNamespace = 'kube-system'; - const { value } = rke2Component; // check values for cpi chart has 'use our method' checkbox const { userValues, combined } = this.findChartValues(rke2Component, 'rancher-vsphere-csi') || {}; From 8ccfffc4fca0a8842dbb186f49be9fcf58d713e1 Mon Sep 17 00:00:00 2001 From: Richard Cox Date: Fri, 8 Nov 2024 10:14:29 +0000 Subject: [PATCH 4/4] Remove duped code --- shell/utils/v-sphere.ts | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/shell/utils/v-sphere.ts b/shell/utils/v-sphere.ts index 7c917a666cc..2bc508c4b1f 100644 --- a/shell/utils/v-sphere.ts +++ b/shell/utils/v-sphere.ts @@ -10,7 +10,7 @@ type Rke2Component = { chartVersionKey: (chartName: string) => string; value: any; isEdit: boolean; - provider: String; + provider: string; $store: any, } @@ -95,25 +95,32 @@ class VSphereUtils { }; } - /** - * Create upstream vsphere cpi secret to sync downstream - */ - async handleVsphereCpiSecret(rke2Component: Rke2Component) { - const { $store, provider, value } = rke2Component; - + private handleVsphereSecret({ $store, provider }: { $store: any, provider: string}): boolean { if (provider !== VMWARE_VSPHERE) { - return; + return false; } const isPrebootstrapEnabled = $store.getters['features/get'](PROVISIONING_PRE_BOOTSTRAP); if (!isPrebootstrapEnabled) { + return false; + } + + return true; + } + + /** + * Create upstream vsphere cpi secret to sync downstream + */ + async handleVsphereCpiSecret(rke2Component: Rke2Component) { + if (!this.handleVsphereSecret(rke2Component)) { return; } const generateName = `${ rootGenerateName }cpi-`; const downstreamName = 'rancher-vsphere-cpi-credentials'; const downstreamNamespace = 'kube-system'; + const { value } = rke2Component; // check values for cpi chart has 'use our method' checkbox const { userValues, combined } = this.findChartValues(rke2Component, 'rancher-vsphere-cpi') || {}; @@ -183,21 +190,14 @@ class VSphereUtils { * Create upstream vsphere csi secret to sync downstream */ async handleVsphereCsiSecret(rke2Component: Rke2Component) { - const { $store, provider, value } = rke2Component; - - if (provider !== VMWARE_VSPHERE) { - return; - } - - const isPrebootstrapEnabled = $store.getters['features/get'](PROVISIONING_PRE_BOOTSTRAP); - - if (!isPrebootstrapEnabled) { + if (!this.handleVsphereSecret(rke2Component)) { return; } const generateName = `${ rootGenerateName }csi-`; const downstreamName = 'rancher-vsphere-csi-credentials'; const downstreamNamespace = 'kube-system'; + const { value } = rke2Component; // check values for cpi chart has 'use our method' checkbox const { userValues, combined } = this.findChartValues(rke2Component, 'rancher-vsphere-csi') || {};