@skyhook-io/k8s-ui 1.13.4 → 1.14.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. package/package.json +4 -4
  2. package/src/components/gitops/GitOpsTableView.tsx +168 -11
  3. package/src/components/gitops/applicationset-row.test.ts +214 -0
  4. package/src/components/gitops/detail-helpers.test.ts +54 -0
  5. package/src/components/gitops/detail-helpers.ts +13 -3
  6. package/src/components/gitops/index.ts +1 -0
  7. package/src/components/gitops/tree/GitOpsTreeGraph.tsx +7 -0
  8. package/src/components/resources/ResourcesView.tsx +259 -80
  9. package/src/components/resources/column-header-width.test.ts +75 -0
  10. package/src/components/resources/kyverno-legacy-action.test.ts +100 -1
  11. package/src/components/resources/kyverno-modern-posture.test.ts +36 -0
  12. package/src/components/resources/renderers/CNPGBackupRenderer.test.tsx +29 -0
  13. package/src/components/resources/renderers/CNPGBackupRenderer.tsx +3 -2
  14. package/src/components/resources/renderers/CNPGClusterRenderer.test.tsx +69 -3
  15. package/src/components/resources/renderers/CNPGClusterRenderer.tsx +6 -2
  16. package/src/components/resources/renderers/KyvernoPolicyReportRenderer.tsx +12 -7
  17. package/src/components/resources/renderers/PolicyCoverageSection.test.tsx +92 -1
  18. package/src/components/resources/renderers/PolicyCoverageSection.tsx +64 -8
  19. package/src/components/resources/renderers/VeleroBSLRenderer.test.tsx +47 -0
  20. package/src/components/resources/renderers/VeleroBSLRenderer.tsx +16 -1
  21. package/src/components/resources/renderers/VeleroRestoreRenderer.test.tsx +88 -0
  22. package/src/components/resources/renderers/VeleroRestoreRenderer.tsx +44 -2
  23. package/src/components/resources/renderers/cnpg-cells.tsx +12 -1
  24. package/src/components/resources/renderers/kyverno-cells.tsx +8 -4
  25. package/src/components/resources/resource-utils-cnpg.golden.test.ts +13 -5
  26. package/src/components/resources/resource-utils-cnpg.test.ts +142 -2
  27. package/src/components/resources/resource-utils-cnpg.ts +132 -7
  28. package/src/components/resources/resource-utils-gpu-ecosystem.test.ts +14 -0
  29. package/src/components/resources/resource-utils-kueue.ts +4 -2
  30. package/src/components/resources/resource-utils-kyverno-modern.ts +3 -1
  31. package/src/components/resources/resource-utils-kyverno.ts +51 -2
  32. package/src/components/resources/resource-utils-velero.ts +32 -0
  33. package/src/components/resources/rules-column-width.test.ts +42 -0
  34. package/src/components/shared/ResourceRendererDispatch.test.tsx +75 -0
  35. package/src/components/shared/ResourceRendererDispatch.tsx +24 -6
  36. package/src/components/topology/GroupNode.tsx +6 -2
  37. package/src/components/topology/topology.css +4 -1
  38. package/src/components/ui/Collapse.tsx +9 -1
  39. package/src/components/ui/RowActionMenu.tsx +4 -0
  40. package/src/components/ui/SelectMenu.tsx +10 -1
  41. package/src/components/ui/drawer-components.tsx +4 -2
  42. package/src/components/workload/WorkloadView.tsx +9 -2
  43. package/src/types/gitops.ts +51 -0
@@ -27,6 +27,12 @@ import {
27
27
  getCNPGClusterDisplayState,
28
28
  getCNPGClusterInstances,
29
29
  getCNPGPoolerInstances,
30
+ getCNPGClusterIsReplica,
31
+ getCNPGClusterReplicaSource,
32
+ getCNPGClusterAvailability,
33
+ isCNPGClusterHibernated,
34
+ isCNPGClusterFencedAll,
35
+ CNPG_DOWN_GRACE_MS,
30
36
  } from './resource-utils-cnpg'
31
37
  import { getCellFilterValue } from './resource-utils'
32
38
 
@@ -176,8 +182,10 @@ describe('getCNPGClusterStatus', () => {
176
182
  expect(getCNPGClusterStatus(cluster({ phase: 'Failing over', readyInstances: 2 }, { instances: 3 })).level).toBe('alert')
177
183
  })
178
184
 
179
- it('treats zero ready instances as down regardless of phase', () => {
180
- const s = getCNPGClusterStatus(cluster({ phase: 'Cluster in healthy state', readyInstances: 0 }, { instances: 3 }))
185
+ it('treats a was-up cluster with zero ready instances as down regardless of phase', () => {
186
+ // currentPrimary proves it was serving; the omitted-then-zero count is a
187
+ // regression, not a first bootstrap. Even a "healthy" phase does not rescue it.
188
+ const s = getCNPGClusterStatus(cluster({ phase: 'Cluster in healthy state', currentPrimary: 'pg-1', readyInstances: 0 }, { instances: 3 }))
181
189
  expect(s.level).toBe('unhealthy')
182
190
  expect(s.text).toBe('Not Ready')
183
191
  })
@@ -193,6 +201,68 @@ describe('getCNPGClusterStatus', () => {
193
201
  })
194
202
  })
