From fa7267f00bd07346fa3be57d1ed5429ec3268262 Mon Sep 17 00:00:00 2001 From: mahesh-09-12 Date: Sun, 21 Jun 2026 15:03:35 +0530 Subject: [PATCH] frontend: storybook: Fix startup failure caused by node story helpers Storybook startup failed with "Cannot access 'KubeObject' before initialization" because baseMocks imported node/storyHelper, which loaded node.ts at runtime only to access NODE_POOL_LABEL_KEYS and type definitions. Extract NODE_POOL_LABEL_KEYS into a dedicated nodeConstants module and update storyHelper to use type-only imports, avoiding an unnecessary runtime dependency on the Node implementation. Re-export NODE_POOL_LABEL_KEYS from node.ts to preserve plugin and consumer compatibility. Signed-off-by: mahesh-09-12 --- frontend/src/components/node/storyHelper.ts | 5 ++-- frontend/src/lib/k8s/node.ts | 17 ++++-------- frontend/src/lib/k8s/nodeConstants.ts | 29 +++++++++++++++++++++ 3 files changed, 37 insertions(+), 14 deletions(-) create mode 100644 frontend/src/lib/k8s/nodeConstants.ts diff --git a/frontend/src/components/node/storyHelper.ts b/frontend/src/components/node/storyHelper.ts index ad8133d80cb..1751767b488 100644 --- a/frontend/src/components/node/storyHelper.ts +++ b/frontend/src/components/node/storyHelper.ts @@ -14,8 +14,9 @@ * limitations under the License. */ -import { KubeMetrics } from '../../lib/k8s/cluster'; -import { KubeNode, NODE_POOL_LABEL_KEYS } from '../../lib/k8s/node'; +import type { KubeMetrics } from '../../lib/k8s/cluster'; +import type { KubeNode } from '../../lib/k8s/node'; +import { NODE_POOL_LABEL_KEYS } from '../../lib/k8s/nodeConstants'; const creationTimestamp = new Date('2022-01-01').toISOString(); diff --git a/frontend/src/lib/k8s/node.ts b/frontend/src/lib/k8s/node.ts index 1b4923a78c1..a2dff75cdde 100644 --- a/frontend/src/lib/k8s/node.ts +++ b/frontend/src/lib/k8s/node.ts @@ -23,6 +23,7 @@ import { KubeNodeSummaryStats, nodeSummaryStats } from './api/v2/nodeSummaryApi' import type { KubeCondition, KubeMetrics } from './cluster'; import type { KubeObjectInterface } from './KubeObject'; import { KubeObject } from './KubeObject'; +import { NODE_POOL_LABEL_KEYS } from './nodeConstants'; export interface KubeNode extends KubeObjectInterface { status: { @@ -63,18 +64,6 @@ export interface KubeNode extends KubeObjectInterface { }; } -/** - * The exact label keys checked by {@link Node.getNodePool}. - * Export this so test helpers and stories can strip them without drifting. - */ -export const NODE_POOL_LABEL_KEYS = [ - 'cloud.google.com/gke-nodepool', - 'kubernetes.azure.com/agentpool', - 'eks.amazonaws.com/nodegroup', - 'kops.k8s.io/instancegroup', - 'cluster.x-k8s.io/deployment-name', -] as const; - class Node extends KubeObject { static kind = 'Node'; static apiName = 'nodes'; @@ -170,4 +159,8 @@ class Node extends KubeObject { } } +// Re-export for plugin compatibility. Import directly from nodeConstants.ts +// when only the label keys are needed to avoid loading the Node implementation. +export { NODE_POOL_LABEL_KEYS }; + export default Node; diff --git a/frontend/src/lib/k8s/nodeConstants.ts b/frontend/src/lib/k8s/nodeConstants.ts new file mode 100644 index 00000000000..c01a53a776a --- /dev/null +++ b/frontend/src/lib/k8s/nodeConstants.ts @@ -0,0 +1,29 @@ +/* + * Copyright 2025 The Kubernetes Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * The exact label keys checked by Node.getNodePool(). + * + * Exported separately so stories, tests, and other consumers can use the + * same source of truth without importing the full Node implementation. + */ +export const NODE_POOL_LABEL_KEYS = [ + 'cloud.google.com/gke-nodepool', + 'kubernetes.azure.com/agentpool', + 'eks.amazonaws.com/nodegroup', + 'kops.k8s.io/instancegroup', + 'cluster.x-k8s.io/deployment-name', +] as const;