Skip to content

Commit

Permalink
Add broker and trigger datamodel and visualization
Browse files Browse the repository at this point in the history
  • Loading branch information
Karthik committed Jul 3, 2020
1 parent 8389fd6 commit ffc1732
Show file tree
Hide file tree
Showing 34 changed files with 810 additions and 104 deletions.
Expand Up @@ -145,7 +145,7 @@ describe('TransformResourceData', () => {
MockKnativeResources,
knativeOverviewResourceUtils,
);
expect(transformedData).toHaveLength(1);
expect(transformedData).toHaveLength(2);
expect(transformedData[0]).toHaveProperties(knativeKeys);
});

Expand Down
Expand Up @@ -295,6 +295,7 @@ export enum ImportOptions {
DOCKERFILE = 'DOCKERFILE',
DATABASE = 'DATABASE',
EVENTSOURCE = 'EVENTSOURCE',
EVENTPUBSUB = 'EVENTPUBSUB',
}

export interface HealthChecksData {
Expand Down
Expand Up @@ -38,6 +38,8 @@ export const TEST_KINDS_MAP = {
migrations: 'VirtualMachineInstanceMigration',
dataVolumes: 'DataVolume',
vmImports: 'VirtualMachineImport',
brokers: 'Broker',
triggers: 'Trigger',
};

export const resources: TopologyDataResources = {
Expand Down
@@ -1,17 +1,12 @@
import * as _ from 'lodash';
import { Node } from '@console/topology';
import { ServiceModel, addEventSource } from '@console/knative-plugin';
import { referenceForModel } from '@console/internal/module/k8s';
import { getKnativeContextMenuAction } from '@console/knative-plugin/src/topology/knative-topology-utils';
import { addResourceMenu, addResourceMenuWithoutCatalog } from '../../../actions/add-resources';
import { GraphData } from '../topology-types';

export const graphActions = (graphData: GraphData, connectorSource?: Node) => {
let resourceMenu = connectorSource ? addResourceMenuWithoutCatalog : addResourceMenu;
const isKnativeService =
connectorSource?.getData()?.data?.kind === referenceForModel(ServiceModel);
if (isKnativeService && graphData.eventSourceEnabled) {
resourceMenu = [...addResourceMenuWithoutCatalog, addEventSource];
}
resourceMenu = getKnativeContextMenuAction(graphData, resourceMenu, connectorSource);
return _.reduce(
resourceMenu,
(menuItems, menuItem) => {
Expand Down
@@ -1,9 +1,9 @@
import * as _ from 'lodash';
import { KebabOption } from '@console/internal/components/utils/kebab';
import { modelFor, referenceFor, referenceForModel } from '@console/internal/module/k8s';
import { modelFor, referenceFor } from '@console/internal/module/k8s';
import { Model, Node } from '@console/topology';
import { asAccessReview } from '@console/internal/components/utils';
import { ServiceModel, addEventSource } from '@console/knative-plugin';
import { getKnativeContextMenuAction } from '@console/knative-plugin/src/topology/knative-topology-utils';
import { addResourceMenuWithoutCatalog } from '../../../actions/add-resources';
import { TopologyApplicationObject, GraphData } from '../topology-types';
import { getTopologyResourceObject } from '../topology-utils';
Expand Down Expand Up @@ -58,12 +58,8 @@ const addResourcesMenu = (
) => {
const primaryResource = application.resources[0]?.resources?.obj;
const connectorSourceObj = connectorSource?.getData()?.resources?.obj || {};
const isKnativeService =
connectorSource?.getData()?.data?.kind === referenceForModel(ServiceModel);
let resourceMenu = addResourceMenuWithoutCatalog;
if (isKnativeService && graphData.eventSourceEnabled) {
resourceMenu = [...addResourceMenuWithoutCatalog, addEventSource];
}
resourceMenu = getKnativeContextMenuAction(graphData, resourceMenu, connectorSource);
return _.reduce(
resourceMenu,
(menuItems, menuItem) => {
Expand Down
Expand Up @@ -38,6 +38,9 @@ export const getAddPageUrl = (
case ImportOptions.EVENTSOURCE:
pageUrl = `/event-source/ns/${ns}`;
break;
case ImportOptions.EVENTPUBSUB:
pageUrl = `/add/ns/${ns}`;
break;
default:
throw new Error('Invalid Import option provided');
}
Expand Down
@@ -0,0 +1,19 @@
import * as React from 'react';
import { StarIcon } from '@patternfly/react-icons';
import {
createKebabAction,
KebabAction,
} from '@console/dev-console/src/utils/add-resources-menu-utils';
import { ImportOptions } from '@console/dev-console/src/components/import/import-types';

export const addSubscription: KebabAction = createKebabAction(
'Add Subscription',
<StarIcon />,
ImportOptions.EVENTPUBSUB,
);

export const addTrigger: KebabAction = createKebabAction(
'Add Trigger',
<StarIcon />,
ImportOptions.EVENTPUBSUB,
);
17 changes: 17 additions & 0 deletions frontend/packages/knative-plugin/src/actions/add-subscription.tsx
@@ -0,0 +1,17 @@
import { KebabOption } from '@console/internal/components/utils';
import { K8sKind, K8sResourceKind } from '@console/internal/module/k8s';
import { EventingSubscriptionModel } from '../models';

export const addSubscription = (model: K8sKind, source: K8sResourceKind): KebabOption => {
return {
label: 'Add Subscription',
href: `add/ns/${source.metadata.namespace}`,
accessReview: {
group: EventingSubscriptionModel.apiGroup,
resource: EventingSubscriptionModel.plural,
name: source.metadata.name,
namespace: source.metadata.namespace,
verb: 'create',
},
};
};
17 changes: 17 additions & 0 deletions frontend/packages/knative-plugin/src/actions/add-trigger.tsx
@@ -0,0 +1,17 @@
import { KebabOption } from '@console/internal/components/utils';
import { K8sKind, K8sResourceKind } from '@console/internal/module/k8s';
import { EventingTriggerModel } from '../models';

export const addTrigger = (model: K8sKind, source: K8sResourceKind): KebabOption => {
return {
label: 'Add Trigger',
href: `add/ns/${source.metadata.namespace}`,
accessReview: {
group: EventingTriggerModel.apiGroup,
resource: EventingTriggerModel.plural,
name: source.metadata.name,
namespace: source.metadata.namespace,
verb: 'create',
},
};
};
2 changes: 2 additions & 0 deletions frontend/packages/knative-plugin/src/actions/index.ts
@@ -1,2 +1,4 @@
export * from './add-event-source';
export * from './traffic-splitting';
export * from './add-trigger';
export * from './add-subscription';
5 changes: 3 additions & 2 deletions frontend/packages/knative-plugin/src/actions/sink-source.ts
@@ -1,10 +1,11 @@
import { KebabOption } from '@console/internal/components/utils';
import { K8sKind, K8sResourceKind } from '@console/internal/module/k8s';
import { setSinkSourceModal } from '../components/modals';
import { EventingSubscriptionModel } from '../models';
import { EventingSubscriptionModel, EventingTriggerModel } from '../models';

export const setSinkSource = (model: K8sKind, source: K8sResourceKind): KebabOption => {
const label = model.kind === EventingSubscriptionModel.kind ? `Move ${model.kind}` : 'Move Sink';
const pubSubModelKinds = [EventingSubscriptionModel.kind, EventingTriggerModel.kind];
const label = pubSubModelKinds.includes(model.kind) ? `Move ${model.kind}` : 'Move Sink';
return {
label,
callback: () =>
Expand Down
Expand Up @@ -3,7 +3,7 @@ import * as _ from 'lodash';
import { OverviewItem } from '@console/shared';
import { referenceFor, K8sResourceKind } from '@console/internal/module/k8s';
import { ResourceLink, SidebarSectionHeading } from '@console/internal/components/utils';
import { EventingSubscriptionModel } from '../../models';
import { EventingSubscriptionModel, EventingTriggerModel, EventingBrokerModel } from '../../models';

type PubSubResourceOverviewListProps = {
items: K8sResourceKind[];
Expand All @@ -12,9 +12,12 @@ type PubSubResourceOverviewListProps = {

type EventPubSubResourcesProps = {
item: OverviewItem & {
triggers?: K8sResourceKind[];
eventSources?: K8sResourceKind[];
eventingsubscription?: K8sResourceKind[];
connections?: K8sResourceKind[];
pods?: K8sResourceKind[];
deployments?: K8sResourceKind[];
};
};

Expand Down Expand Up @@ -48,18 +51,32 @@ const EventPubSubResources: React.FC<EventPubSubResourcesProps> = ({ item }) =>
ksservices = [],
eventSources = [],
eventingsubscription = [],
triggers = [],
connections = [],
pods = [],
deployments = [],
} = item;

switch (obj.kind) {
case EventingTriggerModel.kind:
case EventingSubscriptionModel.kind:
return <PubSubResourceOverviewList items={connections} title="Connections" />;
case EventingBrokerModel.kind:
return (
<>
<PubSubResourceOverviewList items={ksservices} title="Knative Services" />
<PubSubResourceOverviewList items={eventSources} title="Event Sources" />
<PubSubResourceOverviewList items={triggers} title="Triggers" />
<PubSubResourceOverviewList items={pods} title="Pods" />
<PubSubResourceOverviewList items={deployments} title="Deployments" />
</>
);
default:
return (
<>
<PubSubResourceOverviewList items={ksservices} title="Knative Service" />
<PubSubResourceOverviewList items={eventSources} title="Event Source" />
<PubSubResourceOverviewList items={eventingsubscription} title="Subscription" />
<PubSubResourceOverviewList items={ksservices} title="Knative Services" />
<PubSubResourceOverviewList items={eventSources} title="Event Sources" />
<PubSubResourceOverviewList items={eventingsubscription} title="Subscriptions" />
</>
);
}
Expand Down
Expand Up @@ -6,7 +6,11 @@ import { groupVersionFor, K8sKind, referenceForModel } from '@console/internal/m
import { RootState } from '@console/internal/redux';
import { OverviewItem } from '@console/shared';
import { ModifyApplication } from '@console/dev-console/src/actions/modify-application';
import { KNATIVE_SERVING_APIGROUP, KNATIVE_EVENT_MESSAGE_APIGROUP } from '../../const';
import {
KNATIVE_SERVING_APIGROUP,
KNATIVE_EVENT_MESSAGE_APIGROUP,
KNATIVE_EVENTING_APIGROUP,
} from '../../const';
import { RevisionModel, EventingSubscriptionModel } from '../../models';
import { getRevisionActions } from '../../actions/getRevisionActions';
import {
Expand Down Expand Up @@ -83,6 +87,7 @@ const mapStateToProps = (state: RootState): StateProps => {
.filter(
(model: K8sKind) =>
model.apiGroup === KNATIVE_SERVING_APIGROUP ||
model.apiGroup === KNATIVE_EVENTING_APIGROUP ||
model.apiGroup === KNATIVE_EVENT_MESSAGE_APIGROUP ||
isDynamicEventResourceKind(referenceForModel(model)) ||
isEventingChannelResourceKind(referenceForModel(model)),
Expand Down
Expand Up @@ -2,7 +2,13 @@ import * as React from 'react';
import { OverviewItem } from '@console/shared';
import OperatorBackedOwnerReferences from '@console/internal/components/utils';
import { referenceFor } from '@console/internal/module/k8s';
import { RevisionModel, ServiceModel, EventingSubscriptionModel } from '../../models';
import {
RevisionModel,
ServiceModel,
EventingSubscriptionModel,
EventingTriggerModel,
EventingBrokerModel,
} from '../../models';
import KnativeServiceResources from './KnativeServiceResources';
import KnativeRevisionResources from './KnativeRevisionResources';
import RevisionsOverviewList from './RevisionsOverviewList';
Expand Down Expand Up @@ -40,6 +46,8 @@ const getSidebarResources = (item: OverviewItem) => {
);
case ServiceModel.kind:
return <KnativeServiceResources item={item} />;
case EventingBrokerModel.kind:
case EventingTriggerModel.kind:
case EventingSubscriptionModel.kind:
return <EventPubSubResources item={item} />;
default:
Expand Down
Expand Up @@ -7,6 +7,8 @@ import {
EventSubscriptionObj,
EventIMCObj,
knativeServiceObj,
EventBrokerObj,
EventTriggerObj,
} from '../../../topology/__tests__/topology-knative-test-data';
import EventPubSubResources, { PubSubResourceOverviewList } from '../EventPubSubResources';

Expand Down Expand Up @@ -46,9 +48,27 @@ describe('EventPubSubResources', () => {
wrapper = shallow(<EventPubSubResources item={channelItemData} />);
const findPubSubList = wrapper.find(PubSubResourceOverviewList);
expect(findPubSubList).toHaveLength(3);
expect(findPubSubList.at(0).props().title).toEqual('Knative Service');
expect(findPubSubList.at(1).props().title).toEqual('Event Source');
expect(findPubSubList.at(2).props().title).toEqual('Subscription');
expect(findPubSubList.at(0).props().title).toEqual('Knative Services');
expect(findPubSubList.at(1).props().title).toEqual('Event Sources');
expect(findPubSubList.at(2).props().title).toEqual('Subscriptions');
});

it('should render broker section if the kind is Broker ', () => {
const brokerItemData = {
...itemData,
obj: EventBrokerObj,
ksservices: [knativeServiceObj],
triggers: [EventTriggerObj],
connections: [EventBrokerObj, knativeServiceObj],
};
wrapper = shallow(<EventPubSubResources item={brokerItemData} />);
const findPubSubList = wrapper.find(PubSubResourceOverviewList);
expect(findPubSubList).toHaveLength(5);
expect(findPubSubList.at(0).props().title).toEqual('Knative Services');
expect(findPubSubList.at(1).props().title).toEqual('Event Sources');
expect(findPubSubList.at(2).props().title).toEqual('Triggers');
expect(findPubSubList.at(3).props().title).toEqual('Pods');
expect(findPubSubList.at(4).props().title).toEqual('Deployments');
});
});

Expand Down
1 change: 1 addition & 0 deletions frontend/packages/knative-plugin/src/const.ts
Expand Up @@ -6,6 +6,7 @@ export const FLAG_KNATIVE_SERVING_ROUTE = 'KNATIVE_SERVING_ROUTE';
export const FLAG_KNATIVE_SERVING_SERVICE = 'KNATIVE_SERVING_SERVICE';
export const KNATIVE_SERVING_LABEL = 'serving.knative.dev/service';
export const KNATIVE_SERVING_APIGROUP = 'serving.knative.dev';
export const KNATIVE_EVENTING_APIGROUP = 'eventing.knative.dev';
export const KNATIVE_EVENT_MESSAGE_APIGROUP = 'messaging.knative.dev';
export const KNATIVE_EVENT_SOURCE_APIGROUP_DEP = 'sources.eventing.knative.dev';
export const KNATIVE_EVENT_SOURCE_APIGROUP = 'sources.knative.dev';
29 changes: 29 additions & 0 deletions frontend/packages/knative-plugin/src/models.ts
Expand Up @@ -9,6 +9,7 @@ import {
KNATIVE_EVENT_SOURCE_APIGROUP_DEP,
KNATIVE_SERVING_APIGROUP,
KNATIVE_EVENT_MESSAGE_APIGROUP,
KNATIVE_EVENTING_APIGROUP,
} from './const';

const apiVersion = 'v1';
Expand Down Expand Up @@ -237,3 +238,31 @@ export const EventingChannelModel: K8sKind = {
crd: true,
color: knativeEventingColor.value,
};

export const EventingBrokerModel: K8sKind = {
apiGroup: KNATIVE_EVENTING_APIGROUP,
apiVersion: 'v1beta1',
kind: 'Broker',
label: 'Broker',
labelPlural: 'Brokers',
plural: 'brokers',
id: 'broker',
abbr: 'B',
namespaced: true,
crd: true,
color: knativeEventingColor.value,
};

export const EventingTriggerModel: K8sKind = {
apiGroup: KNATIVE_EVENTING_APIGROUP,
apiVersion: 'v1beta1',
kind: 'Trigger',
label: 'Trigger',
labelPlural: 'Triggers',
plural: 'triggers',
id: 'trigger',
abbr: 'T',
namespaced: true,
crd: true,
color: knativeEventingColor.value,
};

0 comments on commit ffc1732

Please sign in to comment.