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

Move topology from dev-console to its own monorepo #7254

Merged
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
3 changes: 2 additions & 1 deletion frontend/packages/console-app/package.json
Expand Up @@ -23,7 +23,8 @@
"@console/patternfly": "0.0.0-fixed",
"@console/pipelines-plugin": "0.0.0-fixed",
"@console/plugin-sdk": "0.0.0-fixed",
"@console/shared": "0.0.0-fixed"
"@console/shared": "0.0.0-fixed",
"@console/topology": "0.0.0-fixed"
},
"consolePlugin": {
"entry": "src/plugin.tsx"
Expand Down
1 change: 1 addition & 0 deletions frontend/packages/console-shared/src/components/index.ts
Expand Up @@ -18,5 +18,6 @@ export * from './popover';
export * from './layout';
export * from './utils';
export * from './modal';
export * from './modals';
export * from './hpa';
export * from './multi-tab-list';
Expand Up @@ -8,8 +8,9 @@ import {
ModalSubmitFooter,
} from '@console/internal/components/factory/modal';
import { Formik, FormikProps, FormikValues } from 'formik';
import { YellowExclamationTriangleIcon, InputField } from '@console/shared';
import { K8sResourceKind } from '@console/internal/module/k8s';
import { YellowExclamationTriangleIcon } from '../status';
import { InputField } from '../formik-fields';

type DeleteResourceModalProps = {
resourceName: string;
Expand Down
@@ -0,0 +1,4 @@
export const deleteResourceModal = (props) =>
import('./DeleteResourceModal' /* webpackChunkName: "shared-modals" */).then((m) =>
m.deleteResourceModal(props),
);
Expand Up @@ -4,7 +4,7 @@ import * as _ from 'lodash';
import { Button, Split, SplitItem, Bullseye } from '@patternfly/react-core';
import { K8sResourceKind, k8sPatch, K8sKind } from '@console/internal/module/k8s';
import { AngleUpIcon, AngleDownIcon } from '@patternfly/react-icons';
import { useRelatedHPA } from '@console/dev-console/src/components/hpa/hooks';
import { useRelatedHPA } from '../../hooks/hpa-hooks';
import { usePodRingLabel, usePodScalingAccessStatus } from '../../utils';
import { ExtPodKind } from '../../types';
import PodStatus from './PodStatus';
Expand Down
Expand Up @@ -2,12 +2,12 @@ import * as React from 'react';
import { shallow } from 'enzyme';
import { PodKind } from '@console/internal/module/k8s';
import { samplePods } from '@console/shared/src/utils/__tests__/test-resource-data';
import { DeploymentConfigModel } from '@console/internal/models';
import { LongArrowAltRightIcon } from '@patternfly/react-icons';
import PodRingSet from '../PodRingSet';
import { PodRCData } from '../../../types';
import * as hooks from '../../../hooks';
import PodRing from '../PodRing';
import { DeploymentConfigModel } from '@console/internal/models';

describe(PodRingSet.displayName, () => {
let podData: PodRCData;
Expand Down
2 changes: 2 additions & 0 deletions frontend/packages/console-shared/src/constants/common.ts
Expand Up @@ -18,6 +18,8 @@ export const KEYBOARD_SHORTCUTS = Object.freeze({
focusNamespaceDropdown: 'n',
});

export const RESOURCE_NAME_TRUNCATE_LENGTH = 13;

// Use a key for the "all" namespaces option that would be an invalid namespace name to avoid a potential clash
export const ALL_NAMESPACES_KEY = '#ALL_NS#';

Expand Down
@@ -1,8 +1,8 @@
import * as React from 'react';
import { HorizontalPodAutoscalerKind, k8sList } from '@console/internal/module/k8s';
import { HorizontalPodAutoscalerModel } from '@console/internal/models';
import { doesHpaMatch } from './hpa-utils';
import { useK8sWatchResource } from '@console/internal/components/utils/k8s-watch-hook';
import { doesHpaMatch } from '../utils/hpa-utils';

export const useRelatedHPA = (
workloadAPI: string,
Expand Down
1 change: 1 addition & 0 deletions frontend/packages/console-shared/src/hooks/index.ts
Expand Up @@ -19,3 +19,4 @@ export * from './post-form-submit-action';
export * from './flag';
export * from './useUserSettings';
export * from './useUserSettingsCompatibility';
export * from './hpa-hooks';
@@ -0,0 +1,49 @@
import { HorizontalPodAutoscalerKind } from '@console/internal/module/k8s';

export const deploymentHasCpuAndMemoryLimits = {
kind: 'Deployment',
apiVersion: 'apps/v1',
metadata: {
name: 'nodejs-rest-http-with-resource-limits',
namespace: 'test-ns',
},
};

export const deploymentConfigHasCpuAndMemoryLimits = {
kind: 'DeploymentConfig',
apiVersion: 'apps.openshift.io/v1',
metadata: {
name: 'nodejs-rest-http-crud-resource-limits',
namespace: 'test-ns',
},
};

export const cpuScaled: HorizontalPodAutoscalerKind = {
kind: 'HorizontalPodAutoscaler',
apiVersion: 'autoscaling/v2beta2',
metadata: {
name: 'example',
namespace: 'test-ns',
},
spec: {
scaleTargetRef: {
kind: 'DeploymentConfig',
name: 'nodejs-rest-http-crud-resource-limits',
apiVersion: 'apps.openshift.io/v1',
},
minReplicas: 2,
maxReplicas: 10,
metrics: [
{
type: 'Resource',
resource: {
name: 'cpu',
target: {
type: 'Utilization',
averageUtilization: 42,
},
},
},
],
},
};
@@ -0,0 +1,16 @@
import {
deploymentHasCpuAndMemoryLimits,
deploymentConfigHasCpuAndMemoryLimits,
cpuScaled,
} from './hpa-utils-data';
import { doesHpaMatch } from '../hpa-utils';

describe('doesHpaMatch checks if it aligns to a workload', () => {
it('expect not to match when hpa does not target workload', () => {
expect(doesHpaMatch(deploymentHasCpuAndMemoryLimits)(cpuScaled)).toBe(false);
});

it('expect to match when hpa does target workload', () => {
expect(doesHpaMatch(deploymentConfigHasCpuAndMemoryLimits)(cpuScaled)).toBe(true);
});
});
13 changes: 13 additions & 0 deletions frontend/packages/console-shared/src/utils/hpa-utils.ts
@@ -0,0 +1,13 @@
import { HorizontalPodAutoscalerKind, K8sResourceCommon } from '@console/internal/module/k8s';

export const doesHpaMatch = (workload: K8sResourceCommon) => (
thisHPA: HorizontalPodAutoscalerKind,
) => {
const {
apiVersion,
kind,
metadata: { name },
} = workload;
const ref = thisHPA?.spec?.scaleTargetRef;
return ref && ref.apiVersion === apiVersion && ref.kind === kind && ref.name === name;
};
1 change: 1 addition & 0 deletions frontend/packages/console-shared/src/utils/index.ts
Expand Up @@ -14,3 +14,4 @@ export * from './label-filter';
export * from './alert-utils';
export * from './operator-utils';
export * from './helm-utils';
export * from './hpa-utils';
Expand Up @@ -38,7 +38,7 @@ import {
AllPodStatus,
} from '../constants';
import { isKnativeServing, isIdled } from './pod-utils';
import { doesHpaMatch } from '@console/dev-console/src/components/hpa/hpa-utils';
import { doesHpaMatch } from './hpa-utils';

export const WORKLOAD_TYPES = [
'deployments',
Expand Down
7 changes: 0 additions & 7 deletions frontend/packages/dev-console/locales/en/devconsole.json
Expand Up @@ -5,9 +5,6 @@
"Build Configs": "Build Configs",
"Select a project to view the list of build configs": "Select a project to view the list of build configs",
"No resources found": "No resources found",
"Select application": "Select application",
"all applications": "all applications",
"Application": "Application",
"Select Secret Name": "Select Secret Name",
"Save": "Save",
"Cancel": "Cancel",
Expand Down Expand Up @@ -121,10 +118,6 @@
"Defines how many concurrent requests are wanted per instance of the application at a given time (soft limit) and is the recommended configuration for autoscaling. If not specified, will be defaulted to the value set in the cluster config.": "Defines how many concurrent requests are wanted per instance of the application at a given time (soft limit) and is the recommended configuration for autoscaling. If not specified, will be defaulted to the value set in the cluster config.",
"Concurrency Limit": "Concurrency Limit",
"Limits the amount of concurrent requests allowed into one instance of the application at a given time (hard limit), and is configured in the revision template. If not specified, will be defaulted to the value set in the cluster config.": "Limits the amount of concurrent requests allowed into one instance of the application at a given time (hard limit), and is configured in the revision template. If not specified, will be defaulted to the value set in the cluster config.",
"Warning: the application grouping already exists.": "Warning: the application grouping already exists.",
"A unique name given to the application grouping to label your resources.": "A unique name given to the application grouping to label your resources.",
"Select an application for your grouping or {{UNASSIGNED_LABEL}} to not use an application grouping.": "Select an application for your grouping or {{UNASSIGNED_LABEL}} to not use an application grouping.",
"Application Name": "Application Name",
"General": "General",
"Project Name": "Project Name",
"A unique name for the project.": "A unique name for the project.",
Expand Down
1 change: 1 addition & 0 deletions frontend/packages/dev-console/package.json
Expand Up @@ -10,6 +10,7 @@
},
"dependencies": {
"@console/git-service": "0.0.0-fixed",
"@console/topology": "0.0.0-fixed",
"@console/knative-plugin": "0.0.0-fixed",
"@console/pipelines-plugin": "0.0.0-fixed",
"@console/plugin-sdk": "0.0.0-fixed"
Expand Down
@@ -1,6 +1,6 @@
import { deleteResourceModal } from '@console/shared';
import { coFetchJSON } from '@console/internal/co-fetch';
import { history } from '@console/internal/components/utils';
import { deleteResourceModal } from '../components/modals';

export const deleteHelmRelease = (releaseName: string, namespace: string, redirect?: string) => {
return {
Expand Down
@@ -1,7 +1,7 @@
import * as React from 'react';
import * as cx from 'classnames';
import { NamespaceBar } from '@console/internal/components/namespace';
import ApplicationSelector from './dropdown/ApplicationSelector';
import NamespaceBarApplicationSelector from '@console/topology/src/components/dropdowns/NamespaceBarApplicationSelector';

import './NamespacedPage.scss';

Expand Down Expand Up @@ -34,7 +34,7 @@ const NamespacedPage: React.FC<NamespacedPageProps> = ({
onNamespaceChange={onNamespaceChange}
hideProjects={hideProjects}
>
{!hideApplications && <ApplicationSelector disabled={disabled} />}
{!hideApplications && <NamespaceBarApplicationSelector disabled={disabled} />}
Copy link
Contributor

Choose a reason for hiding this comment

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

🤔 Is this PR not just a refactor... why the change in component usage?

Copy link
Member Author

Choose a reason for hiding this comment

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

There were two different ApplicationSelector components, one in shared one in dev-console. Both are now in topology (since the use the topology data retrieval) and this one was renamed.

Copy link
Contributor

Choose a reason for hiding this comment

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

Gotcha. Thanks for the clarification!

{toolbar && <div className="odc-namespaced-page__toolbar">{toolbar}</div>}
</NamespaceBar>
<div
Expand Down
Expand Up @@ -3,8 +3,8 @@ import { connect } from 'react-redux';
import { setActiveApplication } from '@console/internal/actions/ui';
import { RootState } from '@console/internal/redux';
import { getActiveApplication } from '@console/internal/reducers/ui';
import { sanitizeApplicationValue } from '@console/topology/src/utils/application-utils';
import { QUERY_PROPERTIES } from '../const';
import { sanitizeApplicationValue } from '../utils/application-utils';

type StateProps = {
application: string;
Expand Down

This file was deleted.

@@ -1,6 +1,6 @@
import { K8sResourceKind } from '@console/internal/module/k8s';
import { ServiceModel } from '@console/knative-plugin';
import { UNASSIGNED_KEY } from '../../../const';
import { UNASSIGNED_KEY } from '@console/topology/src/const';
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit:

Suggested change
import { UNASSIGNED_KEY } from '@console/topology/src/const';
import { UNASSIGNED_KEY } from '@console/topology';

import { DeployImageFormData, GitImportFormData, Resources } from '../../import/import-types';
import { AppResources } from '../edit-application-types';
import { healthChecksProbeInitialData } from '../../health-checks/health-checks-probe-utils';
Expand Down
Expand Up @@ -10,7 +10,7 @@ import { DeploymentConfigModel, DeploymentModel } from '@console/internal/models
import { hasIcon } from '@console/internal/components/catalog/catalog-item-icon';
import { ServiceModel } from '@console/knative-plugin';
import { Pipeline } from '@console/pipelines-plugin/src/utils/pipeline-augment';
import { UNASSIGNED_KEY } from '../../const';
import { UNASSIGNED_KEY } from '@console/topology/src/const';
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit:

Suggested change
import { UNASSIGNED_KEY } from '@console/topology/src/const';
import { UNASSIGNED_KEY } from '@console/topology';

import { Resources, DeploymentData, GitReadableTypes } from '../import/import-types';
import { AppResources } from './edit-application-types';
import { RegistryType } from '../../utils/imagestream-utils';
Expand Down
3 changes: 1 addition & 2 deletions frontend/packages/dev-console/src/components/hpa/HPAPage.tsx
@@ -1,6 +1,6 @@
import * as React from 'react';
import { Helmet } from 'react-helmet';
import { PageBody } from '@console/shared';
import { PageBody, useRelatedHPA } from '@console/shared';
import { useTranslation } from 'react-i18next';
import { ErrorPage404 } from '@console/internal/components/error';
import { LoadingBox, LoadingInline, PageComponentProps } from '@console/internal/components/utils';
Expand All @@ -11,7 +11,6 @@ import NamespacedPage, { NamespacedPageVariants } from '../NamespacedPage';
import HPAFormikForm from './HPAFormikForm';
import HPAPageHeader from './HPAPageHeader';
import { getLimitWarning, VALID_HPA_TARGET_KINDS } from './hpa-utils';
import { useRelatedHPA } from './hooks';

const HPAPage: React.FC<PageComponentProps> = (props) => {
const { t } = useTranslation();
Expand Down
@@ -1,6 +1,5 @@
import { cloneDeep } from 'lodash';
import {
doesHpaMatch,
getFormData,
getInvalidUsageError,
getLimitWarning,
Expand Down Expand Up @@ -281,20 +280,6 @@ describe('getInvalidUsageError returns an error string when limits are not set',
});
});

describe('doesHpaMatch checks if it aligns to a workload', () => {
it('expect not to match when hpa does not target workload', () => {
expect(doesHpaMatch(deploymentExamples.hasCpuAndMemoryLimits)(hpaExamples.cpuScaled)).toBe(
false,
);
});

it('expect to match when hpa does target workload', () => {
expect(
doesHpaMatch(deploymentConfigExamples.hasCpuAndMemoryLimits)(hpaExamples.cpuScaled),
).toBe(true);
});
});

describe('hasCustomMetrics accurately determines if an hpa contains non-default metrics', () => {
it('expect no metrics to mean no custom metrics', () => {
expect(hasCustomMetrics(null)).toBe(false);
Expand Down