Skip to content

Commit

Permalink
feat(versioning): aws-eks-addon versioning added
Browse files Browse the repository at this point in the history
Signed-off-by: ivan katliarchuk <[email protected]>
  • Loading branch information
ivankatliarchuk committed Dec 27, 2024
1 parent dc53eca commit 785cbb4
Show file tree
Hide file tree
Showing 4 changed files with 185 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/modules/versioning/api.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import * as awsEksAddon from './aws-eks-addon';

Check failure on line 1 in lib/modules/versioning/api.ts

View workflow job for this annotation

GitHub Actions / lint-eslint

Unable to resolve path to module './aws-eks-addon'.

Check failure on line 1 in lib/modules/versioning/api.ts

View workflow job for this annotation

GitHub Actions / lint-other

Cannot find module './aws-eks-addon' or its corresponding type declarations.

Check failure on line 1 in lib/modules/versioning/api.ts

View workflow job for this annotation

GitHub Actions / build

Cannot find module './aws-eks-addon' or its corresponding type declarations.

Check failure on line 1 in lib/modules/versioning/api.ts

View workflow job for this annotation

GitHub Actions / test (7/16)

modules/platform/bitbucket/index › initPlatform() › should throw if no token or username/password

Cannot find module './aws-eks-addon' from 'lib/modules/versioning/api.ts' Require stack: lib/modules/versioning/api.ts lib/modules/versioning/index.ts lib/util/exec/containerbase.ts lib/util/exec/index.ts lib/util/git/private-key.ts lib/util/git/index.ts at Resolver._throwModNotFoundError (node_modules/.pnpm/[email protected]/node_modules/jest-resolve/build/resolver.js:427:11) at Object.require (lib/modules/versioning/api.ts:1:1) at Object.require (lib/modules/versioning/index.ts:1:1) at Object.require (lib/util/exec/containerbase.ts:6:1) at Object.require (lib/util/exec/index.ts:7:1) at Object.require (lib/util/git/private-key.ts:7:1) at Object.require (lib/util/git/index.ts:47:1) at Object.require (lib/modules/platform/bitbucket/index.ts:7:1) at lib/modules/platform/bitbucket/index.spec.ts:35:17 at Object.<anonymous> (lib/modules/platform/bitbucket/index.spec.ts:35:17)

Check warning on line 1 in lib/modules/versioning/api.ts

View check run for this annotation

Codecov / codecov/patch

lib/modules/versioning/api.ts#L1

Added line #L1 was not covered by tests
import * as amazonMachineImage from './aws-machine-image';
import * as azureRestApi from './azure-rest-api';
import * as bazelModule from './bazel-module';
Expand Down Expand Up @@ -45,6 +46,7 @@ import * as unity3d from './unity3d';
const api = new Map<string, VersioningApi | VersioningApiConstructor>();
export default api;

api.set(awsEksAddon.id, awsEksAddon.api);

Check warning on line 49 in lib/modules/versioning/api.ts

View check run for this annotation

Codecov / codecov/patch

lib/modules/versioning/api.ts#L49

Added line #L49 was not covered by tests
api.set(amazonMachineImage.id, amazonMachineImage.api);
api.set(azureRestApi.id, azureRestApi.api);
api.set(bazelModule.id, bazelModule.api);
Expand Down
105 changes: 105 additions & 0 deletions lib/modules/versioning/aws-eks-addons/index.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
import aws from '.';

