Skip to content

Commit

Permalink
validate that AKS node pool count is no more than 1000 (#13039)
Browse files Browse the repository at this point in the history
* validate that AKS node pool count is no more than 1000

* update validation message
  • Loading branch information
mantis-toboggan-md authored Jan 14, 2025
1 parent 293cff6 commit 574248d
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
4 changes: 2 additions & 2 deletions pkg/aks/l10n/en-us.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,8 @@ aks:
availabilityZones: Availability zones are not available in the selected region.
privateDnsZone: Private DNS Zone Resource ID must be in the format /subscriptions/SUBSCRIPTION_ID/resourceGroups/RESOURCEGROUP_NAME/providers/Microsoft.Network/privateDnsZones/PRIVATE_DNS_ZONE_NAME. The Private DNS Zone Resource Name must be in the format privatelink.REGION.azmk8s.io, SUBZONE.privatelink.REGION.azmk8s.io, private.REGION.azmk8s.io, or SUBZONE.private.REGION.azmk8s.io
poolName: Node pool names must be 1-12 characters long, consist only of lowercase letters and numbers, and start with a letter.
poolCount: Node count must be at least one in System pools.
poolUserCount: Node count cannot be less than zero.
poolCount: Node count must be at least 1 and at most 1000 in System pools.
poolUserCount: Node count cannot be less than 0 or greater than 1000 in User pools.
poolMinMax: The minimum number of nodes must be less than or equal to the maximum number of nodes, and the node count must be between or equal to the minimum and maximum.
poolMin: The minimum number of nodes must be greater than 0 and at most 1000.
poolMax: The maximum number of nodes must be greater than 0 and at most 1000.
Expand Down
17 changes: 15 additions & 2 deletions pkg/aks/util/__tests__/validators.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,19 +140,24 @@ describe('fx: nodePoolNames', () => {

describe('fx: nodePoolCount', () => {
// AksNodePool unit tests check that the second arg is passed in as expected
it('validates that count is at least 1 when second arg is false', () => {
it('validates that count is at least 1 and at most 1000 when second arg is false', () => {
const validator = validators.nodePoolCount(mockCtx);

expect(validator(1, false)).toBeUndefined();
expect(validator(0, false)).toStrictEqual(MOCK_TRANSLATION);
expect(validator(1000, false)).toBeUndefined();
expect(validator(1001, false)).toStrictEqual(MOCK_TRANSLATION);
});

it('validates that count is at least 0 when second arg is true', () => {
it('validates that count is at least 0 and at most 1000 when second arg is true', () => {
const validator = validators.nodePoolCount(mockCtx);

expect(validator(1, true)).toBeUndefined();
expect(validator(0, true)).toBeUndefined();
expect(validator(1000, true)).toBeUndefined();

expect(validator(-1, true)).toStrictEqual(MOCK_TRANSLATION);
expect(validator(1001, true)).toStrictEqual(MOCK_TRANSLATION);
});

it('validates each node pool in the provided context when not passed a count value', () => {
Expand All @@ -170,6 +175,12 @@ describe('fx: nodePoolCount', () => {
},
{
name: 'klm', _validation: {}, mode: 'User', count: -1
},
{
name: 'nop', _validation: {}, mode: 'User', count: 1001
},
{
name: 'qrs', _validation: {}, mode: 'System', count: 1001
}
] as unknown as AKSNodePool[]
};
Expand All @@ -180,5 +191,7 @@ describe('fx: nodePoolCount', () => {
expect(ctx.nodePools[1]?._validation?._validCount).toStrictEqual(true);
expect(ctx.nodePools[2]?._validation?._validCount).toStrictEqual(true);
expect(ctx.nodePools[3]?._validation?._validCount).toStrictEqual(false);
expect(ctx.nodePools[4]?._validation?._validCount).toStrictEqual(false);
expect(ctx.nodePools[5]?._validation?._validCount).toStrictEqual(false);
});
});
5 changes: 3 additions & 2 deletions pkg/aks/util/validators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,14 +181,15 @@ export const nodePoolNamesUnique = (ctx: any) => {
export const nodePoolCount = (ctx:any) => {
return (count?: number, canBeZero = false) => {
let min = 1;
const max = 1000;
let errMsg = ctx.t('aks.errors.poolCount');

if (canBeZero) {
min = 0;
errMsg = ctx.t('aks.errors.poolUserCount');
}
if (count || count === 0) {
return count >= min ? undefined : errMsg;
return count >= min && count <= max ? undefined : errMsg;
} else {
let allValid = true;

Expand All @@ -201,7 +202,7 @@ export const nodePoolCount = (ctx:any) => {
min = 1;
}

if (count < min) {
if (count < min || count > max) {
pool._validation['_validCount'] = false;
allValid = false;
} else {
Expand Down

0 comments on commit 574248d

Please sign in to comment.