Skip to content

Commit

Permalink
Fix GKE default version and tweak node pool upgrade versioning logic (#…
Browse files Browse the repository at this point in the history
…5151)

* rework gke node pool version logic

* use nodeversions list to determine what version to ffer in nodepool upgrade checkbox

* rebase fixes
  • Loading branch information
mantis-toboggan-md authored Jul 8, 2024
1 parent aefdeba commit 036f8b2
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 53 deletions.
20 changes: 14 additions & 6 deletions lib/shared/addon/components/cluster-driver/driver-gke/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -242,9 +242,6 @@ export default Component.extend(ClusterDriver, {
}
}

if (isEmpty(config.kubernetesVersion)) {
set(this, 'config.kubernetesVersion', versions?.defaultClusterVersion);
}

cb(true);
}).catch((err) => {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -860,9 +865,7 @@ export default Component.extend(ClusterDriver, {
}
}

if (isEmpty(initialVersion)) {
initialVersion = validMasterVersions[0];
}


if (this.editing && !validMasterVersions.includes(initialVersion)) {
validMasterVersions.unshift(initialVersion);
Expand All @@ -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 });
Expand Down
100 changes: 60 additions & 40 deletions lib/shared/addon/components/gke-node-pool-row/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: {},
Expand All @@ -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, {
Expand Down Expand Up @@ -87,15 +84,6 @@ export default Component.extend({
this.send('updateScopes');
}),

editingUpdateNodeVersion: observer('isNewNodePool', 'clusterVersion', function() {
const { isNewNodePool, clusterVersion } = this;
const nodeVersion = get(this, 'nodePool.version');

if (isNewNodePool && clusterVersion !== nodeVersion) {
set(this, 'nodePool.version', clusterVersion);
}
}),

autoscalingChanged: observer('nodePool.autoscaling.enabled', function() {
if (this.isDestroyed || this.isDestroying) {
return;
Expand Down Expand Up @@ -124,6 +112,31 @@ export default Component.extend({
}
}),

// if true, set np.version to latest version <= cp version
// if false, revert np.version
upgradeVersionChanged: observer('upgradeVersion', 'maxAvailableVersion', function() {
const {
upgradeVersion, originalPoolVersion, nodePool, maxAvailableVersion
} = this

if (upgradeVersion){
set(nodePool, 'version', maxAvailableVersion)
} else {
set(nodePool, 'version', originalPoolVersion)
}
}),

// if the pool is new, keep version in sync with cp version
clusterVersionChanged: on('init', observer('clusterVersion', 'maxAvailableVersion', function(){
const {
maxAvailableVersion, isNewNodePool, nodePool
} = this;

if (isNewNodePool && maxAvailableVersion !== nodePool.version){
set(nodePool, 'version', maxAvailableVersion)
}
})),

scopeConfigChanged: on('init', observer('scopeConfig', function() {
if (this.isDestroyed || this.isDestroying) {
return;
Expand Down Expand Up @@ -181,26 +194,43 @@ 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('clusterVersion', 'originalClusterVersion', function(){
const { clusterVersion, originalClusterVersion } = this;

if (isEmpty(clusterVersion) || isEmpty(nodeVersion)) {
return false;
}
return !!clusterVersion && !!originalClusterVersion && clusterVersion !== originalClusterVersion
}),

const nodeIsLess = Semver.lt(nodeVersion, clusterVersion, { includePrerelease: true });
const clusterVersionIsAlsoTheMaxVersion = clusterVersion === defaultClusterVersion;
isNewNodePool: computed('nodePool.isNew', function() {
return this?.nodePool?.isNew ? true : false;
}),

if (nodeIsLess && clusterVersionIsAlsoTheMaxVersion) {
return true;
}
/**
* This property is used to show/hide a np version upgrade checkbox
* 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(){
const { isNewNodePool, clusterWillUpgrade } = this;

return false;
return !isNewNodePool && clusterWillUpgrade
}),

isNewNodePool: computed('nodePool.isNew', function() {
return this?.nodePool?.isNew ? true : false;

// GCP api provides a separate list of versions for node pools, which can be upgraded to anything <= control plane version
maxAvailableVersion: computed('clusterVersion', 'nodeVersions.[]', function() {
const { clusterVersion, nodeVersions } = this;

const availableVersions = nodeVersions.filter((nv) => {
try {
const lteCP = Semver.lte(nv, clusterVersion, { includePreRelease: true })

return lteCP
} catch {
return
}
})

return availableVersions[0]
}),

editedMachineChoice: computed('nodePool.config.machineType', 'machineChoices', function() {
Expand All @@ -221,14 +251,4 @@ export default Component.extend({
return out.sortBy('sortName')
}),


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);
}
})),

});
9 changes: 2 additions & 7 deletions lib/shared/addon/components/gke-node-pool-row/template.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,6 @@
<label class="acc-label">
{{t "clusterNew.googlegke.masterVersion.label"}}
</label>
{{!-- <NewSelect
@classNames="form-control"
@content={{versionChoices}}
@value={{mut nodePool.version}}
/> --}}
{{#if upgradeAvailable}}
<div class="checkbox form-control-static">
<label class="acc-label">
Expand All @@ -34,8 +29,8 @@
/>
{{t
"nodeGroupRow.version.upgrade"
from=nodePool.version
version=clusterVersion
from=originalPoolVersion
version=maxAvailableVersion
}}
</label>
</div>
Expand Down

0 comments on commit 036f8b2

Please sign in to comment.