describe('modules/versioning/aws-eks-addon/index', () => {

Check failure on line 3 in lib/modules/versioning/aws-eks-addons/index.spec.ts

View workflow job for this annotation

GitHub Actions / lint-eslint

Test must be described by this string: 'modules/versioning/aws-eks-addons/index'
describe('parse(version)', () => {
it('should return 1.23.7 and release version', () => {
expect(aws.getMajor('v1.20.7-eksbuild.1')).toBe(1);
expect(aws.getMinor('v1.23.7-eksbuild.1')).toBe(23);
expect(aws.getPatch('v1.20.7-eksbuild.1')).toBe(7);
});
});

describe('isValid(version)', () => {
it('should return true', () => {
expect(aws.isValid('v1.11.7-eksbuild.23')).toBeTruthy();
});

it('should return false', () => {
expect(aws.isValid('v1.11.7-noneksbuild.23')).toBeFalsy();
});
});

describe('isVersion(version)', () => {
it('should return true', () => {
expect(aws.isVersion('v1.11.7-eksbuild.1')).toBeTruthy();
});

it('should return false', () => {
expect(aws.isVersion('v1.11.7')).toBeFalsy();
});
});

describe('isCompatible(version)', () => {
it.each`
input | expected
${''} | ${false}
${'abrakadabra'} | ${false}
${'v1.11.7'} | ${false}
${'v1.11.7.6'} | ${false}
${'v1.11.7-noneksbuild'} | ${false}
${'v1.11.7-noneksbuild.1'} | ${false}
${'v1.11.7-eksbuild'} | ${false}
${'v1.11.7.3-eksbuild.1'} | ${false}
`('isCompatible("$input") === $expected', ({ input, expected }) => {
const actual = aws.isCompatible(input);
expect(actual).toBe(expected);
});
});

describe('isCompatible(version,range)', () => {
it('should return true', () => {
expect(
aws.isCompatible('v1.11.7-eksbuild.1', 'v1.2.7-eksbuild.1'),
).toBeTruthy();
});

it('should return false', () => {
expect(
aws.isCompatible('v1.11.7-eksbuild.1', 'v1.11.7-noneksbuild.1'),
).toBeFalsy();
});
});

describe('isGreaterThan(version1, version2)', () => {
it('should return true', () => {
expect(
aws.isGreaterThan('v1.11.7-eksbuild.1', 'v1.11.7-eksbuild.0'),
).toBeTrue();
expect(
aws.isGreaterThan('v1.20.7-eksbuild.2', 'v1.20.7-eksbuild.1'),
).toBeTrue();
expect(
aws.isGreaterThan('v1.22.7-eksbuild.2', 'v1.20.7-eksbuild.1'),
).toBeTrue();
expect(aws.isGreaterThan('v1.22.7-eksbuild.2', 'v1.22.7')).toBeTrue();
expect(aws.isGreaterThan('v1.20.7-eksbuild.1', 'v2.0.0')).toBeTrue();
});

it('should return false', () => {
expect(
aws.isGreaterThan('v1.20.7-eksbuild.1', 'v1.20.7-eksbuild.2'),
).toBeFalsy();
expect(
aws.isGreaterThan('v1.20.7-eksbuild.1', 'v2.0.0-eksbuild.1'),
).toBeFalsy();
});
});

it('getSatisfyingVersion', () => {
expect(
aws.getSatisfyingVersion(['v1.20.7-eksbuild.1'], 'v1.20.7-eksbuild.1'),
).toBe('v1.20.7-eksbuild.1');
expect(
aws.getSatisfyingVersion(
['v1.20.7-eksbuild.1', 'v1.20.7-eksbuild.2', 'v1.20.7-eksbuild.7'],
'v1.20.7-eksbuild.3',
),
).toBeNull();
expect(
aws.getSatisfyingVersion(
['v1.20.7-eksbuild.1', 'v1.20.7-eksbuild.2'],
'v1.20.7-eksbuild.3',
),
).toBeNull();
});
});
60 changes: 60 additions & 0 deletions lib/modules/versioning/aws-eks-addons/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import { regEx } from '../../../util/regex';
import { coerceString } from '../../../util/string';

Check warning on line 2 in lib/modules/versioning/aws-eks-addons/index.ts

View check run for this annotation

Codecov / codecov/patch

lib/modules/versioning/aws-eks-addons/index.ts#L1-L2

Added lines #L1 - L2 were not covered by tests
import type { GenericVersion } from '../generic';
import { GenericVersioningApi } from '../generic';

