Skip to content

Commit 0980720

Browse files
Support world connection with ipv6
Signed-off-by: Yannik Messerli <[email protected]>
1 parent 17853a9 commit 0980720

File tree

4 files changed

+47
-7
lines changed

4 files changed

+47
-7
lines changed

src/domain/filtering/__tests__/filter-service.test.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ const testFilterEntry = (
4848
describe('filterService', () => {
4949
const regular = ServiceCard.fromService(services.regular);
5050
const world = ServiceCard.fromService(services.world);
51+
const worldIPv6 = ServiceCard.fromService(services.worldIPv6);
5152
const host = ServiceCard.fromService(services.host);
5253
const remoteNode = ServiceCard.fromService(services.remoteNode);
5354
const kubeDns = ServiceCard.fromService(services.kubeDNS);
@@ -61,11 +62,19 @@ describe('filterService', () => {
6162
expect(regular.workload).toBeTruthy();
6263

6364
expect(world.isWorld).toBe(true);
65+
expect(world.isWorldIPv6).toBe(false);
6466
expect(world.isHost).toBe(false);
6567
expect(world.isKubeDNS).toBe(false);
6668
expect(world.isPrometheusApp).toBe(false);
6769
expect(world.isRemoteNode).toBe(false);
6870

71+
expect(worldIPv6.isWorld).toBe(true);
72+
expect(worldIPv6.isWorldIPv6).toBe(true);
73+
expect(worldIPv6.isHost).toBe(false);
74+
expect(worldIPv6.isKubeDNS).toBe(false);
75+
expect(worldIPv6.isPrometheusApp).toBe(false);
76+
expect(worldIPv6.isRemoteNode).toBe(false);
77+
6978
expect(host.isWorld).toBe(false);
7079
expect(host.isHost).toBe(true);
7180
expect(host.isKubeDNS).toBe(false);

src/domain/labels.ts

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ export enum ReservedLabel {
2222
Host = 'reserved:host',
2323
KubeApiserver = 'reserved:kube-apiserver',
2424
World = 'reserved:world',
25+
WorldIPv6 = 'reserved:world-ipv6',
2526
Health = 'reserved:health',
2627
Init = 'reserved:init',
2728
Ingress = 'reserved:ingress',
@@ -135,6 +136,17 @@ export class Labels {
135136
return null;
136137
}
137138

139+
public static findWorldInLabels(labels: KV[], normalizeLabels = true): string | null {
140+
for (const lbl of labels) {
141+
const kv = normalizeLabels ? Labels.normalizeLabel(lbl) : lbl;
142+
if (kv.key === ReservedLabel.World || kv.key === ReservedLabel.WorldIPv6) {
143+
return kv.key;
144+
}
145+
}
146+
147+
return null;
148+
}
149+
138150
public static containsKey(
139151
lbl: KV,
140152
nkeys: Set<string> | Iterable<string>,
@@ -314,10 +326,6 @@ export class Labels {
314326
return Labels.specialLabelKeys.has(key);
315327
}
316328

317-
public static isWorld(labels: KV[]): boolean {
318-
return Labels.haveReserved(labels, ReservedLabel.World);
319-
}
320-
321329
public static isHost(labels: KV[]): boolean {
322330
return Labels.haveReserved(labels, ReservedLabel.Host);
323331
}
@@ -360,7 +368,10 @@ export class Labels {
360368
labels.forEach((lbl: KV) => {
361369
const kv = Labels.normalizeLabel(lbl);
362370

363-
props.isWorld = !!props.isWorld || Labels.isReserved(kv, ReservedLabel.World, false);
371+
props.isWorld =
372+
!!props.isWorld ||
373+
Labels.isReserved(kv, ReservedLabel.World, false) ||
374+
Labels.isReserved(kv, ReservedLabel.WorldIPv6, false);
364375
props.isKubeApiserver =
365376
!!props.isKubeApiserver || Labels.isReserved(kv, ReservedLabel.KubeApiserver, false);
366377
props.isHost = !!props.isHost || Labels.isReserved(kv, ReservedLabel.Host, false);

src/domain/service-map/card.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,8 @@ export class ServiceCard extends AbstractCard {
142142
result.push(FilterEntry.newLabel(ReservedLabel.Ingress));
143143
}
144144

145-
if (this.isWorld) {
146-
result.push(FilterEntry.newLabel(ReservedLabel.World));
145+
if (this.isWorld && this.worldLabel) {
146+
result.push(FilterEntry.newLabel(this.worldLabel));
147147
}
148148

149149
if (this.isKubeDNS) {
@@ -269,10 +269,19 @@ export class ServiceCard extends AbstractCard {
269269
return this.service.namespace || Labels.findNamespaceInLabels(this.labels);
270270
}
271271

272+
@computed
273+
public get worldLabel(): string | null {
274+
return Labels.findWorldInLabels(this.labels);
275+
}
276+
272277
public get isWorld(): boolean {
273278
return this.labelsProps.isWorld;
274279
}
275280

281+
public get isWorldIPv6(): boolean {
282+
return this.labelsProps.isWorld && this.worldLabel === ReservedLabel.WorldIPv6;
283+
}
284+
276285
public get isHost(): boolean {
277286
return this.labelsProps.isHost;
278287
}

src/testing/data/services.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,3 +126,14 @@ export const sameNamespace = {
126126
labels: replaceNsLabel(kubeDNS.labels),
127127
},
128128
};
129+
130+
export const worldIPv6: HubbleService = {
131+
id: 'world-ipv6-service',
132+
name: 'world-ipv6-service',
133+
namespace: 'world-ipv6-service-ns',
134+
labels: [Labels.toKV(ReservedLabel.WorldIPv6)],
135+
dnsNames: [],
136+
workloads: [],
137+
identity: MockServiceIdentity.World,
138+
...restOfService,
139+
};

0 commit comments

Comments
 (0)