From 1418e525aa6eb2a33118c40c1aabe85184037c7b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?serhat=20=C3=A7etinkaya?= <10282948+serhatcetinkaya@users.noreply.github.com> Date: Mon, 12 Aug 2024 11:50:32 +0300 Subject: [PATCH] feat(service): support `publishNotReadyAddresses` (#4500) add support for publishNotReadyAddresses. for more info: https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.30/#servicespec-v1-core this should be backported to 1.29 and 1.28 main branches --- src/service.ts | 13 +++++++++++++ test/service.test.ts | 11 +++++++++++ 2 files changed, 24 insertions(+) diff --git a/src/service.ts b/src/service.ts index 871ab86be..27bb6a5f8 100644 --- a/src/service.ts +++ b/src/service.ts @@ -94,6 +94,16 @@ export interface ServiceProps extends base.ResourceProps { */ readonly loadBalancerSourceRanges?: string[]; + /** + * The publishNotReadyAddresses indicates that any agent which deals with endpoints for this Service + * should disregard any indications of ready/not-ready + * + * More info: https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.30/#servicespec-v1-core + * + * @default - false + */ + readonly publishNotReadyAddresses?: boolean; + } /** @@ -210,6 +220,7 @@ export class Service extends base.Resource { private readonly _selector: Record; private readonly _ports: ServicePort[]; private readonly _loadBalancerSourceRanges?: string[]; + private readonly _publishNotReadyAddresses?: boolean; constructor(scope: Construct, id: string, props: ServiceProps = {}) { super(scope, id); @@ -232,6 +243,7 @@ export class Service extends base.Resource { this._ports = []; this._selector = { }; this._loadBalancerSourceRanges = props.loadBalancerSourceRanges; + this._publishNotReadyAddresses = props.publishNotReadyAddresses; if (props.selector) { this.select(props.selector); @@ -337,6 +349,7 @@ export class Service extends base.Resource { selector: this._selector, ports: ports, loadBalancerSourceRanges: this._loadBalancerSourceRanges, + publishNotReadyAddresses: this._publishNotReadyAddresses, } : { type: this.type, externalName: this.externalName, diff --git a/test/service.test.ts b/test/service.test.ts index 48083e872..106de6bfa 100644 --- a/test/service.test.ts +++ b/test/service.test.ts @@ -185,3 +185,14 @@ test('can be exposed by an ingress', () => { const ingress = Testing.synth(chart)[1]; expect(ingress).toMatchSnapshot(); }); + +test('can set publishNotReadyAddresses', () => { + const chart = Testing.chart(); + new kplus.Service(chart, 'service', { + ports: [{ port: 80 }], + publishNotReadyAddresses: true, + }); + + const spec = Testing.synth(chart)[0].spec; + expect(spec.publishNotReadyAddresses).toBeTruthy(); +});