Skip to content

Commit

Permalink
Merge pull request #7520 from invincibleJai/odc-5228
Browse files Browse the repository at this point in the history
Bug 1906685: show sinkbinding as resources in sidebar if owned by source
  • Loading branch information
openshift-merge-robot committed Dec 15, 2020
2 parents 8e5b41a + 7b81829 commit 4446516
Show file tree
Hide file tree
Showing 9 changed files with 202 additions and 114 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import * as React from 'react';
import { SidebarSectionHeading, ResourceLink } from '@console/internal/components/utils';
import { K8sResourceKind, modelFor, referenceFor } from '@console/internal/module/k8s';

type EventSourceOwnedListProps = {
source: K8sResourceKind;
};

const EventSourceOwnedList: React.FC<EventSourceOwnedListProps> = ({ source }) => {
const sourceModel = modelFor(referenceFor(source));
return (
<>
<SidebarSectionHeading text={sourceModel?.label ?? source.kind} />
<ul className="list-group">
<li className="list-group-item">
<ResourceLink
kind={referenceFor(source)}
name={source.metadata?.name}
namespace={source.metadata?.namespace}
/>
</li>
</ul>
</>
);
};

export default EventSourceOwnedList;
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@ import {
} from '@console/internal/components/utils';
import { PodModel } from '@console/internal/models';
import { PodsOverview } from '@console/internal/components/overview/pods-overview';
import EventSourceOwnedList from './EventSourceOwnedList';

export type EventSinkServicesOverviewListProps = {
type EventSourceResourcesProps = {
obj: K8sResourceKind;
ownedSources?: K8sResourceKind[];
};

const EventSinkServicesOverviewList: React.FC<EventSinkServicesOverviewListProps> = ({ obj }) => {
const EventSourceResources: React.FC<EventSourceResourcesProps> = ({ obj, ownedSources }) => {
const { t } = useTranslation();
const {
kind,
Expand Down Expand Up @@ -83,8 +85,12 @@ const EventSinkServicesOverviewList: React.FC<EventSinkServicesOverviewListProps
</ul>
</>
)}
{ownedSources?.length > 0 &&
ownedSources.map((source) => (
<EventSourceOwnedList key={source.metadata.uid} source={source} />
))}
</>
);
};

