Skip to content

Commit

Permalink
use nodeversions list to determine what version to ffer in nodepool u…
Browse files Browse the repository at this point in the history
…pgrade checkbox
  • Loading branch information
mantis-toboggan-md committed Jul 8, 2024
1 parent d7132b0 commit ad35b30
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 32 deletions.
58 changes: 27 additions & 31 deletions lib/shared/addon/components/gke-node-pool-row/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
}
})),

Expand Down Expand Up @@ -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
}),

Expand All @@ -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(){
Expand All @@ -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'));
}),
Expand All @@ -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);
// }
// })),

});
2 changes: 1 addition & 1 deletion lib/shared/addon/components/gke-node-pool-row/template.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
{{t
"nodeGroupRow.version.upgrade"
from=originalPoolVersion
version=controlPlaneVersion
version=maxAvailableVersion
}}
</label>
</div>
Expand Down

0 comments on commit ad35b30

Please sign in to comment.