Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: resource browser breaking due to undefined kind #2417

Merged
merged 1 commit into from
Jan 29, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 17 additions & 11 deletions src/components/ResourceBrowser/ResourceList/BaseResourceList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -360,12 +360,23 @@ const BaseResourceListContent = ({
.catch(noop)
}

// This should be used only if shouldOverrideSelectedResourceKind is true
// Group and version are not available for Events / shouldOverrideSelectedResourceKind is true
const getSelectedResourceKindOverride = (lowercaseKind: string) => {
const gvkFromRawData: GVKType =
getFirstResourceFromKindResourceMap(lowercaseKindToResourceGroupMap, lowercaseKind)?.gvk ?? ({} as GVKType)

return {
gvk: {
Group: gvkFromRawData.Group ?? selectedResource.gvk.Group,
Kind: gvkFromRawData.Kind ?? selectedResource.gvk.Kind,
Version: gvkFromRawData.Version ?? selectedResource.gvk.Version,
} as GVKType,
}
}

const renderResourceRow = (resourceData: K8sResourceDetailDataType): JSX.Element => {
const lowercaseKind = (resourceData.kind as string)?.toLowerCase()
// This should be used only if shouldOverrideSelectedResourceKind is true
// Group and version are not available for Events / shouldOverrideSelectedResourceKind is true
const gvkFromRawData =
getFirstResourceFromKindResourceMap(lowercaseKindToResourceGroupMap, lowercaseKind)?.gvk ?? ({} as GVKType)
// Redirection and actions are not possible for Events since the required data for the same is not available
const shouldShowRedirectionAndActions = lowercaseKind !== Nodes.Event.toLowerCase()
const isNodeUnschedulable = isNodeListing && !!resourceData.unschedulable
Expand Down Expand Up @@ -434,13 +445,8 @@ const BaseResourceListContent = ({
getResourceListData={reloadResourceListData as () => Promise<void>}
selectedResource={{
...selectedResource,
...(shouldOverrideSelectedResourceKind && {
gvk: {
Group: gvkFromRawData.Group ?? selectedResource.gvk.Group,
Kind: gvkFromRawData.Kind ?? selectedResource.gvk.Kind,
Version: gvkFromRawData.Version ?? selectedResource.gvk.Version,
} as GVKType,
}),
...(shouldOverrideSelectedResourceKind &&
getSelectedResourceKindOverride(lowercaseKind)),
}}
handleResourceClick={handleResourceClick}
hideDeleteResource={hideDeleteResource}
Expand Down
14 changes: 10 additions & 4 deletions src/components/ResourceBrowser/ResourceList/utils.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { noop } from '@devtron-labs/devtron-fe-common-lib'
import { logExceptionToSentry, noop } from '@devtron-labs/devtron-fe-common-lib'
import {
TARGET_K8S_VERSION_SEARCH_KEY,
LOCAL_STORAGE_EXISTS,
Expand Down Expand Up @@ -61,7 +61,13 @@ export const getUpgradeCompatibilityTippyConfig = ({
export const getFirstResourceFromKindResourceMap = (
lowercaseKindToResourceGroupMap: K8SResourceListType['lowercaseKindToResourceGroupMap'],
kind: string,
) =>
Object.values(lowercaseKindToResourceGroupMap).find(
(resourceGroup) => resourceGroup.gvk.Kind?.toLowerCase() === kind.toLowerCase(),
) => {
// Logging to sentry as kind is expected to be received
if (!kind) {
logExceptionToSentry('Kind is not present in the resource')
}

return Object.values(lowercaseKindToResourceGroupMap).find(
(resourceGroup) => resourceGroup.gvk.Kind?.toLowerCase() === kind?.toLowerCase(),
)
}