195
203
 
204
+ describe('getCNPGClusterAvailability — three states a bare zero-ready count collapses', () => {
205
+ // CNPG omits readyInstances when it is 0, so these fixtures OMIT it — the shape
206
+ // the operator actually emits for a down cluster.
207
+ const withPrimary = (extra: any = {}, meta: any = {}) => ({
208
+ metadata: meta,
209
+ spec: { instances: 3 },
210
+ status: { currentPrimary: 'pg-1', ...extra },
211
+ })
212
+
213
+ it('is null while still bootstrapping — reported, but no primary ever elected', () => {
214
+ // The truly-statusless case AND the reported-but-no-primary case both stay
215
+ // null: nothing was serving to lose.
216
+ expect(getCNPGClusterAvailability({ spec: { instances: 3 }, status: {} })).toBeNull()
217
+ expect(getCNPGClusterAvailability({ spec: { instances: 3 }, status: { phase: 'Setting up primary' } })).toBeNull()
218
+ })
219
+
220
+ it('is null when a real ready count exists', () => {
221
+ expect(getCNPGClusterAvailability({ spec: { instances: 3 }, status: { currentPrimary: 'pg-1', readyInstances: 2 } })).toBeNull()
222
+ })
223
+
224
+ it('is down for a was-up cluster with no Ready condition — escalates immediately', () => {
225
+ expect(getCNPGClusterAvailability(withPrimary({ phase: 'Waiting for the instances to become active' }))).toBe('down')
226
+ })
227
+
228
+ it('debounces a fresh Ready=False, then escalates once it ages past the grace', () => {
229
+ const recent = new Date(Date.now() - 60 * 1000).toISOString()
230
+ const old = new Date(Date.now() - CNPG_DOWN_GRACE_MS - 60 * 1000).toISOString()
231
+ const cond = (ltt: string) => withPrimary({
232
+ conditions: [{ type: 'Ready', status: 'False', reason: 'ClusterIsNotReady', lastTransitionTime: ltt }],
233
+ })
234
+ expect(getCNPGClusterAvailability(cond(recent))).toBeNull()
235
+ expect(getCNPGClusterAvailability(cond(old))).toBe('down')
236
+ })
237
+
238
+ it('reads hibernation and all-fencing as neutral, ahead of the down verdict', () => {
239
+ expect(getCNPGClusterAvailability(withPrimary({}, { annotations: { 'cnpg.io/hibernation': 'on' } }))).toBe('hibernated')
240
+ expect(getCNPGClusterAvailability(withPrimary({}, { annotations: { 'cnpg.io/fencedInstances': '["*"]' } }))).toBe('fenced')
241
+ })
242
+
243
+ it('a partial fence is not all-fenced — "*" is the only all-down token', () => {
244
+ expect(isCNPGClusterFencedAll({ metadata: { annotations: { 'cnpg.io/fencedInstances': '["pg-1-2"]' } } })).toBe(false)
245
+ expect(isCNPGClusterFencedAll({ metadata: { annotations: { 'cnpg.io/fencedInstances': '["*"]' } } })).toBe(true)
246
+ // A malformed annotation is treated as not-fenced rather than throwing.
247
+ expect(isCNPGClusterFencedAll({ metadata: { annotations: { 'cnpg.io/fencedInstances': 'not-json' } } })).toBe(false)
248
+ })
249
+
250
+ it('hibernation is an explicit "on", nothing else', () => {
251
+ expect(isCNPGClusterHibernated({ metadata: { annotations: { 'cnpg.io/hibernation': 'on' } } })).toBe(true)
252
+ expect(isCNPGClusterHibernated({ metadata: { annotations: { 'cnpg.io/hibernation': 'off' } } })).toBe(false)
253
+ expect(isCNPGClusterHibernated({ metadata: {} })).toBe(false)
254
+ })
255
+
256
+ it('renders the badge neutral for hibernation and fencing, red only for a real outage', () => {
257
+ expect(getCNPGClusterStatus(withPrimary({}, { annotations: { 'cnpg.io/hibernation': 'on' } })))
258
+ .toMatchObject({ text: 'Hibernated', level: 'neutral' })
259
+ expect(getCNPGClusterStatus(withPrimary({}, { annotations: { 'cnpg.io/fencedInstances': '["*"]' } })))
260
+ .toMatchObject({ text: 'Fenced', level: 'neutral' })
261
+ expect(getCNPGClusterStatus(withPrimary({ phase: 'Switchover in progress' })))
262
+ .toMatchObject({ text: 'Not Ready', level: 'unhealthy' })
263
+ })
264
+ })
265
+
196
266
  describe('getCNPGBackupStatus', () => {
197
267
  it('escalates walArchivingFailing instead of rendering it neutral', () => {
198
268
  // The shipped bug: this phase hit the default branch and rendered grey,
@@ -716,3 +786,73 @@ describe('CNPG scheduled backup lateness', () => {
716
786
  expect(getCNPGScheduledBackupStatus(sb(false, undefined, at(-24 * 60 * MIN))).level).toBe('healthy')
717
787
  })
718
788
  })
789
+
790
+ describe('getCNPGClusterIsReplica — the live replica-cluster role, per CNPG semantics', () => {
791
+ // CNPG carries replica-cluster state in `spec.replica` (enabled/primary/self/source),
792
+ // and its own Cluster.IsReplica() reads: enabled wins when set; otherwise the
793
+ // cluster is a replica only while (self || name) != primary. Promotion mutates
794
+ // those fields but leaves the stanza in place, so presence alone cannot be the
795
+ // signal.
796
+
797
+ it('standalone replica cluster (replica mode enabled) reads as a replica', () => {
798
+ const resource = {
799
+ metadata: { name: 'pg-eu' },
800
+ spec: { replica: { source: 'pg-us', enabled: true } },
801
+ }
802
+ expect(getCNPGClusterIsReplica(resource)).toBe(true)
803
+ })
804
+
805
+ it('a promoted standalone cluster (replica.enabled turned off) is no longer a replica', () => {
806
+ const resource = {
807
+ metadata: { name: 'pg-eu' },
808
+ spec: { replica: { source: 'pg-us', enabled: false } },
809
+ }
810
+ expect(getCNPGClusterIsReplica(resource)).toBe(false)
811
+ })
812
+
813
+ it('distributed topology: a designated replica (primary names another cluster) reads as a replica', () => {
814
+ const resource = {
815
+ metadata: { name: 'pg-eu' },
816
+ spec: { replica: { source: 'pg-us', primary: 'pg-us', self: 'pg-eu' } },
817
+ }
818
+ expect(getCNPGClusterIsReplica(resource)).toBe(true)
819
+ })
820
+
821
+ it('distributed topology: after promotion (primary now names this cluster) it is the primary, stanza still present', () => {
822
+ const resource = {
823
+ metadata: { name: 'pg-eu' },
824
+ spec: { replica: { source: 'pg-us', primary: 'pg-eu', self: 'pg-eu' } },
825
+ }
826
+ expect(getCNPGClusterIsReplica(resource)).toBe(false)
827
+ })
828
+
829
+ it('distributed topology without self falls back to the resource name', () => {
830
+ const promoted = {
831
+ metadata: { name: 'pg-eu' },
832
+ spec: { replica: { source: 'pg-us', primary: 'pg-eu' } },
833
+ }
834
+ expect(getCNPGClusterIsReplica(promoted)).toBe(false)
835
+
836
+ const stillReplica = {
837
+ metadata: { name: 'pg-eu' },
838
+ spec: { replica: { source: 'pg-us', primary: 'pg-us' } },
839
+ }
840
+ expect(getCNPGClusterIsReplica(stillReplica)).toBe(true)
841
+ })
842
+
843
+ it('a bootstrapping standalone replica with only a source (no enabled, no primary) is a replica', () => {
844
+ // The stanza's source is required; before the operator writes enabled, the
845
+ // cluster is still a replica — (self || name) never equals an unset primary.
846
+ const resource = { metadata: { name: 'pg-eu' }, spec: { replica: { source: 'pg-us' } } }
847
+ expect(getCNPGClusterIsReplica(resource)).toBe(true)
848
+ })
849
+
850
+ it('an ordinary standalone cluster with no replica stanza is not a replica', () => {
851
+ expect(getCNPGClusterIsReplica({ metadata: { name: 'pg' }, spec: { instances: 3 } })).toBe(false)
852
+ })
853
+
854
+ it('getCNPGClusterReplicaSource reads the source from the replica stanza', () => {
855
+ const resource = { metadata: { name: 'pg-eu' }, spec: { replica: { source: 'pg-us', enabled: true } } }
856
+ expect(getCNPGClusterReplicaSource(resource)).toBe('pg-us')
857
+ })
858
+ })
@@ -145,6 +145,100 @@ export function classifyCNPGClusterPhase(phase: string): CNPGPhaseBucket {
145
145
  return 'unknown'
146
146
  }
147
147
 
148
+ // Debounce window for calling a was-up cluster "down". A single instance
149
+ // restarting flips Ready=False for a minute or two while the pod comes back;
150
+ // escalating instantly would fire on routine rollouts. Kept in step with
151
+ // cnpgDownGrace in internal/issues/source_cnpg.go — the two must not drift.
152
+ export const CNPG_DOWN_GRACE_MS = 5 * 60 * 1000
153
+
154
+ /**
155
+ * Hibernation is a deliberate scale-to-zero: the operator removes the pods and
156
+ * the cluster reports nothing ready by design. Signalled by an annotation, not
157
+ * by any status field, so it has to be read before a zero-ready count is called
158
+ * an outage.
159
+ */
160
+ export function isCNPGClusterHibernated(resource: any): boolean {
161
+ return resource?.metadata?.annotations?.['cnpg.io/hibernation'] === 'on'
162
+ }
163
+
164
+ /**
165
+ * Fencing stops PostgreSQL on the named instances while leaving the pods up. The
166
+ * annotation is a JSON array of instance names; `"*"` means every instance is
167
+ * fenced, so nothing serves — intentionally, not as a fault. A malformed value
168
+ * is treated as "not fenced" rather than throwing.
169
+ */
170
+ export function isCNPGClusterFencedAll(resource: any): boolean {
171
+ const raw = resource?.metadata?.annotations?.['cnpg.io/fencedInstances']
172
+ if (typeof raw !== 'string' || raw === '') return false
173
+ try {
174
+ const parsed = JSON.parse(raw)
175
+ return Array.isArray(parsed) && parsed.includes('*')
176
+ } catch {
177
+ return false
178
+ }
179
+ }
180
+
181
+ /**
182
+ * Whether a zero-ready cluster is actually unavailable, and why.
183
+ *
184
+ * The load-bearing distinction the badge and the Go detector both turn on:
185
+ * CNPG omits `status.readyInstances` when it is 0 (omitempty int), so "no
186
+ * status yet" and "0 ready" are byte-identical on the wire. The field's
187
+ * presence therefore cannot distinguish an outage from an unreported cluster;
188
+ * any other status the operator has written (phase, primary, a condition) is
189
+ * what marks the count as a real 0 rather than "not reported".
190
+ *
191
+ * `status.currentPrimary` is the version-robust "was up" signal: CNPG sets it
192
+ * the first time a primary is elected and never clears it (present on 1.27 and
193
+ * 1.28). So a zero-ready cluster that HAS a currentPrimary was serving before —
194
+ * a regression — while one that never had a primary is still bootstrapping.
195
+ *
196
+ * - null — not down: still bootstrapping, or a real ready count exists
197
+ * - 'hibernated' / 'fenced' — deliberately not serving, no alarm
198
+ * - 'down' — was up, now zero ready past the grace window
199
+ *
200
+ * Mirrored by getCNPGClusterAvailability's Go counterpart in
201
+ * internal/issues/source_cnpg.go (the allDown verdict) — same signals, same
202
+ * grace, or a badge and its issue disagree.
203
+ */
204
+ export function getCNPGClusterAvailability(
205
+ resource: any,
206
+ ): 'hibernated' | 'fenced' | 'down' | null {
207
+ const status = resource.status || {}
208
+ const desired = resource.spec?.instances ?? 0
209
+ const ready = typeof status.readyInstances === 'number' ? status.readyInstances : 0
210
+ // Any status the operator has written proves it has reconciled at least once,
211
+ // which is what lets an absent readyInstances be read as a real 0 rather than
212
+ // "not reported". Absent EVERYTHING is the truly-statusless case, still unknown.
213
+ const reported = !!(status.phase || status.currentPrimary || status.conditions?.length)
214
+ if (desired <= 0 || ready > 0 || !reported) return null
215
+ // Deliberate not-serving states outrank the down verdict — checked before the
216
+ // was-up gate so a hibernated cluster reads neutral even if it kept a primary.
217
+ if (isCNPGClusterHibernated(resource)) return 'hibernated'
218
+ if (isCNPGClusterFencedAll(resource)) return 'fenced'
219
+ // Never elected a primary → first bootstrap, not a regression.
220
+ if (!status.currentPrimary) return null
221
+ const conditions = status.conditions || []
222
+ const readyCond = conditions.find((c: any) => c.type === 'Ready')
223
+ // A was-up cluster whose Ready only just went False is likely a single
224
+ // instance bouncing; wait out the grace. No Ready=False at all (or no
225
+ // timestamp) means nothing is debouncing, so escalate immediately rather than
226
+ // inventing a start time.
227
+ if (
228
+ readyCond?.status === 'False' &&
229
+ readyCond.lastTransitionTime &&
230
+ Date.now() - Date.parse(readyCond.lastTransitionTime) < CNPG_DOWN_GRACE_MS
231
+ ) {
232
+ return null
233
+ }
234
+ // A cluster woken from hibernation or lifted from a full fence transiently
235
+ // shows this same shape — was-up, zero ready, Ready=False from long before —
236
+ // until its first instance is Ready. CNPG drops the hibernation marker at that
237
+ // point, so from the Cluster status alone this is indistinguishable from a real
238
+ // outage, and it reads down for that short window.
239
+ return 'down'
240
+ }
241
+
148
242
  export function getCNPGClusterStatus(resource: any): StatusBadge {
149
243
  const status = resource.status || {}
150
244
  const phase = status.phase || ''
@@ -165,10 +259,19 @@ export function getCNPGClusterStatus(resource: any): StatusBadge {
165
259
  if (bucket === 'terminal') {
166
260
  return { text: getCNPGClusterDisplayState(phase), color: healthColors.unhealthy, level: 'unhealthy' }
167
261
  }
168
- // Zero ready instances is a hard down that no phase excuses — including a
169
- // failover, where the phase alone would otherwise downgrade a total outage to
170
- // orange.
171
- if (countsKnown && readyInstances === 0) {
262
+ // Availability outranks every phase branch except terminal. A zero-ready
263
+ // cluster CNPG reports by omitting readyInstances would otherwise be invisible
264
+ // here (countsKnown is false without the field) and fall through to the
265
+ // transient phase, painting amber on a total outage. Hibernation and all-fenced
266
+ // are deliberate not-serving states, so they read neutral rather than red.
267
+ const avail = getCNPGClusterAvailability(resource)
268
+ if (avail === 'hibernated') {
269
+ return { text: 'Hibernated', color: healthColors.neutral, level: 'neutral' }
270
+ }
271
+ if (avail === 'fenced') {
272
+ return { text: 'Fenced', color: healthColors.neutral, level: 'neutral' }
273
+ }
274
+ if (avail === 'down') {
172
275
  return { text: 'Not Ready', color: healthColors.unhealthy, level: 'unhealthy' }
173
276
  }
174
277
  if (bucket === 'failing') {
@@ -241,7 +344,20 @@ export function getCNPGClusterStatus(resource: any): StatusBadge {
241
344
  const countOrDash = (n: unknown): string => (typeof n === 'number' ? String(n) : '-')
242
345
 
243
346
  export function getCNPGClusterInstances(resource: any): string {
244
- return `${countOrDash(resource.status?.readyInstances)}/${countOrDash(resource.spec?.instances)}`
347
+ const status = resource.status || {}
348
+ // Absent readyInstances resolves to 0 only for a was-up cluster (one that
349
+ // elected a primary): there the omitted field genuinely means zero ready, and
350
+ // "0/3" agrees with the "Not Ready" badge. Before a primary exists the count
351
+ // is truly unknown, so it stays a dash — the guard against fabricating an
352
+ // outage the badge denies. currentPrimary is the same was-up signal the badge
353
+ // gates its down verdict on, so the cell can never read 0 beside a green badge.
354
+ const ready =
355
+ typeof status.readyInstances === 'number'
356
+ ? status.readyInstances
357
+ : status.currentPrimary
358
+ ? 0
359
+ : undefined
360
+ return `${countOrDash(ready)}/${countOrDash(resource.spec?.instances)}`
245
361
  }
246
362
 
247
363
  export function getCNPGClusterPrimary(resource: any): string {
@@ -554,12 +670,21 @@ export function getCNPGClusterMonitoring(resource: any): {
554
670
  }
555
671
  }
556
672
 
673
+ // CNPG carries replica-cluster state in `spec.replica`. Presence is not the
674
+ // signal: promoting a replica to primary mutates the stanza's fields but leaves
675
+ // it in place. This mirrors the operator's own Cluster.IsReplica() — `enabled`
676
+ // decides when set; otherwise the cluster is a replica only while it is not the
677
+ // designated primary of the distributed topology ((self || name) != primary).
557
678
  export function getCNPGClusterIsReplica(resource: any): boolean {
558
- return !!resource.spec?.replicaCluster
679
+ const replica = resource.spec?.replica
680
+ if (!replica) return false
681
+ if (replica.enabled != null) return replica.enabled === true
682
+ const self = replica.self || resource.metadata?.name
683
+ return self !== replica.primary
559
684
  }
560
685
 
561
686
  export function getCNPGClusterReplicaSource(resource: any): string {
562
- const replica = resource.spec?.replicaCluster
687
+ const replica = resource.spec?.replica
563
688
  if (!replica) return '-'
564
689
  return replica.source || replica.primary || '-'
565
690
  }
@@ -37,6 +37,20 @@ describe('GPU ecosystem API contracts', () => {
37
37
  expect(getKueueWorkloadStatus(workload).text).toBe('Evicted')
38
38
  })
39
39
 
40
+ it('distinguishes Kueue terminal failures from successful workloads', () => {
41
+ for (const reason of ['Failed', 'FailedToStart', 'OutOfSync', 'OwnerNotFound']) {
42
+ expect(getKueueWorkloadStatus({
43
+ status: { conditions: [{ type: 'Finished', status: 'True', reason }] },
44
+ })).toMatchObject({ text: reason, level: 'unhealthy' })
45
+ }
46
+
47
+ for (const reason of ['Succeeded', 'WorkloadSliceReplaced']) {
48
+ expect(getKueueWorkloadStatus({
49
+ status: { conditions: [{ type: 'Finished', status: 'True', reason }] },
50
+ })).toMatchObject({ text: 'Finished', level: 'neutral' })
51
+ }
52
+ })
53
+
40
54
  it('lets KubeRay conditions outrank deprecated state fields', () => {
41
55
  expect(getRayClusterStatus({
42
56
  status: {
@@ -3,6 +3,8 @@
3
3
  import type { StatusBadge } from './resource-utils'
4
4
  import { healthColors } from './resource-utils'
5
5
 
6
+ const failedFinishedReasons = new Set(['Failed', 'FailedToStart', 'OutOfSync', 'OwnerNotFound'])
7
+
6
8
  // ============================================================================
7
9
  // SHARED HELPERS
8
10
  // ============================================================================
@@ -84,8 +86,8 @@ export function getLocalQueueAdmittedWorkloads(resource: any): string {
84
86
  export function getKueueWorkloadStatus(resource: any): StatusBadge {
85
87
  const finished = findCondition(resource, 'Finished')
86
88
  if (finished?.status === 'True') {
87
- if (finished.reason === 'Failed') {
88
- return { text: 'Failed', color: healthColors.unhealthy, level: 'unhealthy' }
89
+ if (failedFinishedReasons.has(finished.reason)) {
90
+ return { text: finished.reason, color: healthColors.unhealthy, level: 'unhealthy' }
89
91
  }
90
92
  return { text: 'Finished', color: healthColors.neutral, level: 'neutral' }
91
93
  }
@@ -472,7 +472,9 @@ export function getKyvernoMutations(resource: any): KyvernoMutation[] {
472
472
  export function getKyvernoGenerations(resource: any): string[] {
473
473
  const generate = resource?.spec?.generate
474
474
  if (!Array.isArray(generate)) return []
475
- return generate.map((g: any) => g?.expression || '').filter(Boolean)
475
+ // Each entry declares its target as exactly one of a CEL `expression` or a
476
+ // YAML `template.value`; both are first-class ways to say what gets generated.
477
+ return generate.map((g: any) => g?.expression || g?.template?.value || '').filter(Boolean)
476
478
  }
477
479
 
478
480
  /**
@@ -115,6 +115,16 @@ export function getKyvernoPolicyStatus(resource: any): StatusBadge {
115
115
  return { text: 'Unknown', color: healthColors.unknown, level: 'unknown' }
116
116
  }
117
117
 
118
+ /**
119
+ * Kyverno's ValidationFailureAction enum accepts the deprecated lowercase
120
+ * `enforce` alongside `Enforce`, and the admission controller blocks on the
121
+ * lowercase spelling exactly as on the capitalized one. Match case-insensitively
122
+ * so a legacy policy carrying the lowercase value is not read as non-blocking.
123
+ */
124
+ export function isKyvernoEnforceAction(action: unknown): boolean {
125
+ return String(action ?? '').toLowerCase() === 'enforce'
126
+ }
127
+
118
128
  /** The rule blocks whose failure an admission request can be rejected for. */
119
129
  function rejectingActions(rule: any): string[] {
120
130
  if (!rule) return []
@@ -148,14 +158,14 @@ function rejectingActions(rule: any): string[] {
148
158
  export function getKyvernoPolicyAction(resource: any): string {
149
159
  const specAction = resource.spec?.validationFailureAction
150
160
  const rules = resource.spec?.rules || []
151
- if (rules.length === 0) return specAction || 'Audit'
161
+ if (rules.length === 0) return isKyvernoEnforceAction(specAction) ? 'Enforce' : 'Audit'
152
162
  const rejecting = rules.filter((rule: any) => rule?.validate || rule?.verifyImages)
153
163
  // Rules, but none that can reject: the spec-level action governs nothing here.
154
164
  if (rejecting.length === 0) return 'Audit'
155
165
  for (const rule of rejecting) {
156
166
  const overrides = rejectingActions(rule)
157
167
  const effective = overrides.length > 0 ? overrides : [specAction]
158
- if (effective.includes('Enforce')) return 'Enforce'
168
+ if (effective.some(isKyvernoEnforceAction)) return 'Enforce'
159
169
  }
160
170
  return 'Audit'
161
171
  }
@@ -204,6 +214,45 @@ export function getKyvernoPolicyBackground(resource: any): boolean {
204
214
  return resource.spec?.background !== false
205
215
  }
206
216
 
217
+ /**
218
+ * `spec.admission`, defaulting to true — the same reading as Kyverno's own
219
+ * AdmissionProcessingEnabled(). When false the policy is never registered with
220
+ * the admission webhook, so it rejects nothing at admission whatever its
221
+ * failureAction says; it can only be seen by background scans.
222
+ */
223
+ export function getKyvernoPolicyAdmission(resource: any): boolean {
224
+ return resource.spec?.admission !== false
225
+ }
226
+
227
+ export interface KyvernoEnforcement {
228
+ /** Badge label. */
229
+ label: string
230
+ /** True only when a violating request is actually rejected at admission. */
231
+ blocks: boolean
232
+ /** Declared to reject, but admission is off — it enforces nothing at admission. */
233
+ discrepancy: boolean
234
+ }
235
+
236
+ /**
237
+ * What a legacy policy does at admission, not just what its failureAction field
238
+ * reads. An Enforce policy with admission disabled blocks nothing — presenting
239
+ * it as a blocking "Enforce" would tell an operator the cluster is guarded when
240
+ * it is not. Labels match the modern CEL family's vocabulary for the same
241
+ * posture: "Background only" when background scans still report violations,
242
+ * "Inactive" when background is disabled too and the policy does nothing.
243
+ */
244
+ export function getKyvernoEnforcement(resource: any): KyvernoEnforcement {
245
+ const action = getKyvernoPolicyAction(resource)
246
+ if (action !== 'Enforce' || getKyvernoPolicyAdmission(resource)) {
247
+ return { label: action, blocks: action === 'Enforce', discrepancy: false }
248
+ }
249
+ return {
250
+ label: getKyvernoPolicyBackground(resource) ? 'Background only' : 'Inactive',
251
+ blocks: false,
252
+ discrepancy: true,
253
+ }
254
+ }
255
+
207
256
  export function getKyvernoPolicyRuleCountByType(resource: any): {
208
257
  validate: number
209
258
  mutate: number
@@ -306,6 +306,30 @@ export function getRestoreExcludedResources(resource: any): string[] {
306
306
  return resource.spec?.excludedResources || []
307
307
  }
308
308
 
309
+ export function getRestoreNamespaceMapping(resource: any): Record<string, string> {
310
+ return resource.spec?.namespaceMapping || {}
311
+ }
312
+
313
+ export function getRestoreLabelSelector(resource: any): any {
314
+ return resource.spec?.labelSelector
315
+ }
316
+
317
+ export function getRestoreOrLabelSelectors(resource: any): any[] {
318
+ return resource.spec?.orLabelSelectors || []
319
+ }
320
+
321
+ /**
322
+ * A label selector only narrows a restore when it carries at least one term. An
323
+ * empty selector matches everything, so it must not be presented as scope: doing
324
+ * so would tell an operator a restore is filtered when it is not.
325
+ */
326
+ export function hasLabelSelectorTerms(selector: any): boolean {
327
+ if (!selector || typeof selector !== 'object') return false
328
+ const hasLabels = selector.matchLabels && Object.keys(selector.matchLabels).length > 0
329
+ const hasExpressions = Array.isArray(selector.matchExpressions) && selector.matchExpressions.length > 0
330
+ return Boolean(hasLabels || hasExpressions)
331
+ }
332
+
309
333
  export function getRestoreDuration(resource: any): string {
310
334
  const start = resource.status?.startTimestamp
311
335
  const end = resource.status?.completionTimestamp
@@ -486,6 +510,14 @@ export function getBSLLastSynced(resource: any): string {
486
510
  return formatAge(lastSynced)
487
511
  }
488
512
 
513
+ // Why the location is unavailable, in the validation controller's own words.
514
+ // A BackupStorageLocation carries no conditions, so status.message is the only
515
+ // place the reason exists — without it the phase is the whole story a reader
516
+ // gets.
517
+ export function getBSLMessage(resource: any): string {
518
+ return resource.status?.message || ''
519
+ }
520
+
489
521
  // ============================================================================
490
522
  // VOLUME SNAPSHOT LOCATION UTILITIES
491
523
  // ============================================================================
@@ -0,0 +1,42 @@
1
+ import { describe, expect, it } from 'vitest'
2
+ import { readFileSync } from 'fs'
3
+ import { join } from 'path'
4
+
5
+ // Parsed from the source rather than exported, matching
6
+ // curated-column-ownership.test.ts: this asserts a property of the data as it
7
+ // is written, and an export would let the two drift.
8
+ const SRC = readFileSync(join(__dirname, 'ResourcesView.tsx'), 'utf8')
9
+
10
+ function columnSetBody(key: string): string {
11
+ const start = SRC.match(new RegExp(`^ ${key}: \\[`, 'm'))
12
+ if (!start || start.index === undefined) throw new Error(`${key} not found in KNOWN_COLUMNS`)
13
+ const open = SRC.indexOf('[', start.index)
14
+ let depth = 1
15
+ let i = open + 1
16
+ while (depth > 0) {
17
+ if (SRC[i] === '[') depth++
18
+ else if (SRC[i] === ']') depth--
19
+ i++
20
+ }
21
+ return SRC.slice(open + 1, i)
22
+ }
23
+
24
+ // The header cell is px-4, so w-16 (64px) leaves 31px for the label while
25
+ // uppercase "RULES" needs ~37px — it clips to "RUL…" unconditionally, with no
26
+ // sort or filter button involved: 'rules' is in SKIP_FILTER_COLUMNS and is not
27
+ // in the sortable-key list, so neither affordance ever renders on it. w-20
28
+ // (80px) leaves 47px.
29
+ describe('Rules column width', () => {
30
+ const kinds = ['kyvernopolicies', 'clusterpolicies', 'httproutes', 'grpcroutes', 'tcproutes', 'tlsroutes']
31
+
32
+ it.each(kinds)('%s Rules column is at least w-20', (kind) => {
33
+ const rules = columnSetBody(kind).match(/\{ key: 'rules'.*\}/)
34
+ expect(rules, `${kind} has no rules column`).not.toBeNull()
35
+ const width = rules![0].match(/width: 'w-(\d+)'/)
36
+ expect(width, `${kind} rules column has no fixed w-* width`).not.toBeNull()
37
+ // Compared numerically, not pinned to w-20, so the wider table-width pass
38
+ // tracked in #1583 can widen these without tripping a test that only
39
+ // claims a floor.
40
+ expect(Number(width![1])).toBeGreaterThanOrEqual(20)
41
+ })
42
+ })
@@ -651,6 +651,81 @@ describe('colliding plurals — near-match API groups', () => {
651
651
  })
652
652
  })
653
653
 
654
+ describe('CAPI Machine kind collisions', () => {
655
+ const foreignApiVersion = 'extension.cluster.x-k8s.io/v1'
656
+
657
+ it.each([
658
+ ['machines', 'Machine', 'Role'],
659
+ ['machinesets', 'MachineSet', 'Delete Policy'],
660
+ ])('routes a foreign %s CRD through the generic renderer only', (plural, kind, capiMarker) => {
661
+ const html = renderKind(plural, {
662
+ apiVersion: foreignApiVersion,
663
+ kind,
664
+ metadata: {
665
+ name: 'foreign',
666
+ namespace: 'default',
667
+ labels: { 'topology.cluster.x-k8s.io/owned': '' },
668
+ },
669
+ spec: { collisionProbe: COLLISION_PROBE },
670
+ status: { phase: 'provisioned' },
671
+ }, 'default')
672
+
673
+ expect(html).toContain(COLLISION_PROBE)
674
+ expect(html).not.toContain(capiMarker)
675
+ expect(html).not.toContain('Topology-controlled')
676
+ expect(getResourceStatus(plural, {
677
+ apiVersion: foreignApiVersion,
678
+ status: { phase: 'provisioned' },
679
+ })?.text).toBe('provisioned')
680
+ })
681
+
682
+ it.each([
683
+ ['machines', 'Machine', 'Role'],
684
+ ['machinesets', 'MachineSet', 'Delete Policy'],
685
+ ])('keeps exact-group CAPI %s resources on the dedicated path', (plural, kind, capiMarker) => {
686
+ const html = renderKind(plural, {
687
+ apiVersion: 'cluster.x-k8s.io/v1beta1',
688
+ kind,
689
+ metadata: {
690
+ name: 'capi',
691
+ namespace: 'default',
692
+ labels: { 'topology.cluster.x-k8s.io/owned': '' },
693
+ },
694
+ spec: { collisionProbe: COLLISION_PROBE },
695
+ status: { phase: 'provisioned' },
696
+ }, 'default')
697
+
698
+ expect(html).toContain(capiMarker)
699
+ expect(html).toContain('Topology-controlled')
700
+ expect(html).not.toContain(COLLISION_PROBE)
701
+ expect(getResourceStatus(plural, {
702
+ apiVersion: 'cluster.x-k8s.io/v1beta1',
703
+ status: { phase: 'provisioned' },
704
+ })?.text).toBe('Provisioned')
705
+ })
706
+
707
+ it.each([
708
+ ['kubeadmcontrolplanes', 'KubeadmControlPlane', 'controlplane.cluster.x-k8s.io/v1beta1'],
709
+ ['awsmanagedcontrolplanes', 'AWSManagedControlPlane', 'controlplane.cluster.x-k8s.io/v1beta2'],
710
+ ['awsmanagedmachinepools', 'AWSManagedMachinePool', 'infrastructure.cluster.x-k8s.io/v1beta2'],
711
+ ['awsmachines', 'AWSMachine', 'infrastructure.cluster.x-k8s.io/v1beta2'],
712
+ ])('keeps the topology-owned warning for %s', (plural, kind, apiVersion) => {
713
+ const html = renderKind(plural, {
714
+ apiVersion,
715
+ kind,
716
+ metadata: {
717
+ name: 'topology-owned',
718
+ namespace: 'default',
719
+ labels: { 'topology.cluster.x-k8s.io/owned': '' },
720
+ },
721
+ spec: {},
722
+ status: {},
723
+ }, 'default')
724
+
725
+ expect(html).toContain('Topology-controlled')
726
+ })
727
+ })
728
+
654
729
  describe('shared plurals — the status path collides too', () => {
655
730
  // The renderer and the status badge are two separate switches over the same
656
731
  // plural, and fixing one leaves the other reading a foreign CRD's conditions