From 322ab14a726b66646d5db898d0958f0670b8b2ec 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] rework gke node pool version logic --- .../cluster-driver/driver-gke/component.js | 20 ++- .../components/gke-node-pool-row/component.js | 127 ++++++++---------- .../components/gke-node-pool-row/template.hbs | 7 +- 3 files changed, 69 insertions(+), 85 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 f26165e166..47d82c745d 100644 --- a/lib/shared/addon/components/gke-node-pool-row/component.js +++ b/lib/shared/addon/components/gke-node-pool-row/component.js @@ -28,11 +28,12 @@ export default Component.extend({ nodeVersions: null, controlPlaneVersion: null, upgradeVersion: false, + originalPoolVersion: null, init() { this._super(...arguments); - const { nodePool, maxVersion } = this; + const { nodePool } = this; setProperties(this, { scopeConfig: {}, @@ -51,8 +52,8 @@ export default Component.extend({ } } - if (isEmpty(nodePool?.version) && !isEmpty(maxVersion)) { - set(this, 'nodePool.version', maxVersion); + if (nodePool.version){ + set(this, 'originalPoolVersion', nodePool.version) } } else { setProperties(this, { @@ -84,12 +85,12 @@ export default Component.extend({ this.send('updateScopes'); }), - editingUpdateNodeVersion: observer('isNewNodePool', 'clusterVersionIsLessThanMax', 'controlPlaneVersion', function() { - const { isNewNodePool, clusterVersionIsLessThanMax } = 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 && clusterVersionIsLessThanMax) { + if (isNewNodePool && !!clusterVersion && clusterVersion !== nodeVersion && clusterWillUpgrade) { set(this, 'nodePool.version', clusterVersion); } }), @@ -122,6 +123,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; @@ -167,40 +193,27 @@ export default Component.extend({ return ''; }), - maxVersion: computed('versionChoices', 'controlPlaneVersion', function() { - const clusterVersion = get(this, 'controlPlaneVersion'); - const versionChoices = get(this, 'versionChoices'); + clusterWillUpgrade: computed('controlPlaneVersion', 'originalClusterVersion', function(){ + const { controlPlaneVersion, originalClusterVersion } = this; - return versionChoices?.[0]?.value || clusterVersion; + // 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 }), - clusterVersionIsLessThanMax: computed('maxVersion', 'controlPlaneVersion', function() { - const clusterVersion = get(this, 'controlPlaneVersion'); - const maxVersion = get(this, 'maxVersion'); - - return Semver.lte(clusterVersion, maxVersion, { includePrerelease: true }); + isNewNodePool: computed('nodePool.isNew', function() { + return this?.nodePool?.isNew ? true : false; }), - upgradeAvailable: computed('controlPlaneVersion', 'clusterVersionIsLessThanMax', 'mode', 'nodePool.version', 'originalClusterVersion', function() { - const clusterVersion = get(this, 'controlPlaneVersion'); - const nodeVersion = get(this, 'nodePool.version'); - const clusterVersionIsLessThanMax = get(this, 'clusterVersionIsLessThanMax'); - - if (isEmpty(clusterVersion) || isEmpty(nodeVersion)) { - return false; - } - - const nodeIsLess = Semver.lt(nodeVersion, clusterVersion, { includePrerelease: true }); - - if (nodeIsLess && clusterVersionIsLessThanMax) { - return true; - } - - return 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; - isNewNodePool: computed('nodePool.isNew', function() { - return this?.nodePool?.isNew ? true : false; + return !isNewNodePool && clusterWillUpgrade }), editedMachineChoice: computed('nodePool.config.machineType', 'machineChoices', function() { @@ -221,46 +234,14 @@ export default Component.extend({ return out.sortBy('sortName') }), - // versionChoices: computed('nodeVersions.[]', 'controlPlaneVersion', 'mode', function() { - // // google gke console allows the node version to be anything less than master version - // const { - // nodeVersions, - // controlPlaneVersion, - // mode, - // } = this; - - // const coerceedVersion = coerceVersion(controlPlaneVersion); - // const maxVersionRange = `<= ${ coerceedVersion }`; - // let newVersions = this.serviceVersions.parseCloudProviderVersionChoices(nodeVersions, controlPlaneVersion, mode, maxVersionRange); - - // const controlPlaneVersionMatch = newVersions.findBy('value', controlPlaneVersion); - - // if (!isEmpty(controlPlaneVersionMatch)) { - // set(controlPlaneVersionMatch, 'label', `${ controlPlaneVersionMatch.label } (control plane version)`); - - // set(this, 'nodePool.version', controlPlaneVersionMatch.value); + // shouldUpgradeVersion: on('init', observer('upgradeVersion', 'controlPlaneVersion', function() { + // const { upgradeVersion } = this; + // const clusterVersion = get(this, 'controlPlaneVersion'); + // const nodeVersion = get(this, 'nodePool.version'); - // const indexOfMatch = newVersions.indexOf(controlPlaneVersionMatch); - - // if (indexOfMatch > 0) { - // // gke returns a semver like 1.17.17-gke.2800, 1.17.17-gke.3000 - // // semver logic sorts these correctly but because we have to coerce the version, all versions in the 1.17.17 comebace - // // since they are sorted lets just find our CP master match index and cut everything off before that - // newVersions = newVersions.slice(indexOfMatch); - // } + // if (upgradeVersion && clusterVersion !== nodeVersion ) { + // set(this, 'nodePool.version', clusterVersion); // } - - // return newVersions; - // }), - - shouldUpgradeVersion: on('init', observer('upgradeVersion', 'clusterVersionIsLessThanMax', 'controlPlaneVersion', function() { - const { upgradeVersion, clusterVersionIsLessThanMax } = this; - const clusterVersion = get(this, 'controlPlaneVersion'); - const nodeVersion = get(this, 'nodePool.version'); - - if (upgradeVersion && clusterVersion !== nodeVersion && clusterVersionIsLessThanMax) { - 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 3632657c3b..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}}