Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add KubernetesIngressAddOn for enhanced Ingress Management #989

Merged
merged 41 commits into from
Jun 28, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
96a1075
added kubernetes nginx addon
Apr 23, 2024
3a0a9fa
Add KubernetesIngressAddOn for enhanced ingress management
Apr 23, 2024
b0ae0e5
added kubernetes nginx test
Apr 24, 2024
0d26f2d
added semi-colon
Apr 24, 2024
a39f0d7
updated the KubernetesIngressAddOnProps interface to include properti…
Apr 24, 2024
18d1121
made the corrections Ela suggested and added the docs for addon along…
Jun 3, 2024
29f7ed7
Merge remote-tracking branch 'upstream/main' into add-kubernetes-ingr…
Jun 3, 2024
35153df
Resolved merge conflicts
Jun 3, 2024
d572c92
Resolved merge conflicts
Jun 3, 2024
08b9b79
Merge branch 'aws-quickstart:main' into add-kubernetes-ingress-addon
Pjv93 Jun 3, 2024
adf9d3e
Updated Kubernetes-Nginx addon
Pjv93 Jun 3, 2024
58505d0
uploaded kubernetes-nginx.md file
Pjv93 Jun 3, 2024
02b3604
Update mkdocs.yml
Pjv93 Jun 3, 2024
e9cad83
Update index.md
Pjv93 Jun 3, 2024
698b52c
Update and rename kubernetes-nginx.md to kubernetes-ingress.md
Pjv93 Jun 3, 2024
0f85308
Update index.md
Pjv93 Jun 3, 2024
dff5d9e
Recreated folder with proper kubernetes-ingressa and added index.ts
Pjv93 Jun 3, 2024
cc8a11e
Update index.ts
Pjv93 Jun 3, 2024
1ed7d1e
Update mkdocs.yml
Pjv93 Jun 3, 2024
d9c396c
Update index.ts
Pjv93 Jun 3, 2024
a4e103c
Delete lib/addons/kubernetes-nginx directory as I have renamed the fi…
Pjv93 Jun 19, 2024
1a18751
Update mkdocs.yml added kubeshark to resolve confilct
Pjv93 Jun 19, 2024
6d8aa04
Update package.json to resolve conflicts
Pjv93 Jun 19, 2024
ef31d19
updated mkdocs.yml file
Jun 19, 2024
837fa61
resolved conflicts
Jun 19, 2024
79c0311
renamed test file to kubernetes-ingress.test.ts
Jun 19, 2024
fb899b2
removed test files
Jun 19, 2024
59be4fb
resolved conflicts
Jun 19, 2024
ba29239
modified file references from kubernetes-ingress to ingress-nginx.md
Jun 25, 2024
9f671f2
Merge branch 'aws-quickstart:main' into add-kubernetes-ingress-addon
Pjv93 Jun 25, 2024
1f077e8
Merge branch 'aws-quickstart:main' into add-kubernetes-ingress-addon
Pjv93 Jun 27, 2024
e554ae2
Update index.ts - corrected ingress addon name and removed params
Pjv93 Jun 27, 2024
e58fa7c
Update index.ts added ingress-nginx
Pjv93 Jun 27, 2024
f89aad8
added ingress-nginx.md to mkdocs.yml
Jun 25, 2024
6f3a6b9
removed kubernetesNginxAddOn references to IngressNginxAddOn
Jun 25, 2024
eb528fa
removed kubernetes-nginx conflict
Jun 27, 2024
e407116
Merge remote-tracking branch 'upstream/main' into add-kubernetes-ingr…
Jun 27, 2024
6ad6bb0
updated title to Ingress Nginx Addon
Jun 27, 2024
0442bfa
modified ingress name from nginx to ingress-nginx
Jun 28, 2024
2c1ceb2
added semi-colon to resolve lint warning
Jun 28, 2024
14b3b4a
added ClusterIP value to blueprint-construct file
Jun 28, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/addons/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
export * from './neuron';
export * from './eks-pod-identity-agent';
export * from './neuron';
export * from './kubernetes-nginx'

Check warning on line 63 in lib/addons/index.ts

View workflow job for this annotation

GitHub Actions / build (20.10.0)

Missing semicolon
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing semi colon


