Skip to content

Commit

Permalink
make ingress extensible
Browse files Browse the repository at this point in the history
  • Loading branch information
eminugurkenar committed Oct 21, 2024
1 parent c840f1c commit 54b486e
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions src/ingress.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,16 @@ export interface IngressProps extends base.ResourceProps {
* additional Ingress configuration, including the name of the Ingress controller.
*/
readonly className?: string;

/**
* A custom comparison function used to sort ingress paths.
* This function compares two `HttpIngressPath` objects, `a` and `b`, and returns:
* - A negative number if `a` should appear before `b`
* - A positive number if `a` should appear after `b`
* - Zero if their order does not matter.
* This function can be customized to control how ingress paths are ordered when applied to an array of paths.
*/
readonly pathCompareFn?: ((a: k8s.HttpIngressPath, b: k8s.HttpIngressPath) => number);
}

/**
Expand Down Expand Up @@ -90,10 +100,13 @@ export class Ingress extends base.Resource {
private readonly _rulesPerHost: { [host: string]: k8s.HttpIngressPath[] } = {};
private _defaultBackend?: IngressBackend;
private readonly _tlsConfig: IngressTls[] = [];
private readonly _pathCompareFn: ((a: k8s.HttpIngressPath, b: k8s.HttpIngressPath) => number)

constructor(scope: Construct, id: string, props: IngressProps = {}) {
super(scope, id);

this._pathCompareFn = props.pathCompareFn ?? sortByPath

this.apiObject = new k8s.KubeIngress(this, 'Resource', {
metadata: props.metadata,
spec: {
Expand Down Expand Up @@ -217,7 +230,7 @@ export class Ingress extends base.Resource {
for (const [host, paths] of Object.entries(this._rulesPerHost)) {
rules.push({
host: host ? host : undefined,
http: { paths: paths.sort(sortByPath) },
http: { paths: paths.sort(this._pathCompareFn) },
});
}

Expand Down Expand Up @@ -319,7 +332,7 @@ export class IngressBackend {
});
}

private constructor(private readonly backend: k8s.IngressBackend) {
constructor(private readonly backend: k8s.IngressBackend) {

}

Expand Down

0 comments on commit 54b486e

Please sign in to comment.