Check warning on line 4 in lib/modules/versioning/aws-eks-addons/index.ts

View check run for this annotation

Codecov / codecov/patch

lib/modules/versioning/aws-eks-addons/index.ts#L4

Added line #L4 was not covered by tests
import type { VersioningApi } from '../types';

export const id = 'aws-eks-addon';
export const displayName = 'aws-eks-addon';

Check warning on line 8 in lib/modules/versioning/aws-eks-addons/index.ts

View check run for this annotation

Codecov / codecov/patch

lib/modules/versioning/aws-eks-addons/index.ts#L7-L8

Added lines #L7 - L8 were not covered by tests

export const urls = [];

Check warning on line 10 in lib/modules/versioning/aws-eks-addons/index.ts

View check run for this annotation

Codecov / codecov/patch

lib/modules/versioning/aws-eks-addons/index.ts#L10

Added line #L10 was not covered by tests

export const supportsRanges = false;

Check warning on line 12 in lib/modules/versioning/aws-eks-addons/index.ts

View check run for this annotation

Codecov / codecov/patch

lib/modules/versioning/aws-eks-addons/index.ts#L12

Added line #L12 was not covered by tests

const versionPattern = regEx(

Check warning on line 14 in lib/modules/versioning/aws-eks-addons/index.ts

View check run for this annotation

Codecov / codecov/patch

lib/modules/versioning/aws-eks-addons/index.ts#L14

Added line #L14 was not covered by tests
'^[vV]?(\\d+(?:\\.\\d+)*)(?<metadata>-eksbuild\\.\\d+)?$',
);

class AwsEKSAddonVersioningApi extends GenericVersioningApi {
protected _parse(version: string): GenericVersion | null {
if (!version) {
return null;

Check warning on line 21 in lib/modules/versioning/aws-eks-addons/index.ts

View check run for this annotation

Codecov / codecov/patch

lib/modules/versioning/aws-eks-addons/index.ts#L21

Added line #L21 was not covered by tests
}
const matches: RegExpExecArray | null = versionPattern.exec(version);

Check warning on line 23 in lib/modules/versioning/aws-eks-addons/index.ts

View check run for this annotation

Codecov / codecov/patch

lib/modules/versioning/aws-eks-addons/index.ts#L23

Added line #L23 was not covered by tests
if (!matches) {
return null;

Check warning on line 25 in lib/modules/versioning/aws-eks-addons/index.ts

View check run for this annotation

Codecov / codecov/patch

lib/modules/versioning/aws-eks-addons/index.ts#L25

Added line #L25 was not covered by tests
}
const [, prefix, suffix] = matches;

Check warning on line 27 in lib/modules/versioning/aws-eks-addons/index.ts

View check run for this annotation

Codecov / codecov/patch

lib/modules/versioning/aws-eks-addons/index.ts#L27

Added line #L27 was not covered by tests
if (!suffix) {
return null;

Check warning on line 29 in lib/modules/versioning/aws-eks-addons/index.ts

View check run for this annotation

Codecov / codecov/patch

lib/modules/versioning/aws-eks-addons/index.ts#L29

Added line #L29 was not covered by tests
}
const release: number[] = prefix.split('.').map(Number);

Check warning on line 31 in lib/modules/versioning/aws-eks-addons/index.ts

View check run for this annotation

Codecov / codecov/patch

lib/modules/versioning/aws-eks-addons/index.ts#L31

Added line #L31 was not covered by tests
if (release.length !== 3) {
return null;

Check warning on line 33 in lib/modules/versioning/aws-eks-addons/index.ts

View check run for this annotation

Codecov / codecov/patch

lib/modules/versioning/aws-eks-addons/index.ts#L33

Added line #L33 was not covered by tests
}
return { release, suffix };

Check warning on line 35 in lib/modules/versioning/aws-eks-addons/index.ts

View check run for this annotation

Codecov / codecov/patch

lib/modules/versioning/aws-eks-addons/index.ts#L35

Added line #L35 was not covered by tests
}

protected override _compare(version: string, other: string): number {
const compare: number = super._compare(version, other);

Check warning on line 39 in lib/modules/versioning/aws-eks-addons/index.ts

View check run for this annotation

Codecov / codecov/patch

lib/modules/versioning/aws-eks-addons/index.ts#L39

Added line #L39 was not covered by tests
if (compare !== 0) {
return compare;

Check warning on line 41 in lib/modules/versioning/aws-eks-addons/index.ts

View check run for this annotation

Codecov / codecov/patch

lib/modules/versioning/aws-eks-addons/index.ts#L41

Added line #L41 was not covered by tests
}
const parsed1: GenericVersion | null = this._parse(version);
const parsed2: GenericVersion | null = this._parse(other);

Check warning on line 44 in lib/modules/versioning/aws-eks-addons/index.ts

View check run for this annotation

Codecov / codecov/patch

lib/modules/versioning/aws-eks-addons/index.ts#L43-L44

Added lines #L43 - L44 were not covered by tests

const suffix1 = coerceString(parsed1?.suffix);
const suffix2 = coerceString(parsed2?.suffix);
return suffix1.localeCompare(suffix2);

Check warning on line 48 in lib/modules/versioning/aws-eks-addons/index.ts

View check run for this annotation

Codecov / codecov/patch

lib/modules/versioning/aws-eks-addons/index.ts#L46-L48

Added lines #L46 - L48 were not covered by tests
}

override isCompatible(version: string, current: string): boolean {
const parsed1: GenericVersion | null = this._parse(version);
const parsed2: GenericVersion | null = this._parse(current);

Check warning on line 53 in lib/modules/versioning/aws-eks-addons/index.ts

View check run for this annotation

Codecov / codecov/patch

lib/modules/versioning/aws-eks-addons/index.ts#L52-L53

Added lines #L52 - L53 were not covered by tests
return !!(parsed1 && parsed2);
}
}

