Skip to content

Commit

Permalink
feat(gce): Enabled extended memory feature to define reusable custom …
Browse files Browse the repository at this point in the history
…types (#9721)

* fix(4773): Added extended memory feature to define reausable custom type.

* fix(4773): Enabled Extended memory feature for N1,N2 and N2D instance family

Co-authored-by: rsinghsidhu <[email protected]>
Co-authored-by: caseyhebebrand <[email protected]>
  • Loading branch information
3 people authored Oct 27, 2021
1 parent 9a3dbe5 commit e108e95
Show file tree
Hide file tree
Showing 8 changed files with 94 additions and 19 deletions.
4 changes: 3 additions & 1 deletion packages/google/src/help/gce.help.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ const helpContents: { [key: string]: string } = {
'gce.instance.customInstance.cores':
'<ul><li>Above 1, vCPU count must be even.</li><li>Zones that support Haswell and Ivy Bridge processors can support custom machine types up to 32 vCPUs.</li><li>Zones that support Sandy Bridge processors can support up to 16 vCPUs.</li></ul>',
'gce.instance.customInstance.memory':
'<ul><li>Memory per vCPU must be between .9 GB and 6.5 GB.</li><li>Total memory must be a multiple of 256 MB.</li></ul>',
'<ul><li>Memory per vCPU must be between .9 GB and 6.5 GB.</li><li>Total memory must be a multiple of 256 MB.</li><li>Memory per vCPU must be between .9 GB and 800 GB if selected extended memory feature.</li></ul>',
'gce.instance.customInstance.extendedmemory':
'Add more memory per vCPU to your VM instance. <a href="https://cloud.google.com/compute/docs/instances/creating-instance-with-custom-machine-type#extendedmemory">Click here </a>for more information regarding extended memory',
'gce.instance.customMetadata.instance-template': 'The instance template used to configure this instance.',
'gce.instance.customMetadata.load-balancer-names':
'This field is used to "remember" what load balancers this instance is associated with, even if it is deregistered.',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,23 +88,24 @@ module(GOOGLE_INSTANCE_CUSTOM_CUSTOMINSTANCEBUILDER_GCE_SERVICE, []).factory(
return [..._.range(min, max, 0.25), max];
}

function memoryIsValid(instanceFamily, totalMemory, vCpuCount) {
function memoryIsValid(instanceFamily, totalMemory, vCpuCount, extendedMemory) {
const min = minMemoryForVCpuCount(instanceFamily, vCpuCount);
const max = maxMemoryForVCpuCount(instanceFamily, vCpuCount);
const max = extendedMemory ? 800 : maxMemoryForVCpuCount(instanceFamily, vCpuCount);
return _.inRange(totalMemory, min, max) || totalMemory === max;
}

/*
* In the API, you must always provide memory in MB units.
* Format: custom-NUMBER_OF_CPUS-AMOUNT_OF_MEMORY
* */
function generateInstanceTypeString(instanceFamily, vCpuCount, totalMemory) {
function generateInstanceTypeString(instanceFamily, vCpuCount, totalMemory, extendedMemory) {
const extendedFlag = extendedMemory ? '-ext' : '';
const memoryInMbs = Number(totalMemory) * 1024;
instanceFamily = instanceFamily.toLowerCase();
if (instanceFamily === 'n1') {
return `custom-${vCpuCount}-${memoryInMbs}`;
return `custom-${vCpuCount}-${memoryInMbs}${extendedFlag}`;
}
return `${instanceFamily}-custom-${vCpuCount}-${memoryInMbs}`;
return `${instanceFamily}-custom-${vCpuCount}-${memoryInMbs}${extendedFlag}`;
}

function parseInstanceTypeString(instanceTypeString) {
Expand All @@ -129,10 +130,11 @@ module(GOOGLE_INSTANCE_CUSTOM_CUSTOMINSTANCEBUILDER_GCE_SERVICE, []).factory(
totalMemory,
location,
locationToInstanceTypesMap,
extendedMemory,
) {
return _.every([
numberOfVCpusIsValid(instanceFamily, vCpuCount),
memoryIsValid(instanceFamily, totalMemory, vCpuCount),
memoryIsValid(instanceFamily, totalMemory, vCpuCount, extendedMemory),
vCpuCountForLocationIsValid(instanceFamily, vCpuCount, location, locationToInstanceTypesMap),
]);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,7 @@ angular
let vCpuCount = _.get(c, 'viewState.customInstance.vCpuCount');
const instanceFamily = _.get(c, 'viewState.customInstance.instanceFamily');
const memory = _.get(c, 'viewState.customInstance.memory');
const extendedMemory = _.get(c, 'viewState.customInstance.extendedMemory');
const { zone, regional, region } = c;
const { locationToInstanceTypesMap } = c.backingData.credentialsKeyedByAccount[c.credentials];
const location = regional ? region : zone;
Expand Down Expand Up @@ -294,7 +295,7 @@ angular
_.every([
memory,
vCpuCount,
!gceCustomInstanceBuilderService.memoryIsValid(instanceFamily, memory, vCpuCount),
!gceCustomInstanceBuilderService.memoryIsValid(instanceFamily, memory, vCpuCount, extendedMemory),
])
) {
_.set(c, 'viewState.customInstance.memory', undefined);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ angular
const c = $scope.command;
const location = c.regional ? c.region : c.zone;
const { locationToInstanceTypesMap } = c.backingData.credentialsKeyedByAccount[c.credentials];

const extendedMemory = _.get(c, 'viewState.customInstance.extendedMemory');
const customInstanceChoices = [
_.get(c, 'viewState.customInstance.instanceFamily'),
_.get(c, 'viewState.customInstance.vCpuCount'),
Expand All @@ -230,10 +230,14 @@ angular
...customInstanceChoices,
location,
locationToInstanceTypesMap,
extendedMemory,
),
])
) {
c.instanceType = gceCustomInstanceBuilderService.generateInstanceTypeString(...customInstanceChoices);
c.instanceType = gceCustomInstanceBuilderService.generateInstanceTypeString(
...customInstanceChoices,
extendedMemory,
);

instanceTypeService.getInstanceTypeDetails(c.selectedProvider, 'buildCustom').then((instanceTypeDetails) => {
c.viewState.instanceTypeDetails = instanceTypeDetails;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@ import React from 'react';
import type { Option } from 'react-select';
import Select from 'react-select';

import { HelpField } from '@spinnaker/core';
import { CheckboxInput, HelpField } from '@spinnaker/core';
import './customInstanceConfigurer.component.less';

export interface ICustomInstanceConfig {
vCpuCount: number;
memory: number;
instanceFamily: string;
extendedMemory: boolean;
}

export interface ICustomInstanceConfigurerProps {
Expand All @@ -17,6 +19,7 @@ export interface ICustomInstanceConfigurerProps {
selectedVCpuCount: number;
selectedMemory: number;
selectedInstanceFamily: string;
selectedExtendedMemory: boolean;
onChange: (config: ICustomInstanceConfig) => void;
}

Expand Down Expand Up @@ -50,7 +53,7 @@ export class CustomInstanceConfigurer extends React.Component<ICustomInstanceCon
/>
</div>
</div>
<div className="row">
<div className="row gce-instance-build-custom-select">
<div className="col-md-5 sm-label-right">
<b>Cores </b>
<HelpField id="gce.instance.customInstance.cores" />
Expand All @@ -64,20 +67,50 @@ export class CustomInstanceConfigurer extends React.Component<ICustomInstanceCon
/>
</div>
</div>
<div className="row" style={{ marginTop: '5px' }}>
<div className="row gce-instance-build-custom-select">
<div className="col-md-5 sm-label-right">
<b>Memory (Gb) </b>
<HelpField id="gce.instance.customInstance.memory" />
</div>
<div className="col-md-3">
<Select
options={memoryOptions}
clearable={false}
value={{ label: selectedMemoryLabel, value: this.props.selectedMemory }}
onChange={this.handleMemoryChange}
/>
{this.props.selectedExtendedMemory ? (
<input
type="number"
name="memory"
className="form-control"
value={this.props.selectedMemory}
onChange={(event) => this.handleMemoryChangeCustom(event.target.value)}
/>
) : (
<Select
options={memoryOptions}
clearable={false}
value={{ label: selectedMemoryLabel, value: this.props.selectedMemory }}
onChange={this.handleMemoryChange}
/>
)}
</div>
</div>
{this.props.selectedInstanceFamily !== 'E2' ? (
<div className="row gce-instance-build-custom-select">
<div className="col-md-5 sm-label-right"></div>
<div className="col-md-3">
<span className="gce-instance-build-custom-extended-memory-checkbox">
<CheckboxInput
name="extendedMemory"
text="Extended Memory"
checked={this.props.selectedExtendedMemory}
onChange={(event: { target: { checked: boolean } }) => {
this.handleExtendedMemory(event.target.checked);
}}
/>
<div className="gce-instance-build-custom-extended-memory-checkbox-helptext">
<HelpField id="gce.instance.customInstance.extendedmemory" />
</div>
</span>
</div>
</div>
) : null}
</div>
);
}
Expand All @@ -88,6 +121,7 @@ export class CustomInstanceConfigurer extends React.Component<ICustomInstanceCon
instanceFamily: this.props.selectedInstanceFamily,
vCpuCount: value,
memory: this.props.selectedMemory,
extendedMemory: this.props.selectedExtendedMemory,
});
};

Expand All @@ -97,6 +131,7 @@ export class CustomInstanceConfigurer extends React.Component<ICustomInstanceCon
instanceFamily: this.props.selectedInstanceFamily,
vCpuCount: this.props.selectedVCpuCount,
memory: value,
extendedMemory: this.props.selectedExtendedMemory,
});
};

