Skip to content

Commit

Permalink
Merge pull request #750 from zjaco13/kubeproxy-versioning
Browse files Browse the repository at this point in the history
update kube-proxy to auto choose version
  • Loading branch information
elamaran11 authored Jul 10, 2023
2 parents abbd7f9 + 1b346c2 commit ebef7d3
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 14 deletions.
18 changes: 9 additions & 9 deletions docs/addons/kube-proxy.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,27 +20,27 @@ import * as blueprints from '@aws-quickstart/eks-blueprints';

const app = new cdk.App();

const addOn = new blueprints.addons.KubeProxyAddOn('v1.19.6-eksbuild.2'); // optionally specify the image version to pull or empty constructor
const addOn = new blueprints.addons.KubeProxyAddOn('v1.27.1-eksbuild.1'); // optionally specify the image version to pull or empty constructor for auto selection

const blueprint = blueprints.EksBlueprint.builder()
.addOns(addOn)
.build(app, 'my-stack-name');
```
## Configuration Options

- `version`: Pass in the kube-proxy plugin version compatible with kubernetes-cluster version as shown below
- `version`: Optionally pass in the kube-proxy plugin version compatible with kubernetes-cluster version as shown below
```bash
# Assuming cluster version is 1.20, below command shows versions of the Kube-proxy add-on available for the specified cluster's version.
# Assuming cluster version is 1.27, below command shows versions of the Kube-proxy add-on available for the specified cluster's version.
aws eks describe-addon-versions \
--addon-name kube-proxy \
--kubernetes-version 1.19 \
--kubernetes-version 1.27 \
--query "addons[].addonVersions[].[addonVersion, compatibilities[].defaultVersion]" \
--output text
# Output
v1.19.6-eksbuild.2
True
v1.18.8-eksbuild.1
v1.27.3-eksbuild.1
False
v1.27.1-eksbuild.1
True
```
# Validation
To validate that kube-proxy add-on is running, ensure that the pod is in Running state
Expand All @@ -57,8 +57,8 @@ aws eks describe-addon \
--query "addon.addonVersion" \
--output text
# Output
v1.19.6-eksbuild.2
v1.27.1-eksbuild.1
```
## Functionality

Applies Kube-proxy add-on to Amazon EKS cluster.
Applies Kube-proxy add-on to Amazon EKS cluster.
22 changes: 20 additions & 2 deletions lib/addons/core-addon/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { ClusterAddOn } from "../..";
import { ClusterInfo, Values } from "../../spi";
import { Construct } from "constructs";
import { IManagedPolicy, ManagedPolicy, PolicyDocument } from "aws-cdk-lib/aws-iam";
import { KubernetesVersion } from "aws-cdk-lib/aws-eks";
import { createServiceAccountWithPolicy, deployBeforeCapacity, userLog, } from "../../utils";

export class CoreAddOnProps {
Expand Down Expand Up @@ -36,6 +37,12 @@ export class CoreAddOnProps {
* Indicates that add-on must be installed before any capacity is added for worker nodes (incuding Fargate).
*/
readonly controlPlaneAddOn?: boolean;


/**
* Map between kubernetes versions and addOn versions for auto selection.
*/
readonly versionMap?: Map<KubernetesVersion, string>;
}

const DEFAULT_NAMESPACE = "kube-system";
Expand Down Expand Up @@ -69,10 +76,16 @@ export class CoreAddOn implements ClusterAddOn {
serviceAccount = this.createServiceAccount(clusterInfo, saNamespace, policies);
serviceAccountRoleArn = serviceAccount.role.roleArn;
}
let version: string = this.coreAddOnProps.version;

if (this.coreAddOnProps.versionMap) {
version = this.coreAddOnProps.version != "auto" ? this.coreAddOnProps.version : this.provideVersion(clusterInfo, this.coreAddOnProps.versionMap);
}
userLog.debug(`Core add-on ${this.coreAddOnProps.addOnName} has autoselected version ${version}`);

let addOnProps = {
addonName: this.coreAddOnProps.addOnName,
addonVersion: this.coreAddOnProps.version,
addonVersion: version,
configurationValues: JSON.stringify(this.coreAddOnProps.configurationValues),
clusterName: clusterInfo.cluster.clusterName,
serviceAccountRoleArn: serviceAccountRoleArn,
Expand Down Expand Up @@ -126,4 +139,9 @@ export class CoreAddOn implements ClusterAddOn {
return result;
}

}
provideVersion(clusterInfo: ClusterInfo, versionMap: Map<KubernetesVersion, string>) : string {
let version: string = versionMap.get(clusterInfo.version) ?? versionMap.values().next().value;
return version;
}

}
2 changes: 1 addition & 1 deletion lib/addons/helm-addon/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,4 +92,4 @@ export abstract class HelmAddOn implements spi.ClusterAddOn {
const chart = { ...this.props, ...{ values, dependencyMode, wait, timeout, createNamespace } };
return kubectlProvider.addHelmChart(chart);
}
}
}
14 changes: 12 additions & 2 deletions lib/addons/kube-proxy/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
import { KubernetesVersion } from "aws-cdk-lib/aws-eks";
import { CoreAddOn } from "../core-addon";

const versionMap: Map<KubernetesVersion, string> = new Map([
[KubernetesVersion.of("1.27"), "v1.27.1-eksbuild.1"],
[KubernetesVersion.V1_26, "v1.26.2-eksbuild.1"],
[KubernetesVersion.V1_25, "v1.25.6-eksbuild.1"],
[KubernetesVersion.V1_24, "v1.24.7-eksbuild.2"],
[KubernetesVersion.V1_23, "v1.23.7-eksbuild.1"],
]);

/**
* Implementation of KubeProxy EKS add-on.
*/
Expand All @@ -8,8 +17,9 @@ export class KubeProxyAddOn extends CoreAddOn {
constructor(version?: string) {
super({
addOnName: "kube-proxy",
version: version ?? "v1.25.6-eksbuild.1",
saName: "kube-proxy"
version: version ?? "auto",
saName: "kube-proxy",
versionMap: versionMap,
});
}
}

0 comments on commit ebef7d3

Please sign in to comment.