Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ Adds an activity to the Activity Card of Overview Dashboard where the triggering

| Name | Value Type | Optional | Description |
| ---- | ---------- | -------- | ----------- |
| `k8sResource` | `CodeRef<FirehoseResource & { isList: true; }>` | no | The utilization item to be replaced. |
| `k8sResource` | `CodeRef<WatchK8sResource & { prop: string; } & { isList: true; }>` | no | The utilization item to be replaced. |
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we need to update the 4.22 changelog with this breaking change

| `component` | `CodeRef<React.ComponentType<K8sActivityProps<T>>>` | no | The action component. |
| `isActivity` | `CodeRef<(resource: T) => boolean>` | yes | Function which determines if the given resource represents the action. If not defined, every resource represents activity. |
| `getTimestamp` | `CodeRef<(resource: T) => Date>` | yes | Timestamp for the given action, which will be used for ordering. |
Expand All @@ -405,7 +405,7 @@ Adds a health subsystem to the status card of Overview dashboard where the sourc
| Name | Value Type | Optional | Description |
| ---- | ---------- | -------- | ----------- |
| `title` | `string` | no | Title of operators section in the popup. |
| `resources` | `CodeRef<FirehoseResource[]>` | no | Kubernetes resources which will be fetched and passed to `healthHandler`. |
| `resources` | `CodeRef<WatchK8sResourceWithProp[]>` | no | Kubernetes resources which will be fetched and passed to `healthHandler`. |
| `getOperatorsWithStatuses` | `CodeRef<GetOperatorsWithStatuses<T>>` | yes | Resolves status for the operators. |
| `operatorRowLoader` | `CodeRef<React.ComponentType<OperatorRowProps<T>>>` | yes | Loader for popup row component. |
| `viewAllLink` | `string` | yes | Links to all resources page. If not provided then a list page of the first resource from resources prop is used. |
Expand All @@ -425,7 +425,7 @@ Adds a health subsystem to the status card of Overview dashboard where the sourc
| `title` | `string` | no | The display name of the subsystem. |
| `queries` | `string[]` | no | The Prometheus queries |
| `healthHandler` | `CodeRef<PrometheusHealthHandler>` | no | Resolve the subsystem's health. |
| `additionalResource` | `CodeRef<FirehoseResource>` | yes | Additional resource which will be fetched and passed to `healthHandler`. |
| `additionalResource` | `CodeRef<WatchK8sResourceWithProp>` | yes | Additional resource which will be fetched and passed to `healthHandler`. |
| `popupComponent` | `CodeRef<React.ComponentType<PrometheusHealthPopupProps>>` | yes | Loader for popup content. If defined, a health item will be represented as a link which opens popup with given content. |
| `popupTitle` | `string` | yes | The title of the popover. |
| `popupClassname` | `string` | yes | Optional classname for the popup top-level component. |
Expand Down Expand Up @@ -466,8 +466,8 @@ Adds a health subsystem to the status card of Overview dashboard where the sourc
| `url` | `string` | no | The URL to fetch data from. It will be prefixed with base k8s URL. |
| `healthHandler` | `CodeRef<URLHealthHandler<T>>` | no | Resolve the subsystem's health. |
| `fetch` | `CodeRef<Fetch>` | yes | Custom function to fetch data from the URL.<br/>If none is specified, default one (`coFetchJson`) will be used.<br/>Response is then parsed by `healthHandler`. |
| `additionalResource` | `CodeRef<FirehoseResource>` | yes | Additional resource which will be fetched and passed to `healthHandler`. |
| `popupComponent` | `CodeRef<React.ComponentType<{ healthResult?: T; healthResultError?: any; k8sResult?: FirehoseResult<R>; }>>` | yes | Loader for popup content. If defined, a health item will be represented as a link which opens popup with given content. |
| `additionalResource` | `CodeRef<WatchK8sResourceWithProp>` | yes | Additional resource which will be fetched and passed to `healthHandler`. |
| `popupComponent` | `CodeRef<React.ComponentType<{ healthResult?: T; healthResultError?: any; k8sResult?: WatchK8sResultsObject<R>; }>>` | yes | Loader for popup content. If defined, a health item will be represented as a link which opens popup with given content. |
| `popupTitle` | `string` | yes | The title of the popover. |

