Skip to content

Commit

Permalink
feat(service): support publishNotReadyAddresses (#4500)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
serhatcetinkaya authored Aug 12, 2024
1 parent b3399e2 commit 1418e52
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

}

/**
Expand Down Expand Up @@ -210,6 +220,7 @@ export class Service extends base.Resource {
private readonly _selector: Record<string, string>;
private readonly _ports: ServicePort[];
private readonly _loadBalancerSourceRanges?: string[];
private readonly _publishNotReadyAddresses?: boolean;

constructor(scope: Construct, id: string, props: ServiceProps = {}) {
super(scope, id);
Expand All @@ -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);
Expand Down Expand Up @@ -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,
Expand Down
11 changes: 11 additions & 0 deletions test/service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});

0 comments on commit 1418e52

Please sign in to comment.