export class Constants {
public static readonly BLUEPRINTS_ADDON = "blueprints-addon";
Expand Down
112 changes: 112 additions & 0 deletions lib/addons/kubernetes-nginx/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
// Import necessary AWS CDK and utility modules
import { ICertificate, Certificate } from "aws-cdk-lib/aws-certificatemanager";

Check warning on line 2 in lib/addons/kubernetes-nginx/index.ts

View workflow job for this annotation

GitHub Actions / build (20.10.0)

'ICertificate' is defined but never used
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove ICertificate.

import { Construct } from "constructs";
import { merge } from "ts-deepmerge";
import * as dot from 'dot-object';
import { dependable, supportsALL } from "../../utils";
import { setPath } from "../../utils/object-utils";
import { AwsLoadBalancerControllerAddOn, ClusterInfo, Values, HelmAddOn, HelmAddOnProps, HelmAddOnUserProps, GlobalResources } from "@aws-quickstart/eks-blueprints";

Check warning on line 8 in lib/addons/kubernetes-nginx/index.ts

View workflow job for this annotation

GitHub Actions / build (20.10.0)

'GlobalResources' is defined but never used

Check failure on line 8 in lib/addons/kubernetes-nginx/index.ts

View workflow job for this annotation

GitHub Actions / build (20.10.0)

Cannot find module '@aws-quickstart/eks-blueprints' or its corresponding type declarations.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove GlobalResources if not used


// Define the properties for the Kubernetes Ingress Add-On with optional and required settings
export interface KubernetesIngressAddOnProps extends HelmAddOnUserProps {
backendProtocol?: string;
crossZoneEnabled?: boolean;
internetFacing?: boolean;
targetType?: string;
externalDnsHostname?: string;
certificateDomainName?: string;
ingressClassName?: string;
controllerClass?: string;
electionId?: string;
isDefaultClass?: boolean;
certificateResourceName?: string;
}

// Set default properties for the add-on
const defaultProps: KubernetesIngressAddOnProps = {
name: "kubernetes-ingress",

Check failure on line 27 in lib/addons/kubernetes-nginx/index.ts

View workflow job for this annotation

GitHub Actions / build (20.10.0)

Object literal may only specify known properties, and 'name' does not exist in type 'KubernetesIngressAddOnProps'.
Pjv93 marked this conversation as resolved.
Show resolved Hide resolved
chart: "ingress-nginx",
release: "k8s-ingress",
version: "4.10.0",
repository: "https://kubernetes.github.io/ingress-nginx",
backendProtocol: 'http',
crossZoneEnabled: true,
internetFacing: true,
targetType: 'ip',
namespace: 'kube-system',
};

// Define the class for the Kubernetes Ingress Add-On, extending HelmAddOn
@supportsALL
export class KubernetesIngressAddOn extends HelmAddOn {
private readonly options: KubernetesIngressAddOnProps;

// Constructor for the class, merging default props with user-defined props
constructor(props?: KubernetesIngressAddOnProps) {
super({ ...defaultProps, ...props } as HelmAddOnProps);
this.options = { ...defaultProps, ...props } as KubernetesIngressAddOnProps;
}

// Dependency decorator to ensure this add-on is deployed after the AWS Load Balancer Controller
@dependable(AwsLoadBalancerControllerAddOn.name)
async deploy(clusterInfo: ClusterInfo): Promise<Construct> {
const props = this.options;

// Log for debugging: shows the certificate domain name used
console.log("Using certificate domain name: ", props.certificateDomainName);

// Setup service annotations based on the properties provided
const presetAnnotations: any = {
'service.beta.kubernetes.io/aws-load-balancer-backend-protocol': props.backendProtocol,
'service.beta.kubernetes.io/aws-load-balancer-attributes': `load_balancing.cross_zone.enabled=${props.crossZoneEnabled}`,
'service.beta.kubernetes.io/aws-load-balancer-scheme': props.internetFacing ? 'internet-facing' : 'internal',
'service.beta.kubernetes.io/aws-load-balancer-type': 'external',
'service.beta.kubernetes.io/aws-load-balancer-nlb-target-type': props.targetType,
'external-dns.alpha.kubernetes.io/hostname': props.externalDnsHostname,
'service.beta.kubernetes.io/aws-load-balancer-connection-idle-timeout': '3600'
};

// Define values for Helm chart based on properties and annotations
const values: Values = {
controller: {
service: {
annotations: presetAnnotations
},
ingressClassResource: {
name: props.ingressClassName || "nginx",
enabled: true,
default: props.isDefaultClass ?? false,
controllerValue: props.controllerClass || "k8s.io/ingress-nginx"
},
electionID: props.electionId || "ingress-controller-leader"
}
};

// Create a certificate if a domain name is provided
if (props.certificateDomainName) {
const certificate = new Certificate(clusterInfo.cluster, 'MyCertificate', {
domainName: props.certificateDomainName,
});
console.log("Certificate ARN:", certificate.certificateArn);
presetAnnotations['service.beta.kubernetes.io/aws-load-balancer-ssl-cert'] = certificate.certificateArn;
}

// Configure SSL-related annotations if certificate resource name is provided
if (props.certificateResourceName) {
presetAnnotations['service.beta.kubernetes.io/aws-load-balancer-ssl-ports'] = 'https';
presetAnnotations['service.beta.kubernetes.io/aws-load-balancer-ssl-cert'] = props.certificateResourceName;
presetAnnotations['nginx.ingress.kubernetes.io/force-ssl-redirect'] = true;

// Set HTTP and HTTPS target ports
setPath(values, "controller.service.targetPorts.http", "http");
const httpsTargetPort = dot.pick("controller.service.targetPorts.https", props.values) || "http";

Check failure on line 102 in lib/addons/kubernetes-nginx/index.ts

View workflow job for this annotation

GitHub Actions / build (20.10.0)

Property 'values' does not exist on type 'KubernetesIngressAddOnProps'.
setPath(values, "controller.service.targetPorts.https", httpsTargetPort);
}

// Merge user-defined values with defaults for the Helm chart deployment
const mergedValues = merge(values, this.props.values ?? {});

Check failure on line 107 in lib/addons/kubernetes-nginx/index.ts

View workflow job for this annotation

GitHub Actions / build (20.10.0)

Property 'props' does not exist on type 'KubernetesIngressAddOn'.
const nginxHelmChart = this.addHelmChart(clusterInfo, mergedValues);

Check failure on line 108 in lib/addons/kubernetes-nginx/index.ts

View workflow job for this annotation

GitHub Actions / build (20.10.0)

Property 'addHelmChart' does not exist on type 'KubernetesIngressAddOn'.

return Promise.resolve(nginxHelmChart);
}
}
Loading