Expand All @@ -106,6 +141,26 @@ export class CustomInstanceConfigurer extends React.Component<ICustomInstanceCon
instanceFamily: value,
vCpuCount: this.props.selectedVCpuCount,
memory: this.props.selectedMemory,
extendedMemory: value === 'E2' ? false : this.props.selectedExtendedMemory,
});
};

private handleMemoryChangeCustom = (val: string) => {
const value = +val;
this.props.onChange({
instanceFamily: this.props.selectedInstanceFamily,
vCpuCount: this.props.selectedVCpuCount,
memory: value,
extendedMemory: this.props.selectedExtendedMemory,
});
};

private handleExtendedMemory = (checked: boolean) => {
this.props.onChange({
instanceFamily: this.props.selectedInstanceFamily,
vCpuCount: this.props.selectedVCpuCount,
memory: this.props.selectedMemory,
extendedMemory: checked,
});
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
selected-v-cpu-count="instanceArchetypeCtrl.command.viewState.customInstance.vCpuCount"
memory-list="instanceArchetypeCtrl.command.backingData.customInstanceTypes.memoryList"
selected-memory="instanceArchetypeCtrl.command.viewState.customInstance.memory"
selected-extended-memory="instanceArchetypeCtrl.command.viewState.customInstance.extendedMemory"
on-change="instanceArchetypeCtrl.command.setCustomInstanceViewState"
></gce-custom-instance-configurer>
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
.gce-instance-build-custom-select {
margin-top: 5px;
.gce-instance-build-custom-extended-memory-checkbox {
display: flex;
}
.gce-instance-build-custom-extended-memory-checkbox-helptext {
margin: 8px 0px 0px 3px;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ module(GCE_CUSTOM_INSTANCE_CONFIGURER, []).component(
'selectedVCpuCount',
'selectedMemory',
'selectedInstanceFamily',
'selectedExtendedMemory',
'onChange',
]),
);

0 comments on commit e108e95

Please sign in to comment.