export const api: VersioningApi = new AwsEKSAddonVersioningApi();

Check warning on line 58 in lib/modules/versioning/aws-eks-addons/index.ts

View check run for this annotation

Codecov / codecov/patch

lib/modules/versioning/aws-eks-addons/index.ts#L58

Added line #L58 was not covered by tests

export default api;

Check warning on line 60 in lib/modules/versioning/aws-eks-addons/index.ts

View check run for this annotation

Codecov / codecov/patch

lib/modules/versioning/aws-eks-addons/index.ts#L60

Added line #L60 was not covered by tests
18 changes: 18 additions & 0 deletions lib/modules/versioning/aws-eks-addons/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
AWS versioning syntax is used for EKS Addon updates.

It is based off [Semantic Versioning 2.0](https://semver.org) but with a subset of addon `build metadata` syntax.

At the moment every ESK Addon that matches the regex `^[vV]?(\d+(?:\.\d+)*)(-eksbuild\.\d+)?$` is considered a valid "release".

**Key Points about EKS Addon Versioning**

1. Versioning Scheme: Add-ons typically follow a semantic versioning scheme (e.g., Major.Minor.Patch). This helps in understanding the significance of changes between versions:

- `Major`: Indicates significant changes or breaking API changes for plugin version.
- `Minor`: Introduces new features or enhancements for plugin version.
- `Patch`: Includes bug fixes and minor improvements for plugin version.
- `Build Metadata` : It helps differentiate this particular release from others that might have been built independently.

2. Default Versions: When creating a new EKS cluster, AWS often selects a default version for each addon based on the cluster's Kubernetes version and other factors. This default version is usually the most stable and recommended for the specific cluster configuration

3. Build metadata. Example `eksbuild.1`. The `eksbuild.1` part signifies a specific build or release within the `1.19.0` version, likely managed by the EKS build system. It helps differentiate this particular release from others that might have been built independently. The build metadata provides additional context about the specific release, which can be useful for tracking and troubleshooting.

0 comments on commit 785cbb4

Please sign in to comment.