Skip to content

Commit

Permalink
rework gke node pool version logic
Browse files Browse the repository at this point in the history
  • Loading branch information
mantis-toboggan-md committed Jul 8, 2024
1 parent 74e4876 commit 322ab14
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 85 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
127 changes: 54 additions & 73 deletions lib/shared/addon/components/gke-node-pool-row/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: {},
Expand All @@ -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, {
Expand Down Expand Up @@ -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);
}
}),
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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() {
Expand All @@ -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);
}
})),
// })),

});
7 changes: 1 addition & 6 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,7 +29,7 @@
/>
{{t
"nodeGroupRow.version.upgrade"
from=nodePool.version
from=originalPoolVersion
version=controlPlaneVersion
}}
</label>
Expand Down

0 comments on commit 322ab14

Please sign in to comment.