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

fix(ingress): add ingressClassName to IngressProps (#2964) #3765

Merged
merged 1 commit into from
Feb 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
9 changes: 9 additions & 0 deletions src/ingress.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,14 @@ export interface IngressProps extends base.ResourceProps {
* extension, if the ingress controller fulfilling the ingress supports SNI.
*/
readonly tls?: IngressTls[];

/**
* Class Name for this ingress.
*
* This field is a reference to an IngressClass resource that contains
* additional Ingress configuration, including the name of the Ingress controller.
*/
readonly className?: string;
}

/**
Expand Down Expand Up @@ -90,6 +98,7 @@ export class Ingress extends base.Resource {
metadata: props.metadata,
spec: {
defaultBackend: Lazy.any({ produce: () => this._defaultBackend?._toKube() }),
ingressClassName: props.className,
rules: Lazy.any({ produce: () => this.synthRules() }),
tls: Lazy.any({ produce: () => this.tlsConfig() }),
},
Expand Down
30 changes: 30 additions & 0 deletions test/ingress.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,36 @@ test('defaultChild', () => {

});

test('IngressClassName can be set', () => {
// GIVEN
const chart = Testing.chart();
const service = new Service(chart, 'my-service', { ports: [{ port: 80 }] } );

// WHEN
new Ingress(chart, 'my-ingress', {
defaultBackend: IngressBackend.fromService(service),
className: 'myIngressClassName',
});

// THEN
expect(Testing.synth(chart).filter(x => x.kind === 'Ingress')).toStrictEqual([
{
apiVersion: 'networking.k8s.io/v1',
kind: 'Ingress',
metadata: { name: 'test-my-ingress-c8135042' },
spec: {
defaultBackend: {
service: {
name: 'test-my-service-c8493104',
port: { number: 80 },
},
},
ingressClassName: 'myIngressClassName',
},
},
]);
});

describe('IngressBackend', () => {
describe('fromService', () => {
test('if the service exposes a port, it will be used by the ingress', () => {
Expand Down
Loading