---
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ export type HealthItemProps = WithClassNameProps<{

export type ResourceInventoryItemProps = {
resources: K8sResourceCommon[];
additionalResources?: { [key: string]: [] };
additionalResources?: { [key: string]: K8sResourceCommon[] };
mapper?: StatusGroupMapper;
kind: K8sModel;
isLoading: boolean;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,22 @@ export type WatchK8sResourcesGeneric = {
};
};

/**
* WatchK8sResource with a `prop` field that serves as a key to identify
* this resource in multi-resource watch results. Used by dashboard extensions
* and legacy components that watch multiple K8s resources simultaneously.
*/
export type WatchK8sResourceWithProp = WatchK8sResource & {
prop: string;
};

export type WatchK8sResult<R extends K8sResourceCommon | K8sResourceCommon[]> = [R, boolean, any];

/**
* @deprecated Use WatchK8sResource with useK8sWatchResource hook instead.
* FirehoseResource will be removed in a future release.
* @see WatchK8sResource
*/
export type FirehoseResource = {
kind: K8sResourceKindReference;
name?: string;
Expand All @@ -239,6 +255,10 @@ export type FirehoseResource = {
fieldSelector?: string;
};

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Leaving the following Firehose types for backward compatibility in case any external plugins have imported them. Can remove them once I double check they are not being used externally.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vojtechszocs @logonoff Could you confirm ☝

/**
* @deprecated Use WatchK8sResultsObject instead. FirehoseResult will be removed in a future release.
* @see WatchK8sResultsObject
*/
export type FirehoseResult<
R extends K8sResourceCommon | K8sResourceCommon[] = K8sResourceCommon[]
> = {
Expand All @@ -249,12 +269,14 @@ export type FirehoseResult<
kind?: string;
};

/**
* @deprecated Use WatchK8sResults instead. FirehoseResourcesResult will be removed in a future release.
* @see WatchK8sResults
*/
export type FirehoseResourcesResult = {
[key: string]: FirehoseResult<K8sResourceCommon | K8sResourceCommon[]>;
};

export type WatchK8sResult<R extends K8sResourceCommon | K8sResourceCommon[]> = [R, boolean, any];

export type UseK8sWatchResource = <R extends K8sResourceCommon | K8sResourceCommon[]>(
initResource: WatchK8sResource | null,
) => WatchK8sResult<R>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ import type {
PrometheusResponse,
ResourcesObject,
WatchK8sResults,
FirehoseResourcesResult,
FirehoseResult,
WatchK8sResultsObject,
OverviewCardSpan,
K8sResourceKind,
} from './console-types';
Expand All @@ -18,7 +17,7 @@ import type {
export type CardSpan = OverviewCardSpan;

export type GetOperatorsWithStatuses<R extends K8sResourceCommon = K8sResourceCommon> = (
resources: FirehoseResourcesResult,
resources: WatchK8sResults<ResourcesObject>,
) => OperatorStatusWithResources<R>[];

export type K8sActivityProps<R extends K8sResourceCommon = K8sResourceCommon> = {
Expand Down Expand Up @@ -53,13 +52,13 @@ export type OperatorHealth = {
export type PrometheusHealthHandler = (
responses: { response: PrometheusResponse; error: any }[],
t?: TFunction,
additionalResource?: FirehoseResult<K8sResourceCommon | K8sResourceCommon[]>,
additionalResource?: WatchK8sResultsObject<K8sResourceCommon | K8sResourceCommon[]>,
infrastructure?: K8sResourceKind,
) => SubsystemHealth;

export type PrometheusHealthPopupProps = {
responses: { response: PrometheusResponse; error: any }[];
k8sResult?: FirehoseResult<K8sResourceCommon | K8sResourceCommon[]>;
k8sResult?: WatchK8sResultsObject<K8sResourceCommon | K8sResourceCommon[]>;
hide: () => void;
};

Expand All @@ -80,7 +79,7 @@ export type SubsystemHealth = {
export type URLHealthHandler<
R,
T extends K8sResourceCommon | K8sResourceCommon[] = K8sResourceCommon | K8sResourceCommon[]
> = (response: R, error: any, additionalResource?: FirehoseResult<T>) => SubsystemHealth;
> = (response: R, error: any, additionalResource?: WatchK8sResultsObject<T>) => SubsystemHealth;

export type StatusPopupItemProps = {
children: ReactNode;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import type {
StatusGroupMapper,
WatchK8sResources,
WatchK8sResults,
FirehoseResource,
FirehoseResult,
WatchK8sResourceWithProp,
WatchK8sResultsObject,
} from './console-types';
import type {
CardSpan,
Expand Down Expand Up @@ -62,7 +62,7 @@ export type DashboardsOverviewHealthPrometheusSubsystem = Extension<
/** Resolve the subsystem's health. */
healthHandler: CodeRef<PrometheusHealthHandler>;
/** Additional resource which will be fetched and passed to `healthHandler`. */
additionalResource?: CodeRef<FirehoseResource>;
additionalResource?: CodeRef<WatchK8sResourceWithProp>;
/** Loader for popup content. If defined, a health item will be represented as a link which opens popup with given content. */
popupComponent?: CodeRef<React.ComponentType<PrometheusHealthPopupProps>>;
/** The title of the popover. */
Expand Down Expand Up @@ -96,13 +96,13 @@ export type DashboardsOverviewHealthURLSubsystem<
*/
fetch?: CodeRef<Fetch>;
/** Additional resource which will be fetched and passed to `healthHandler`. */
additionalResource?: CodeRef<FirehoseResource>;
additionalResource?: CodeRef<WatchK8sResourceWithProp>;
/** Loader for popup content. If defined, a health item will be represented as a link which opens popup with given content. */
popupComponent?: CodeRef<
React.ComponentType<{
healthResult?: T;
healthResultError?: any;
k8sResult?: FirehoseResult<R>;
k8sResult?: WatchK8sResultsObject<R>;
}>
>;
/** The title of the popover. */
Expand Down Expand Up @@ -138,7 +138,7 @@ export type DashboardsOverviewHealthOperator<
/** Title of operators section in the popup. */
title: string;
/** Kubernetes resources which will be fetched and passed to `healthHandler`. */
resources: CodeRef<FirehoseResource[]>;
resources: CodeRef<WatchK8sResourceWithProp[]>;
/** Resolves status for the operators. */
getOperatorsWithStatuses?: CodeRef<GetOperatorsWithStatuses<T>>;
/** Loader for popup row component. */
Expand Down Expand Up @@ -193,7 +193,7 @@ export type DashboardsOverviewResourceActivity<
'console.dashboards/overview/activity/resource',
{
/** The utilization item to be replaced. */
k8sResource: CodeRef<FirehoseResource & { isList: true }>;
k8sResource: CodeRef<WatchK8sResourceWithProp & { isList: true }>;
/** Function which determines if the given resource represents the action. If not defined, every resource represents activity. */
isActivity?: CodeRef<(resource: T) => boolean>;
/** Timestamp for the given action, which will be used for ordering. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,13 @@ import { useCallback } from 'react';
import * as _ from 'lodash';
import { useTranslation } from 'react-i18next';
import { Link } from 'react-router';
import type { GetOperatorsWithStatuses, OperatorRowProps } from '@console/dynamic-plugin-sdk';
import type {
GetOperatorsWithStatuses,
OperatorRowProps,
WatchK8sResults,
K8sResourceCommon,
} from '@console/dynamic-plugin-sdk';
import type { LazyLoader } from '@console/internal/components/utils/async';
import type { FirehoseResourcesResult } from '@console/internal/components/utils/types';
import { getMostImportantStatuses } from './state-utils';
import { HealthState } from './states';
import StatusItem, { StatusPopupSection } from './StatusPopup';
Expand Down Expand Up @@ -75,7 +79,7 @@ export const OperatorsSection: FC<OperatorsSectionProps> = ({
};

type OperatorsSectionProps = {
resources: FirehoseResourcesResult;
resources: WatchK8sResults<{ [key: string]: K8sResourceCommon | K8sResourceCommon[] }>;
getOperatorsWithStatuses: GetOperatorsWithStatuses;
title: string;
linkTo: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,19 @@ import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
import * as fuzzy from 'fuzzysearch';
import * as _ from 'lodash';
import { useTranslation } from 'react-i18next';
import type { WatchK8sResultsObject } from '@console/dynamic-plugin-sdk';
import type { ConsoleSelectProps } from '@console/internal/components/utils/console-select';
import { ConsoleSelect } from '@console/internal/components/utils/console-select';
import { ResourceIcon } from '@console/internal/components/utils/resource-icon';
import { LoadingInline } from '@console/internal/components/utils/status-box';
import type { FirehoseResult } from '@console/internal/components/utils/types';
import type { K8sResourceKind, K8sKind } from '@console/internal/module/k8s';
import { referenceForModel, modelFor, referenceFor } from '@console/internal/module/k8s';

/** Extended result type that includes optional kind for badge display fallback */
type ResourceDropdownResult = WatchK8sResultsObject<K8sResourceKind | K8sResourceKind[]> & {
kind?: string;
};

type DropdownItemProps = {
model: K8sKind;
name: string;
Expand Down Expand Up @@ -57,7 +62,7 @@ export interface ResourceDropdownProps {
transformLabel?: Function;
loaded?: boolean;
loadError?: unknown;
resources?: FirehoseResult[];
resources?: ResourceDropdownResult[];
autoSelect?: boolean;
resourceFilter?: (resource: K8sResourceKind) => boolean;
onChange?: (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,30 @@ import { useMemo } from 'react';
import { FormGroup, FormHelperText, HelperText, HelperTextItem } from '@patternfly/react-core';
import type { FormikValues } from 'formik';
import { useField, useFormikContext } from 'formik';
import type { FirehoseResult } from '@console/internal/components/utils/types';
import { useFormikValidationFix } from '../../hooks/useFormikValidationFix';
import type { ResourceDropdownProps } from '../dropdown/ResourceDropdown';
import { ResourceDropdown } from '../dropdown/ResourceDropdown';
import type { DropdownFieldProps } from './field-types';
import { getFieldId } from './field-utils';

export interface ResourceDropdownFieldProps extends DropdownFieldProps {
dataSelector: ResourceDropdownProps['dataSelector'];
resources: FirehoseResult[];
showBadge?: ResourceDropdownProps['showBadge'];
onLoad?: ResourceDropdownProps['onLoad'];
onChange?: ResourceDropdownProps['onChange'];
resourceFilter?: ResourceDropdownProps['resourceFilter'];
autoSelect?: ResourceDropdownProps['autoSelect'];
placeholder?: string;
actionItems?: ResourceDropdownProps['actionItems'];
appendItems?: ResourceDropdownProps['appendItems'];
customResourceKey?: ResourceDropdownProps['customResourceKey'];
export interface ResourceDropdownFieldProps
extends Omit<DropdownFieldProps, 'onChange'>,
Pick<
ResourceDropdownProps,
| 'dataSelector'
| 'resources'
| 'showBadge'
| 'onLoad'
| 'onChange'
| 'resourceFilter'
| 'autoSelect'
| 'placeholder'
| 'actionItems'
| 'appendItems'
| 'customResourceKey'
| 'menuClassName'
> {
dataTest?: string;
menuClassName?: ResourceDropdownProps['menuClassName'];
}

const ResourceDropdownField: FC<ResourceDropdownFieldProps> = ({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import { useState, useCallback, useMemo } from 'react';
import * as _ from 'lodash';
import type { WatchK8sResource, WatchK8sResults } from '@console/dynamic-plugin-sdk';
import type {
WatchK8sResource,
K8sResourceCommon,
WatchK8sResultsObject,
} from '@console/dynamic-plugin-sdk';
import { useK8sWatchResources } from '@console/internal/components/utils/k8s-watch-hook';

type UseDynamicK8sWatchResourcesResult = {
results: WatchK8sResults<Record<string, WatchK8sResource>>;
results: Record<string, WatchK8sResultsObject<K8sResourceCommon | K8sResourceCommon[]>>;
watchResource: (key: string, resource: WatchK8sResource) => void;
stopWatchResource: (key: string) => void;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,13 @@ import YAML from 'js-yaml';
import * as _ from 'lodash';
import { useTranslation } from 'react-i18next';
import { PodDisruptionBudgetModel } from '@console/app/src/models';
import type { AddAction, CatalogItemType, Perspective } from '@console/dynamic-plugin-sdk';
import type {
AddAction,
CatalogItemType,
Perspective,
WatchK8sResultsObject,
} from '@console/dynamic-plugin-sdk';
import { isAddAction, isCatalogItemType, isPerspective } from '@console/dynamic-plugin-sdk';
import type { FirehoseResult } from '@console/internal/components/utils/types';
import {
BuildConfigModel,
ClusterRoleModel,
Expand Down Expand Up @@ -331,7 +335,10 @@ const useDefaultSamples = () => {
);
};

export const useResourceSidebarSamples = (kindObj: K8sKind, yamlSamplesList: FirehoseResult) => {
export const useResourceSidebarSamples = (
kindObj: K8sKind,
yamlSamplesList: WatchK8sResultsObject<K8sResourceKind[]>,
) => {
const defaultSamples = useDefaultSamples();

if (!kindObj) {
Expand Down
23 changes: 12 additions & 11 deletions frontend/packages/console-shared/src/types/pod.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import type {
ExtPodKind,
K8sResourceCommon,
PodControllerOverviewItem,
WatchK8sResultsObject,
} from '@console/dynamic-plugin-sdk/src/extensions/console-types';
import type { FirehoseResult } from '@console/internal/components/utils/types';
import type { DeploymentKind, PodKind } from '@console/internal/module/k8s';

export type {
Expand All @@ -15,19 +16,19 @@ export type {
} from '@console/dynamic-plugin-sdk/src/extensions/console-types';

export interface PodDataResources {
replicationControllers: FirehoseResult;
replicaSets: FirehoseResult;
pods: FirehoseResult<PodKind[]>;
deploymentConfigs?: FirehoseResult;
deployments?: FirehoseResult<DeploymentKind[]>;
replicationControllers: WatchK8sResultsObject<K8sResourceCommon[]>;
replicaSets: WatchK8sResultsObject<K8sResourceCommon[]>;
pods: WatchK8sResultsObject<PodKind[]>;
deploymentConfigs?: WatchK8sResultsObject<K8sResourceCommon[]>;
deployments?: WatchK8sResultsObject<DeploymentKind[]>;
}

export interface PodRingResources {
pods: FirehoseResult<PodKind[]>;
replicaSets: FirehoseResult;
replicationControllers: FirehoseResult;
deployments?: FirehoseResult<DeploymentKind[]>;
deploymentConfigs?: FirehoseResult;
pods: WatchK8sResultsObject<PodKind[]>;
replicaSets: WatchK8sResultsObject<K8sResourceCommon[]>;
replicationControllers: WatchK8sResultsObject<K8sResourceCommon[]>;
deployments?: WatchK8sResultsObject<DeploymentKind[]>;
deploymentConfigs?: WatchK8sResultsObject<K8sResourceCommon[]>;
}

export interface PodRingData {
Expand Down
Loading