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

Bug 1911269: hide "waiting for builds" info message when a build is present #7665

Merged
merged 1 commit into from Jan 22, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -4,9 +4,13 @@ import { useK8sWatchResources } from '@console/internal/components/utils/k8s-wat
import { getBuildConfigsForResource } from '../utils';
import { BuildConfigOverviewItem } from '../types';

export const useBuildConfigsWatcher = (
resource: K8sResourceKind,
): { loaded: boolean; loadError: string; buildConfigs: BuildConfigOverviewItem[] } => {
export type BuildConfigData = {
loaded: boolean;
loadError: string;
buildConfigs: BuildConfigOverviewItem[];
};

export const useBuildConfigsWatcher = (resource: K8sResourceKind): BuildConfigData => {
const [loaded, setLoaded] = React.useState<boolean>(false);
const [loadError, setLoadError] = React.useState<string>(null);
const [buildConfigs, setBuildConfigs] = React.useState<BuildConfigOverviewItem[]>();
Expand Down
63 changes: 37 additions & 26 deletions frontend/public/components/overview/pods-overview.tsx
@@ -1,13 +1,15 @@
import * as _ from 'lodash-es';
import * as React from 'react';
import { Link } from 'react-router-dom';
import { useTranslation } from 'react-i18next';

import { Alert, AlertActionLink } from '@patternfly/react-core';
import {
Status,
usePodsWatcher,
getPodsForResource,
getResourcesToWatchForPods,
BuildConfigData,
} from '@console/shared';
import { ResourceLink, resourcePath, SidebarSectionHeading, LoadingBox } from '../utils';
import { podPhase, PodKind, K8sResourceKind, referenceFor } from '../../module/k8s';
Expand Down Expand Up @@ -94,7 +96,7 @@ const PodOverviewItem: React.FC<PodOverviewItemProps> = ({ pod }) => {
metadata: { name, namespace },
} = pod;
const phase = podPhase(pod);

const { t } = useTranslation();
return (
<li className="list-group-item container-fluid">
<div className="row">
Expand All @@ -105,7 +107,7 @@ const PodOverviewItem: React.FC<PodOverviewItemProps> = ({ pod }) => {
<Status status={phase} />
</span>
<span className="col-xs-3 text-right">
<Link to={`${resourcePath(kind, name, namespace)}/logs`}>View logs</Link>
<Link to={`${resourcePath(kind, name, namespace)}/logs`}>{t('public~View logs')}</Link>
</span>
</div>
</li>
Expand All @@ -128,22 +130,26 @@ const PodsOverviewList: React.SFC<PodOverviewListProps> = ({ pods }) => (

PodsOverviewList.displayName = 'PodsOverviewList';

const isComplete = (build: K8sResourceKind) => build.status?.completionTimestamp;

export const PodsOverviewContent: React.SFC<PodsOverviewContentProps> = ({
obj,
pods,
loaded,
loadError,
allPodsLink,
emptyText,
hasBuildConfig,
buildConfigData,
}) => {
const {
metadata: { name, namespace },
} = obj;

const { t } = useTranslation();
const [showWaitingPods, setShowWaitingPods] = React.useState(false);
const showWaitingForBuildAlert =
hasBuildConfig && isDeploymentGeneratedByWebConsole(obj) && pods.some(isPodWithoutImageId);
buildConfigData.buildConfigs?.length > 0 &&
!buildConfigData.buildConfigs[0].builds.some((build) => isComplete(build)) &&
isDeploymentGeneratedByWebConsole(obj);

let filteredPods = [...pods];
if (showWaitingForBuildAlert && !showWaitingPods) {
Expand All @@ -154,32 +160,37 @@ export const PodsOverviewContent: React.SFC<PodsOverviewContentProps> = ({
const errorPodCount = _.size(_.filter(pods, (pod) => isPodError(pod)));
const podsShown = Math.max(Math.min(errorPodCount, MAX_ERROR_PODS), MAX_PODS);
const linkTo = allPodsLink || `${resourcePath(referenceFor(obj), name, namespace)}/pods`;
const emptyMessage = emptyText || 'No Pods found for this resource.';
const emptyMessage = emptyText || t('public~No Pods found for this resource.');

const podAlert = showWaitingForBuildAlert ? (
<Alert
isInline
variant="info"
title={t('public~Waiting for the build')}
actionLinks={
<AlertActionLink onClick={() => setShowWaitingPods(!showWaitingPods)}>
{showWaitingPods
? t('public~Hide waiting pods with errors')
: t('public~Show waiting pods with errors')}
</AlertActionLink>
}
>
{t(
'public~Waiting for the first build to run successfully. You may temporarily see "ImagePullBackOff" and "ErrImagePull" errors while waiting.',
)}
</Alert>
) : null;

return (
<>
<SidebarSectionHeading text="Pods">
<SidebarSectionHeading text={t('public~Pods')}>
{_.size(pods) > podsShown && (
<Link className="sidebar__section-view-all" to={linkTo}>
{`View all (${_.size(pods)})`}
{t('public~View all {{podSize}}', { podSize: _.size(pods) })}
</Link>
)}
</SidebarSectionHeading>
{showWaitingForBuildAlert ? (
<Alert
isInline
variant="info"
title="Waiting for the build"
actionLinks={
<AlertActionLink onClick={() => setShowWaitingPods(!showWaitingPods)}>
{`${showWaitingPods ? 'Hide' : 'Show'} waiting pods with errors`}
</AlertActionLink>
}
>
Waiting for the first build to run successfully. You may temporarily see
"ImagePullBackOff" and "ErrImagePull" errors while waiting.
</Alert>
) : null}
{buildConfigData.loaded && !buildConfigData.loadError && podAlert}
{_.isEmpty(filteredPods) ? (
<span className="text-muted">{loaded || !!loadError ? emptyMessage : <LoadingBox />}</span>
) : (
Expand Down Expand Up @@ -281,15 +292,15 @@ type PodsOverviewContentProps = {
loadError: string;
allPodsLink?: string;
emptyText?: string;
hasBuildConfig?: boolean;
buildConfigData?: BuildConfigData;
podsFilter?: (pod: PodKind) => boolean;
};

type PodsOverviewProps = {
obj: K8sResourceKind;
allPodsLink?: string;
emptyText?: string;
hasBuildConfig?: boolean;
buildConfigData?: BuildConfigData;
podsFilter?: (pod: PodKind) => boolean;
hideIfEmpty?: boolean;
};
Expand All @@ -299,6 +310,6 @@ type PodsOverviewMultipleProps = {
podResources: K8sResourceKind[];
allPodsLink?: string;
emptyText?: string;
hasBuildConfig?: boolean;
buildConfigData?: BuildConfigData;
podsFilter?: (pod: PodKind) => boolean;
};
Expand Up @@ -22,12 +22,12 @@ export const OverviewDetailsResourcesTab: React.SFC<OverviewDetailsResourcesTabP
}) => {
const { hpas, obj } = item;
const pluginComponents = usePluginsOverviewTabSection(item);
const { buildConfigs } = useBuildConfigsWatcher(obj);
const hasBuildConfig = buildConfigs?.length > 0;
const { loaded, loadError, buildConfigs } = useBuildConfigsWatcher(obj);

return (
<div className="overview__sidebar-pane-body">
<ManagedByOperatorLink obj={item.obj} />
<PodsOverview obj={obj} hasBuildConfig={hasBuildConfig} />
<PodsOverview obj={obj} buildConfigData={{ loaded, loadError, buildConfigs }} />
<BuildOverview buildConfigs={buildConfigs} />
<HPAOverview hpas={hpas} />
{pluginComponents.map(({ Component, key }) => (
Expand Down
7 changes: 7 additions & 0 deletions frontend/public/locales/en/public.json
Expand Up @@ -384,6 +384,13 @@
"Limit Ranges": "Limit Ranges",
"Chargeback": "Chargeback",
"Custom Resource Definitions": "Custom Resource Definitions",
"View logs": "View logs",
"No Pods found for this resource.": "No Pods found for this resource.",
"Waiting for the build": "Waiting for the build",
"Hide waiting pods with errors": "Hide waiting pods with errors",
"Show waiting pods with errors": "Show waiting pods with errors",
"Waiting for the first build to run successfully. You may temporarily see \"ImagePullBackOff\" and \"ErrImagePull\" errors while waiting.": "Waiting for the first build to run successfully. You may temporarily see \"ImagePullBackOff\" and \"ErrImagePull\" errors while waiting.",
"View all {{podSize}}": "View all {{podSize}}",
Comment on lines +387 to +393
Copy link
Member

Choose a reason for hiding this comment

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

👍

"Reconnect": "Reconnect",
"Ready": "Ready",
"Restarts": "Restarts",
Expand Down