Skip to content

Commit 877e64d

Browse files
authored
chore: adds more KRIs to Overview-like things (#5008)
Adds/ensures KRIs are carried through to the summary YAML views. There is also a bit of copy/pasting for consistency reasons between Dataplanes/ZoneProxies. There are reasons for formatting decisions in the code here and I commented it up quite a bit to explain why rather than just depend on the formatting to be self-explanatory (that alone it not explanatory enough I don't think) I renamed the Dataplane tests and added back the ZoneProxy tests but renamed them all to make it clearer what they are testing. Usually we avoid mocking/setting up full data objects to test against, but in this case its the most straight-forwards way to assert that we have neither too many fields or not enough fields. If I think of a different way thats just as straight-forwards but also clearer I might tweak this in the future. Note: We are now expected KRIs to be added to the top-level DataplaneOverviews via the backend. Depending on when this PR gets merged we can either consider this in this PR or a follow up PR once the backend PR is complete. --------- Signed-off-by: John Cowen <john.cowen@konghq.com>
1 parent bcde297 commit 877e64d

8 files changed

Lines changed: 170 additions & 20 deletions

File tree

packages/kuma-gui/src/app/data-planes/data/DataplaneOverview.ts

Lines changed: 37 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { Dataplane } from './Dataplane'
22
import { DataplaneInsight } from './DataplaneInsight'
33
import { DataplaneNetworking } from './DataplaneNetworking'
4+
import { Kri } from '@/app/kuma/kri'
45
import type { PaginatedApiListResponse } from '@/types/api.d'
56
import type {
67
DataPlaneOverview as PartialDataplaneOverview,
@@ -29,7 +30,17 @@ export const DataplaneOverview = {
2930
const isCertExpired = getIsCertExpired(dataplaneInsight)
3031
const isCertExpiresSoon = getIsCertExpiresSoon(dataplaneInsight)
3132

32-
const labels = typeof item.labels !== 'undefined' ? item.labels : {}
33+
const labels = item.labels ?? {}
34+
const id = item.name
35+
const mesh = item.mesh
36+
// check for label first, fallback to tags
37+
const zone = labels['kuma.io/origin'] === 'zone' && labels['kuma.io/zone'] ? labels['kuma.io/zone'] : tags.find((tag) => tag.label === 'kuma.io/zone')?.value ?? ''
38+
const namespace = labels['k8s.kuma.io/namespace'] ?? ''
39+
const name = labels['kuma.io/display-name'] ?? item.name
40+
41+
// temporarily make a KRI until we have those from the backend
42+
const kri = Kri.toString({ shortName: 'dp', mesh, zone, namespace, name })
43+
3344

3445
// get all tags and labels with kuma.io/service
3546
// uniquify and and sort
@@ -38,20 +49,25 @@ export const DataplaneOverview = {
3849
...(labels['kuma.io/service'] ? [labels['kuma.io/service']] : []),
3950
])).sort((a, b) => a.localeCompare(b))
4051

41-
// check for label first, fallback to tags
42-
const zone = labels['kuma.io/zone'] || tags.find((tag) => tag.label === 'kuma.io/zone')?.value
4352

4453

4554
return {
4655
...item,
47-
id: item.name,
48-
name: labels['kuma.io/display-name'] || item.name,
49-
namespace: labels['k8s.kuma.io/namespace'] ?? '',
56+
kri,
57+
name,
58+
mesh,
59+
labels,
60+
creationTime: item.creationTime ?? '',
61+
modificationTime: item.modificationTime ?? '',
62+
// aliases
63+
id,
64+
namespace,
65+
zone,
66+
67+
dataplaneInsight,
5068
dataplane: {
5169
networking,
5270
},
53-
labels,
54-
dataplaneInsight,
5571
dataplaneType: (() => {
5672
switch (true) {
5773
case networking.type === 'gateway':
@@ -92,17 +108,27 @@ export const DataplaneOverview = {
92108
isCertExpired,
93109
isCertExpiresSoon,
94110
services,
95-
zone,
111+
// config should only contain non-defaulted values
112+
// because we want to show what the API responded with
113+
// we then copy over things that should be on the Entity, but
114+
// are only on the EntityOverview
96115
config: {
97116
...Dataplane.fromObject({
117+
// bare minimum props to keep TS happy
118+
// plus a splat of the original Entity
98119
type: 'Dataplane',
99120
name: item.name,
100121
mesh: item.mesh,
101122
...item.dataplane,
102123
}).config,
124+
125+
// the things we copy over
126+
// kri is always missing and we always purposefully add and generate ourselves
127+
kri,
128+
// we only copy these over if they exist
103129
...(typeof item.labels !== 'undefined' ? { labels: item.labels } : {}),
104-
creationTime: item.creationTime,
105-
modificationTime: item.modificationTime,
130+
...(typeof item.creationTime !== 'undefined' ? { creationTime: item.creationTime } : {}),
131+
...(typeof item.modificationTime !== 'undefined' ? { modificationTime: item.modificationTime } : {}),
106132
},
107133
}
108134
},

packages/kuma-gui/src/app/data-planes/data/index.spec.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -364,12 +364,13 @@ describe('DataplaneOverview', () => {
364364
})
365365
describe('dataplane.config', () => {
366366
test(
367-
'config is derived from Dataplane and based on DataplaneOverview data',
367+
'config (used for display) contains the correct fields, no more, no less',
368368
async ({ fixture }) => {
369369
const expected = {
370370
type: 'Dataplane',
371371
name: 'dp-name',
372372
mesh: 'dp-mesh',
373+
kri: 'kri_dp_dp-mesh___dp-name_',
373374
labels: {
374375
'kuma.io/display-name': 'dp-name',
375376
},
@@ -387,6 +388,7 @@ describe('DataplaneOverview', () => {
387388
const actual = await fixture.setup((item) => {
388389
item.name = expected.name
389390
item.mesh = expected.mesh
391+
// item.kri = expected.kri
390392
item.creationTime = expected.creationTime
391393
item.modificationTime = expected.modificationTime
392394
item.dataplane.networking = expected.networking

packages/kuma-gui/src/app/zone-egresses/data/index.spec.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,4 +210,41 @@ describe('ZoneEgressOverview', () => {
210210
},
211211
)
212212
})
213+
describe('zoneEgressOverview.config', () => {
214+
test('config (used for display) contains the correct fields, no more, no less', async ({ fixture }) => {
215+
216+
const expected = {
217+
type: 'ZoneEgress',
218+
name: 'zone-egress-name.zone-egress-namespace',
219+
mesh: 'mesh-0',
220+
kri: 'kri_ze_mesh-0___zone-egress-name_',
221+
labels: {
222+
'kuma.io/display-name': 'zone-egress-name',
223+
},
224+
zone: 'zone-0',
225+
creationTime: '2021-07-13T08:40:59Z',
226+
modificationTime: '2021-07-13T08:40:59Z',
227+
networking: {
228+
address: '486f:d1db:efde:c143:94a5:cb9f:271a:c1a7',
229+
port: 58936,
230+
},
231+
}
232+
const actual = await fixture.setup((item) => {
233+
item.name = expected.name
234+
item.mesh = expected.mesh
235+
// item.kri = expected.kri
236+
item.labels = expected.labels
237+
item.creationTime = expected.creationTime
238+
item.modificationTime = expected.modificationTime
239+
item.zoneEgress = {
240+
networking: expected.networking,
241+
zone: expected.zone,
242+
}
243+
244+
return item
245+
})
246+
expect(actual.config).toStrictEqual(expected)
247+
})
248+
})
249+
213250
})

packages/kuma-gui/src/app/zone-egresses/data/index.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ export const ZoneEgressOverview = {
7474
const name = labels['kuma.io/display-name'] ?? item.name
7575

7676

77+
// temporarily make a KRI until we have those from the backend
7778
const kri = Kri.toString({ shortName: 'ze', mesh, zone, namespace, name })
7879

7980
return {
@@ -91,17 +92,26 @@ export const ZoneEgressOverview = {
9192

9293
zoneEgressInsight,
9394
zoneEgress,
95+
// config should only contain non-defaulted values
96+
// because we want to show what the API responded with
97+
// we then copy over things that should be on the Entity, but
98+
// are only on the EntityOverview
9499
config: {
95100
...ZoneEgress.fromObject({
101+
// bare minimum props to keep TS happy
102+
// plus a splat of the original Entity
96103
type: 'ZoneEgress',
97104
name: item.name,
98105
mesh: item.mesh,
99-
kri,
100-
creationTime: item.creationTime,
101-
modificationTime: item.modificationTime,
102106
...item.zoneEgress,
103107
}).config,
108+
// the things we copy over
109+
// kri is always missing and we always purposefully add and generate ourselves
110+
kri,
111+
// we only copy these over if they exist
104112
...(typeof item.labels !== 'undefined' ? { labels: item.labels } : {}),
113+
...(typeof item.creationTime !== 'undefined' ? { creationTime: item.creationTime } : {}),
114+
...(typeof item.modificationTime !== 'undefined' ? { modificationTime: item.modificationTime } : {}),
105115
},
106116
// it is possible to have zoneEgresses on a 'disabled' zone but we don't
107117
// want to do anything special about that just now at least

packages/kuma-gui/src/app/zone-ingresses/data/index.spec.ts

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,4 +283,51 @@ describe('ZoneIngressOverview', () => {
283283
},
284284
)
285285
})
286+
describe('zoneIngressOverview.config', () => {
287+
test('config (used for display) contains the correct fields, no more, no less', async ({ fixture }) => {
288+
const expected = {
289+
type: 'ZoneIngress',
290+
name: 'zone-ingress-name.zone-ingress-namespace',
291+
mesh: 'mesh-0',
292+
kri: 'kri_zi_mesh-0___zone-ingress-name_',
293+
labels: {
294+
'kuma.io/display-name': 'zone-ingress-name',
295+
},
296+
zone: 'zone-0',
297+
creationTime: '2021-07-13T08:40:59Z',
298+
modificationTime: '2021-07-13T08:40:59Z',
299+
availableServices: [{
300+
instances: 50,
301+
mesh: 'mesh-0',
302+
tags: {
303+
app: 'programm-app',
304+
'kuma.io/zone': 'zone-0',
305+
'kuma.io/service': 'program-app_alarm_svc_36676',
306+
},
307+
}],
308+
networking: {
309+
address: '486f:d1db:efde:c143:94a5:cb9f:271a:c1a7',
310+
advertisedAddress: '190.26.201.59',
311+
advertisedPort: 58329,
312+
port: 58936,
313+
},
314+
}
315+
const actual = await fixture.setup((item) => {
316+
item.name = expected.name
317+
item.mesh = expected.mesh
318+
// item.kri = expected.kri
319+
item.labels = expected.labels
320+
item.creationTime = expected.creationTime
321+
item.modificationTime = expected.modificationTime
322+
item.zoneIngress = {
323+
availableServices: expected.availableServices,
324+
networking: expected.networking,
325+
zone: expected.zone,
326+
}
327+
328+
return item
329+
})
330+
expect(actual.config).toStrictEqual(expected)
331+
})
332+
})
286333
})

packages/kuma-gui/src/app/zone-ingresses/data/index.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ export const ZoneIngressOverview = {
8080
const namespace = labels['k8s.kuma.io/namespace'] ?? ''
8181
const name = labels['kuma.io/display-name'] ?? item.name
8282

83+
// temporarily make a KRI until we have those from the backend
8384
const kri = Kri.toString({ shortName: 'zi', mesh, zone, namespace, name })
8485

8586
return {
@@ -97,17 +98,28 @@ export const ZoneIngressOverview = {
9798

9899
zoneIngressInsight,
99100
zoneIngress,
101+
// config should only contain non-defaulted values
102+
// because we want to show what the API responded with
103+
// we then copy over things that should be on the Entity, but
104+
// are only on the EntityOverview
100105
config: {
101106
...ZoneIngress.fromObject({
107+
// bare minimum props to keep TS happy
108+
// plus a splat of the original Entity
102109
type: 'ZoneIngress',
103110
name: item.name,
104111
mesh: item.mesh,
105-
kri,
106112
creationTime: item.creationTime,
107113
modificationTime: item.modificationTime,
108114
...item.zoneIngress,
109115
}).config,
116+
117+
// the things we copy over
118+
// kri is always missing and we always purposefully add and generate ourselves
119+
kri,
110120
...(typeof item.labels !== 'undefined' ? { labels: item.labels } : {}),
121+
...(typeof item.creationTime !== 'undefined' ? { creationTime: item.creationTime } : {}),
122+
...(typeof item.modificationTime !== 'undefined' ? { modificationTime: item.modificationTime } : {}),
111123
},
112124
// it is possible to have zoneIngresses on a 'disabled' zone but we don't
113125
// want to do anything special about that just now at least

packages/kuma-gui/src/app/zones/data/index.ts

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { get } from '@/app/application'
2+
import { Kri } from '@/app/kuma/kri'
23
import { Resource } from '@/app/resources/data/Resource'
34
import { Subscription, SubscriptionCollection } from '@/app/subscriptions/data'
45
import type { PaginatedApiListResponse as CollectionResponse } from '@/types/api.d'
@@ -83,6 +84,15 @@ export const ZoneOverview = {
8384
},
8485

8586
fromObject: (item: PartialZoneOverview) => {
87+
88+
const labels = item.labels ?? {}
89+
const id = item.name
90+
91+
const name = labels['kuma.io/display-name'] ?? item.name
92+
93+
// temporarily make a KRI until we have those from the backend
94+
const kri = Kri.toString({ shortName: 'z', mesh: '', zone: '', namespace: '', name })
95+
8696
const insight = ZoneInsight.fromObject(item.zoneInsight)
8797
const zone = Zone.fromObject(item.zone)
8898
const state = {
@@ -92,8 +102,14 @@ export const ZoneOverview = {
92102
} as const
93103
return {
94104
...item,
95-
id: item.name,
96-
labels: item.labels ?? {},
105+
kri,
106+
name,
107+
labels,
108+
creationTime: item.creationTime ?? '',
109+
modificationTime: item.modificationTime ?? '',
110+
// aliases
111+
id,
112+
97113
zoneInsight: insight,
98114
zone,
99115
// first check see if the zone is disabled, if not look for the connectedSubscription

packages/kuma-gui/src/types/index.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -341,8 +341,8 @@ export interface LabelValue {
341341
export interface Entity {
342342
type: string
343343
name: string
344-
creationTime: string
345-
modificationTime: string
344+
creationTime?: string
345+
modificationTime?: string
346346
}
347347

348348
export interface MeshEntity extends Entity {

0 commit comments

Comments
 (0)