From d7132b0de9c012985de59e9644ff4428af585494 Mon Sep 17 00:00:00 2001 From: Nancy Butler <42977925+mantis-toboggan-md@users.noreply.github.com> Date: Mon, 8 Jul 2024 08:55:44 -0700 Subject: [PATCH 1/3] rework gke node pool version logic --- .../cluster-driver/driver-gke/component.js | 20 +++-- .../components/gke-node-pool-row/component.js | 90 ++++++++++++------- .../components/gke-node-pool-row/template.hbs | 9 +- 3 files changed, 73 insertions(+), 46 deletions(-) diff --git a/lib/shared/addon/components/cluster-driver/driver-gke/component.js b/lib/shared/addon/components/cluster-driver/driver-gke/component.js index 7000a10082..d1a7910392 100644 --- a/lib/shared/addon/components/cluster-driver/driver-gke/component.js +++ b/lib/shared/addon/components/cluster-driver/driver-gke/component.js @@ -242,9 +242,6 @@ export default Component.extend(ClusterDriver, { } } - if (isEmpty(config.kubernetesVersion)) { - set(this, 'config.kubernetesVersion', versions?.defaultClusterVersion); - } cb(true); }).catch((err) => { @@ -275,6 +272,14 @@ export default Component.extend(ClusterDriver, { }, }, + versionChoicesChanged: observer('versionChoices.[]', 'config.kubernetesVersion', 'versions.{validMasterVersions,channels}', function(){ + const { config, versionChoices } = this; + + if (isEmpty(config.kubernetesVersion)) { + set(this, 'config.kubernetesVersion', versionChoices[0].value); + } + }), + networkPolicyEnabledChanged: observer('config.networkPolicyEnabled', function() { if (get(this, 'isNew') && get(this, 'config.networkPolicyEnabled')) { set(this, 'config.clusterAddons.networkPolicyConfig', true); @@ -860,9 +865,7 @@ export default Component.extend(ClusterDriver, { } } - if (isEmpty(initialVersion)) { - initialVersion = validMasterVersions[0]; - } + if (this.editing && !validMasterVersions.includes(initialVersion)) { validMasterVersions.unshift(initialVersion); @@ -871,6 +874,11 @@ export default Component.extend(ClusterDriver, { Semver.rsort(validMasterVersions, { includePrerelease: true }); const versionChoices = this.serviceVersions.parseCloudProviderVersionChoicesV2(validMasterVersions.slice(), initialVersion, mode, null, false, MINIMUM_VERSION); + if (isEmpty(initialVersion)) { + initialVersion = versionChoices[0]?.value; + } + + if (this.editing) { try { const initialSem = Semver.parse(initialVersion, { includePrerelease: true }); diff --git a/lib/shared/addon/components/gke-node-pool-row/component.js b/lib/shared/addon/components/gke-node-pool-row/component.js index b5851d6f0f..bd4db49c04 100644 --- a/lib/shared/addon/components/gke-node-pool-row/component.js +++ b/lib/shared/addon/components/gke-node-pool-row/component.js @@ -27,15 +27,12 @@ export default Component.extend({ nodeVersions: null, clusterVersion: null, upgradeVersion: false, + originalPoolVersion: null, init() { this._super(...arguments); - const { - nodePool, - clusterVersion, - defaultClusterVersion - } = this; + const { nodePool } = this; setProperties(this, { scopeConfig: {}, @@ -54,8 +51,8 @@ export default Component.extend({ } } - if (isEmpty(nodePool?.version) && !isEmpty(clusterVersion)) { - set(this, 'nodePool.version', defaultClusterVersion); + if (nodePool.version){ + set(this, 'originalPoolVersion', nodePool.version) } } else { setProperties(this, { @@ -87,11 +84,12 @@ export default Component.extend({ this.send('updateScopes'); }), - editingUpdateNodeVersion: observer('isNewNodePool', 'clusterVersion', function() { - const { isNewNodePool, clusterVersion } = this; + editingUpdateNodeVersion: observer('isNewNodePool', 'clusterWillUpgrade', 'controlPlaneVersion', function() { + const { isNewNodePool, clusterWillUpgrade } = this; + const clusterVersion = get(this, 'controlPlaneVersion'); const nodeVersion = get(this, 'nodePool.version'); - if (isNewNodePool && clusterVersion !== nodeVersion) { + if (isNewNodePool && !!clusterVersion && clusterVersion !== nodeVersion && clusterWillUpgrade) { set(this, 'nodePool.version', clusterVersion); } }), @@ -124,6 +122,31 @@ export default Component.extend({ } }), + // if true, set np.version to controlPlaneVersion + // if false, revert np.version + upgradeVersionChanged: observer('upgradeVersion', 'controlPlaneVersion', function() { + const { + upgradeVersion, originalPoolVersion, controlPlaneVersion, nodePool + } = this + + if (upgradeVersion){ + set(nodePool, 'version', controlPlaneVersion) + } else { + set(nodePool, 'version', originalPoolVersion) + } + }), + + // if the pool is new, keep version in sync with cp version + controlPlaneVersionChanged: on('init', observer('controlPlaneVersion', function(){ + const { + controlPlaneVersion, isNewNodePool, nodePool + } = this; + + if (isNewNodePool && controlPlaneVersion !== nodePool.version){ + set(nodePool, 'version', controlPlaneVersion) + } + })), + scopeConfigChanged: on('init', observer('scopeConfig', function() { if (this.isDestroyed || this.isDestroying) { return; @@ -181,28 +204,29 @@ export default Component.extend({ return ''; }), - upgradeAvailable: computed('clusterVersion', 'mode', 'nodePool.version', 'defaultClusterVersion', function() { - const { clusterVersion, defaultClusterVersion } = this; - const nodeVersion = get(this, 'nodePool.version'); + clusterWillUpgrade: computed('controlPlaneVersion', 'originalClusterVersion', function(){ + const { controlPlaneVersion, originalClusterVersion } = this; - if (isEmpty(clusterVersion) || isEmpty(nodeVersion)) { - return false; - } - - const nodeIsLess = Semver.lt(nodeVersion, clusterVersion, { includePrerelease: true }); - const clusterVersionIsAlsoTheMaxVersion = clusterVersion === defaultClusterVersion; - - if (nodeIsLess && clusterVersionIsAlsoTheMaxVersion) { - return true; - } - - return false; + // gke versions have a long suffix eg 1.26.15-gke.1900000 and 1.26.15-gke.1900001 may both be options so we use a simple equality check instead of semver package + // logic in driver-gke ensures that if a new version is selected it must be an upgrade from original version + return !!controlPlaneVersion && !!originalClusterVersion && controlPlaneVersion !== originalClusterVersion }), isNewNodePool: computed('nodePool.isNew', function() { return this?.nodePool?.isNew ? true : false; }), + /** + * This property is used to show/hide a np version upgrade checkbox + * when the box is checked the np is upgraded to match the cp version + * with new node pools, the version is always kept in sync with the cp version so no checkbox shown + */ + upgradeAvailable: computed('isNewNodePool', 'clusterWillUpgrade', function(){ + const { isNewNodePool, clusterWillUpgrade } = this; + + return !isNewNodePool && clusterWillUpgrade + }), + editedMachineChoice: computed('nodePool.config.machineType', 'machineChoices', function() { return get(this, 'machineChoices').findBy('name', get(this, 'nodePool.config.machineType')); }), @@ -221,14 +245,14 @@ export default Component.extend({ return out.sortBy('sortName') }), + // shouldUpgradeVersion: on('init', observer('upgradeVersion', 'controlPlaneVersion', function() { + // const { upgradeVersion } = this; + // const clusterVersion = get(this, 'controlPlaneVersion'); + // const nodeVersion = get(this, 'nodePool.version'); - shouldUpgradeVersion: on('init', observer('upgradeVersion', 'clusterVersion', function() { - const { upgradeVersion, clusterVersion } = this; - const nodeVersion = get(this, 'nodePool.version'); - - if (upgradeVersion && clusterVersion !== nodeVersion) { - set(this, 'nodePool.version', clusterVersion); - } - })), + // if (upgradeVersion && clusterVersion !== nodeVersion ) { + // set(this, 'nodePool.version', clusterVersion); + // } + // })), }); diff --git a/lib/shared/addon/components/gke-node-pool-row/template.hbs b/lib/shared/addon/components/gke-node-pool-row/template.hbs index 1a0bc372e1..61ab5acd02 100644 --- a/lib/shared/addon/components/gke-node-pool-row/template.hbs +++ b/lib/shared/addon/components/gke-node-pool-row/template.hbs @@ -19,11 +19,6 @@ - {{!-- --}} {{#if upgradeAvailable}}
From ad35b3060f8ebd03b45006e68950871be3c8c164 Mon Sep 17 00:00:00 2001 From: Nancy Butler <42977925+mantis-toboggan-md@users.noreply.github.com> Date: Mon, 8 Jul 2024 09:55:41 -0700 Subject: [PATCH 2/3] use nodeversions list to determine what version to ffer in nodepool upgrade checkbox --- .../components/gke-node-pool-row/component.js | 58 +++++++++---------- .../components/gke-node-pool-row/template.hbs | 2 +- 2 files changed, 28 insertions(+), 32 deletions(-) diff --git a/lib/shared/addon/components/gke-node-pool-row/component.js b/lib/shared/addon/components/gke-node-pool-row/component.js index bd4db49c04..7bd8459166 100644 --- a/lib/shared/addon/components/gke-node-pool-row/component.js +++ b/lib/shared/addon/components/gke-node-pool-row/component.js @@ -84,16 +84,6 @@ export default Component.extend({ this.send('updateScopes'); }), - editingUpdateNodeVersion: observer('isNewNodePool', 'clusterWillUpgrade', 'controlPlaneVersion', function() { - const { isNewNodePool, clusterWillUpgrade } = this; - const clusterVersion = get(this, 'controlPlaneVersion'); - const nodeVersion = get(this, 'nodePool.version'); - - if (isNewNodePool && !!clusterVersion && clusterVersion !== nodeVersion && clusterWillUpgrade) { - set(this, 'nodePool.version', clusterVersion); - } - }), - autoscalingChanged: observer('nodePool.autoscaling.enabled', function() { if (this.isDestroyed || this.isDestroying) { return; @@ -122,28 +112,28 @@ export default Component.extend({ } }), - // if true, set np.version to controlPlaneVersion + // if true, set np.version to latest version <= cp version // if false, revert np.version - upgradeVersionChanged: observer('upgradeVersion', 'controlPlaneVersion', function() { + upgradeVersionChanged: observer('upgradeVersion', 'maxAvailableVersion', function() { const { - upgradeVersion, originalPoolVersion, controlPlaneVersion, nodePool + upgradeVersion, originalPoolVersion, nodePool, maxAvailableVersion } = this if (upgradeVersion){ - set(nodePool, 'version', controlPlaneVersion) + set(nodePool, 'version', maxAvailableVersion) } else { set(nodePool, 'version', originalPoolVersion) } }), // if the pool is new, keep version in sync with cp version - controlPlaneVersionChanged: on('init', observer('controlPlaneVersion', function(){ + controlPlaneVersionChanged: on('init', observer('controlPlaneVersion', 'maxAvailableVersion', function(){ const { - controlPlaneVersion, isNewNodePool, nodePool + maxAvailableVersion, isNewNodePool, nodePool } = this; - if (isNewNodePool && controlPlaneVersion !== nodePool.version){ - set(nodePool, 'version', controlPlaneVersion) + if (isNewNodePool && maxAvailableVersion !== nodePool.version){ + set(nodePool, 'version', maxAvailableVersion) } })), @@ -207,8 +197,6 @@ export default Component.extend({ clusterWillUpgrade: computed('controlPlaneVersion', 'originalClusterVersion', function(){ const { controlPlaneVersion, originalClusterVersion } = this; - // gke versions have a long suffix eg 1.26.15-gke.1900000 and 1.26.15-gke.1900001 may both be options so we use a simple equality check instead of semver package - // logic in driver-gke ensures that if a new version is selected it must be an upgrade from original version return !!controlPlaneVersion && !!originalClusterVersion && controlPlaneVersion !== originalClusterVersion }), @@ -218,7 +206,7 @@ export default Component.extend({ /** * This property is used to show/hide a np version upgrade checkbox - * when the box is checked the np is upgraded to match the cp version + * when the box is checked the np is upgraded to latest node version that is <= cp version * with new node pools, the version is always kept in sync with the cp version so no checkbox shown */ upgradeAvailable: computed('isNewNodePool', 'clusterWillUpgrade', function(){ @@ -227,6 +215,24 @@ export default Component.extend({ return !isNewNodePool && clusterWillUpgrade }), + + // GCP api provides a separate list of versions for node pools, which can be upgraded to anything <= control plane version + maxAvailableVersion: computed('controlPlaneVersion', 'nodeVersions.[]', function() { + const { controlPlaneVersion, nodeVersions } = this; + + const availableVersions = nodeVersions.filter((nv) => { + try { + const lteCP = Semver.lte(nv, controlPlaneVersion, { includePreRelease: true }) + + return lteCP + } catch { + return + } + }) + + return availableVersions[0] + }), + editedMachineChoice: computed('nodePool.config.machineType', 'machineChoices', function() { return get(this, 'machineChoices').findBy('name', get(this, 'nodePool.config.machineType')); }), @@ -245,14 +251,4 @@ export default Component.extend({ return out.sortBy('sortName') }), - // shouldUpgradeVersion: on('init', observer('upgradeVersion', 'controlPlaneVersion', function() { - // const { upgradeVersion } = this; - // const clusterVersion = get(this, 'controlPlaneVersion'); - // const nodeVersion = get(this, 'nodePool.version'); - - // if (upgradeVersion && clusterVersion !== nodeVersion ) { - // set(this, 'nodePool.version', clusterVersion); - // } - // })), - }); diff --git a/lib/shared/addon/components/gke-node-pool-row/template.hbs b/lib/shared/addon/components/gke-node-pool-row/template.hbs index 61ab5acd02..6f87b6b8aa 100644 --- a/lib/shared/addon/components/gke-node-pool-row/template.hbs +++ b/lib/shared/addon/components/gke-node-pool-row/template.hbs @@ -30,7 +30,7 @@ {{t "nodeGroupRow.version.upgrade" from=originalPoolVersion - version=controlPlaneVersion + version=maxAvailableVersion }} From 72c4cd05639f02e4f1df251dbc07f8a1419b3941 Mon Sep 17 00:00:00 2001 From: Nancy Butler <42977925+mantis-toboggan-md@users.noreply.github.com> Date: Mon, 8 Jul 2024 10:31:22 -0700 Subject: [PATCH 3/3] rebase fixes --- .../components/gke-node-pool-row/component.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/shared/addon/components/gke-node-pool-row/component.js b/lib/shared/addon/components/gke-node-pool-row/component.js index 7bd8459166..af2f70d8c6 100644 --- a/lib/shared/addon/components/gke-node-pool-row/component.js +++ b/lib/shared/addon/components/gke-node-pool-row/component.js @@ -127,7 +127,7 @@ export default Component.extend({ }), // if the pool is new, keep version in sync with cp version - controlPlaneVersionChanged: on('init', observer('controlPlaneVersion', 'maxAvailableVersion', function(){ + clusterVersionChanged: on('init', observer('clusterVersion', 'maxAvailableVersion', function(){ const { maxAvailableVersion, isNewNodePool, nodePool } = this; @@ -194,10 +194,10 @@ export default Component.extend({ return ''; }), - clusterWillUpgrade: computed('controlPlaneVersion', 'originalClusterVersion', function(){ - const { controlPlaneVersion, originalClusterVersion } = this; + clusterWillUpgrade: computed('clusterVersion', 'originalClusterVersion', function(){ + const { clusterVersion, originalClusterVersion } = this; - return !!controlPlaneVersion && !!originalClusterVersion && controlPlaneVersion !== originalClusterVersion + return !!clusterVersion && !!originalClusterVersion && clusterVersion !== originalClusterVersion }), isNewNodePool: computed('nodePool.isNew', function() { @@ -217,12 +217,12 @@ export default Component.extend({ // GCP api provides a separate list of versions for node pools, which can be upgraded to anything <= control plane version - maxAvailableVersion: computed('controlPlaneVersion', 'nodeVersions.[]', function() { - const { controlPlaneVersion, nodeVersions } = this; + maxAvailableVersion: computed('clusterVersion', 'nodeVersions.[]', function() { + const { clusterVersion, nodeVersions } = this; const availableVersions = nodeVersions.filter((nv) => { try { - const lteCP = Semver.lte(nv, controlPlaneVersion, { includePreRelease: true }) + const lteCP = Semver.lte(nv, clusterVersion, { includePreRelease: true }) return lteCP } catch {