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 @@
- {{!--