export default EventSinkServicesOverviewList;
export default EventSourceResources;
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import KnativeRevisionResources from './KnativeRevisionResources';
import RevisionsOverviewList from './RevisionsOverviewList';
import KSRoutesOverviewList from './RoutesOverviewList';
import ConfigurationsOverviewList from './ConfigurationsOverviewList';
import EventSinkServicesOverviewList from './EventSinkServicesOverviewList';
import EventSourceResources from './EventSourceResources';
import {
isDynamicEventResourceKind,
isEventingChannelResourceKind,
Expand All @@ -27,9 +27,9 @@ type OverviewDetailsResourcesTabProps = {
};

const getSidebarResources = (item: KnativeServiceOverviewItem) => {
const { obj, ksroutes, revisions, configurations } = item;
const { obj, ksroutes, revisions, configurations, eventSources } = item;
if (isDynamicEventResourceKind(referenceFor(obj))) {
return <EventSinkServicesOverviewList obj={obj} />;
return <EventSourceResources obj={obj} ownedSources={eventSources} />;
}
if (isEventingChannelResourceKind(referenceFor(obj))) {
return <EventPubSubResources item={item} />;
Expand All @@ -42,7 +42,7 @@ const getSidebarResources = (item: KnativeServiceOverviewItem) => {
case ServiceModel.kind:
return <KnativeServiceResources item={item} />;
case CamelKameletBindingModel.kind:
return <EventSinkServicesOverviewList obj={obj} />;
return <EventSourceResources obj={obj} ownedSources={eventSources} />;
case EventingBrokerModel.kind:
case EventingTriggerModel.kind:
case EventingSubscriptionModel.kind:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import * as React from 'react';
import { shallow, ShallowWrapper } from 'enzyme';
import { K8sResourceKind } from '@console/internal/module/k8s';
import { ResourceLink, SidebarSectionHeading } from '@console/internal/components/utils';
import EventSourceOwnedList from '../EventSourceOwnedList';
import { getEventSourceResponse } from '../../../topology/__tests__/topology-knative-test-data';
import { EventSourceSinkBindingModel } from '../../../models';

type EventSourceOwnedListProps = React.ComponentProps<typeof EventSourceOwnedList>;

describe('EventSourceOwnedList', () => {
const mockData: K8sResourceKind = getEventSourceResponse(EventSourceSinkBindingModel).data[0];
let wrapper: ShallowWrapper<EventSourceOwnedListProps>;
beforeEach(() => {
wrapper = shallow(<EventSourceOwnedList source={mockData} />);
});

it('should render SidebarSectionHeading, ResourceLink', () => {
expect(wrapper.find(SidebarSectionHeading)).toHaveLength(1);
expect(wrapper.find(ResourceLink)).toHaveLength(1);
});
});
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as React from 'react';
import { shallow } from 'enzyme';
import * as _ from 'lodash';
import { referenceForModel } from '@console/internal/module/k8s';
import { K8sResourceKind, referenceForModel } from '@console/internal/module/k8s';
import { usePodsWatcher } from '@console/shared';
import { PodsOverview } from '@console/internal/components/overview/pods-overview';
import {
Expand All @@ -15,8 +15,11 @@ import {
EventSourceApiServerModel,
EventSourceCamelModel,
EventingIMCModel,
EventSourceContainerModel,
EventSourceSinkBindingModel,
} from '../../../models';
import EventSinkServicesOverviewList from '../EventSinkServicesOverviewList';
import EventSourceResources from '../EventSourceResources';
import EventSourceOwnedList from '../EventSourceOwnedList';

jest.mock('react-i18next', () => {
const reactI18next = require.requireActual('react-i18next');
Expand Down Expand Up @@ -137,16 +140,14 @@ describe('EventSinkServicesOverviewList', () => {
'spec',
'status',
]);
const wrapper = shallow(<EventSinkServicesOverviewList obj={mockData} />);
const wrapper = shallow(<EventSourceResources obj={mockData} />);
expect(wrapper.find('span').text()).toBe(`${i18nNS}~No sink found for this resource.`);
});

it('should have ResourceLink with proper kind for sink to knSvc', () => {
podData = noPodData;
const wrapper = shallow(
<EventSinkServicesOverviewList
obj={getEventSourceResponse(EventSourceApiServerModel).data[0]}
/>,
<EventSourceResources obj={getEventSourceResponse(EventSourceApiServerModel).data[0]} />,
);
const findResourceLink = wrapper.find(ResourceLink);
expect(findResourceLink).toHaveLength(1);
Expand All @@ -166,7 +167,7 @@ describe('EventSinkServicesOverviewList', () => {
...{ spec: sinkData },
};
podData = noPodData;
const wrapper = shallow(<EventSinkServicesOverviewList obj={sinkChannelData} />);
const wrapper = shallow(<EventSourceResources obj={sinkChannelData} />);
const findResourceLink = wrapper.find(ResourceLink);
expect(findResourceLink).toHaveLength(1);
expect(findResourceLink.at(0).props().kind).toEqual(referenceForModel(EventingIMCModel));
Expand All @@ -180,16 +181,14 @@ describe('EventSinkServicesOverviewList', () => {
},
};
podData = noPodData;
const wrapper = shallow(<EventSinkServicesOverviewList obj={mockData} />);
const wrapper = shallow(<EventSourceResources obj={mockData} />);
expect(wrapper.find(ExternalLink)).toHaveLength(1);
expect(wrapper.find(ResourceLink)).toHaveLength(0);
});

it('should have ExternalLink when sinkUri is present', () => {
const wrapper = shallow(
<EventSinkServicesOverviewList
obj={getEventSourceResponse(EventSourceApiServerModel).data[0]}
/>,
<EventSourceResources obj={getEventSourceResponse(EventSourceApiServerModel).data[0]} />,
);
expect(wrapper.find(ExternalLink)).toHaveLength(1);
});
Expand All @@ -199,15 +198,13 @@ describe('EventSinkServicesOverviewList', () => {
getEventSourceResponse(EventSourceApiServerModel).data[0],
'status',
);
const wrapper = shallow(<EventSinkServicesOverviewList obj={mockEventSourceDataNoURI} />);
const wrapper = shallow(<EventSourceResources obj={mockEventSourceDataNoURI} />);
expect(wrapper.find(ExternalLink)).toHaveLength(0);
});

it('should show Deployment if present', () => {
const wrapper = shallow(
<EventSinkServicesOverviewList
obj={getEventSourceResponse(EventSourceApiServerModel).data[0]}
/>,
<EventSourceResources obj={getEventSourceResponse(EventSourceApiServerModel).data[0]} />,
);
const findResourceLink = wrapper.find(ResourceLink);
const findSidebarSectionHeading = wrapper.find(SidebarSectionHeading);
Expand All @@ -219,23 +216,54 @@ describe('EventSinkServicesOverviewList', () => {

it('should show pods if present', () => {
const wrapper = shallow(
<EventSinkServicesOverviewList
obj={getEventSourceResponse(EventSourceApiServerModel).data[0]}
/>,
<EventSourceResources obj={getEventSourceResponse(EventSourceApiServerModel).data[0]} />,
);
expect(wrapper.find(PodsOverview)).toHaveLength(1);
expect(wrapper.find(PodsOverview).props().allPodsLink).toEqual(
'/search/ns/testproject3?kind=Pod&q=sources.knative.dev%2FapiServerSource%3Doverlayimage',
);
});

it('should not show pods if not present', () => {
it('should not show owned source if not present', () => {
podData = noPodData;
const wrapper = shallow(
<EventSinkServicesOverviewList
obj={getEventSourceResponse(EventSourceApiServerModel).data[0]}
<EventSourceResources obj={getEventSourceResponse(EventSourceApiServerModel).data[0]} />,
);
expect(wrapper.find(EventSourceOwnedList)).toHaveLength(0);
});

it('should show owned source if present', () => {
const sourceData = getEventSourceResponse(EventSourceSinkBindingModel).data[0];
const ownSourceData: K8sResourceKind[] = [
{
...sourceData,
metadata: {
name: 'overlayimage-sbs',
namespace: 'testproject3',
uid: '1317f615-9636-11e9-b134-06a61d886b689_2',
ownerReferences: [
{
apiVersion: 'sources.knative.dev/v1beta1',
blockOwnerDeletion: true,
controller: true,
kind: 'ContainerSource',
name: 'overlayimage',
uid: '1317f615-9636-11e9-b134-06a61d886b689_1',
},
],
},
},
];
const wrapper = shallow(
<EventSourceResources
obj={getEventSourceResponse(EventSourceContainerModel).data[0]}
ownedSources={ownSourceData}
/>,
);
expect(wrapper.find(PodsOverview)).toHaveLength(0);
const findOwnedSourcesList = wrapper.find(EventSourceOwnedList);
expect(findOwnedSourcesList).toHaveLength(1);
expect(findOwnedSourcesList.at(0).props().source.kind).toEqual(
EventSourceSinkBindingModel.kind,
);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import KnativeRevisionResources from '../KnativeRevisionResources';
import RevisionsOverviewList from '../RevisionsOverviewList';
import KSRoutesOverviewList from '../RoutesOverviewList';
import ConfigurationsOverviewList from '../ConfigurationsOverviewList';
import EventSinkServicesOverviewList from '../EventSinkServicesOverviewList';
import EventSourceResources from '../EventSourceResources';
import EventPubSubResources from '../EventPubSubResources';
import {
MockKnativeResources,
Expand Down Expand Up @@ -49,7 +49,7 @@ describe('OverviewDetailsKnativeResourcesTab', () => {
expect(wrapper.find(KnativeRevisionResources)).toHaveLength(1);
});

it('should render EventSinkServicesOverviewList on sidebar', () => {
it('should render EventSourceResources on sidebar', () => {
jest
.spyOn(fetchDynamicEventSources, 'isDynamicEventResourceKind')
.mockImplementationOnce(() => true);
Expand All @@ -58,10 +58,10 @@ describe('OverviewDetailsKnativeResourcesTab', () => {
...{ obj: getEventSourceResponse(EventSourceCronJobModel).data[0] },
};
const wrapper = shallow(<OverviewDetailsKnativeResourcesTab {...knItem} />);
expect(wrapper.find(EventSinkServicesOverviewList)).toHaveLength(1);
expect(wrapper.find(EventSourceResources)).toHaveLength(1);
});

it('should render EventSinkServicesOverviewList on sidebar for sinkBinding', () => {
it('should render EventSourceResources on sidebar for sinkBinding', () => {
jest
.spyOn(fetchDynamicEventSources, 'isDynamicEventResourceKind')
.mockImplementationOnce(() => true);
Expand All @@ -70,7 +70,7 @@ describe('OverviewDetailsKnativeResourcesTab', () => {
...{ obj: sampleEventSourceSinkbinding.data[0] },
};
const wrapper = shallow(<OverviewDetailsKnativeResourcesTab {...knItem} />);
expect(wrapper.find(EventSinkServicesOverviewList)).toHaveLength(1);
expect(wrapper.find(EventSourceResources)).toHaveLength(1);
});

it('should render OperatorBackedOwnerReferences with proper props', () => {
Expand Down Expand Up @@ -116,12 +116,12 @@ describe('OverviewDetailsKnativeResourcesTab', () => {
expect(wrapper.find(EventPubSubResources)).toHaveLength(1);
});

it('should render EventSinkServicesOverviewList on sidebar for KameletBinding', () => {
it('should render EventSourceResources on sidebar for KameletBinding', () => {
knItem.item = {
...knItem.item,
...{ obj: sampleSourceKameletBinding.data[0] },
};
const wrapper = shallow(<OverviewDetailsKnativeResourcesTab {...knItem} />);
expect(wrapper.find(EventSinkServicesOverviewList)).toHaveLength(1);
expect(wrapper.find(EventSourceResources)).toHaveLength(1);
});
});
8 changes: 4 additions & 4 deletions frontend/packages/knative-plugin/src/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ export const EventSourceCronJobModel: K8sKind = {

export const EventSourcePingModel: K8sKind = {
apiGroup: KNATIVE_EVENT_SOURCE_APIGROUP,
apiVersion: 'v1alpha2',
apiVersion: 'v1beta1',
kind: 'PingSource',
label: 'Ping Source',
labelPlural: 'Ping Sources',
Expand All @@ -127,7 +127,7 @@ export const EventSourcePingModel: K8sKind = {

export const EventSourceContainerModel: K8sKind = {
apiGroup: KNATIVE_EVENT_SOURCE_APIGROUP,
apiVersion: 'v1alpha2',
apiVersion: 'v1beta1',
kind: 'ContainerSource',
label: 'Container Source',
labelPlural: 'Container Sources',
Expand All @@ -141,7 +141,7 @@ export const EventSourceContainerModel: K8sKind = {

export const EventSourceApiServerModel: K8sKind = {
apiGroup: KNATIVE_EVENT_SOURCE_APIGROUP,
apiVersion: 'v1alpha2',
apiVersion: 'v1beta1',
kind: 'ApiServerSource',
label: 'ApiServerSource',
labelPlural: 'ApiServerSources',
Expand Down Expand Up @@ -183,7 +183,7 @@ export const EventSourceKafkaModel: K8sKind = {

export const EventSourceSinkBindingModel: K8sKind = {
apiGroup: KNATIVE_EVENT_SOURCE_APIGROUP,
apiVersion: 'v1alpha2',
apiVersion: 'v1beta1',
kind: 'SinkBinding',
label: 'SinkBinding',
labelPlural: 'SinkBindings',
Expand Down

0 comments on commit 4446516

Please sign in to comment.