Skip to content

Commit

Permalink
Added filter for internal objects in Installed Operators
Browse files Browse the repository at this point in the history
  • Loading branch information
bipuladh committed Jan 14, 2020
1 parent 28cfe3b commit 50c8811
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 32 deletions.
Expand Up @@ -81,6 +81,7 @@ import {
SubscriptionKind,
SubscriptionState,
} from '../types';
import { getInternalObjects, isInternalObject } from '../utils';
import { ProvidedAPIsPage, ProvidedAPIPage } from './operand';
import { createUninstallOperatorModal } from './modals/uninstall-operator-modal';
import { operatorGroupFor, operatorNamespaceFor } from './operator-group';
Expand Down Expand Up @@ -611,22 +612,32 @@ const crdCardRowStateToProps = ({ k8s }, { crdDescs }) => {
};
};

export const CRDCardRow = connect(crdCardRowStateToProps)((props: CRDCardRowProps) => (
<div className="co-crd-card-row">
{_.isEmpty(props.crdDescs) ? (
<span className="text-muted">No Kubernetes APIs are being provided by this Operator.</span>
) : (
props.crdDescs.map((desc) => (
<CRDCard
key={referenceForProvidedAPI(desc)}
crd={desc}
csv={props.csv}
canCreate={props.createable.includes(referenceForProvidedAPI(desc))}
/>
))
)}
</div>
));
export const CRDCardRow = connect(crdCardRowStateToProps)((props: CRDCardRowProps) => {
const internals = getInternalObjects(props.csv.metadata.annotations);
return (
<div className="co-crd-card-row">
{_.isEmpty(props.crdDescs) ? (
<span className="text-muted">No Kubernetes APIs are being provided by this Operator.</span>
) : (
props.crdDescs.reduce(
(acc, desc) =>
!isInternalObject(internals, desc.name)
? [
...acc,
<CRDCard
key={referenceForProvidedAPI(desc)}
crd={desc}
csv={props.csv}
canCreate={props.createable.includes(referenceForProvidedAPI(desc))}
/>,
]
: acc,
[],
)
)}
</div>
);
});

export const ClusterServiceVersionDetails: React.SFC<ClusterServiceVersionDetailsProps> = (
props,
Expand Down Expand Up @@ -795,24 +806,34 @@ export const ClusterServiceVersionsDetailsPage: React.FC<ClusterServiceVersionsD
props,
) => {
const instancePagesFor = (obj: ClusterServiceVersionKind) => {
const internalObjects = getInternalObjects(_.get(obj, 'metadata.annotations'));
return (providedAPIsFor(obj).length > 1
? [{ href: 'instances', name: 'All Instances', component: ProvidedAPIsPage }]
: ([] as Page[])
).concat(
providedAPIsFor(obj).map((desc: CRDDescription) => ({
href: referenceForProvidedAPI(desc),
name: desc.displayName,
component: React.memo(
() => (
<ProvidedAPIPage
csv={obj}
kind={referenceForProvidedAPI(desc)}
namespace={obj.metadata.namespace}
/>
),
_.isEqual,
),
})),
providedAPIsFor(obj).reduce(
(acc, desc: CRDDescription) =>
!isInternalObject(internalObjects, desc.name)
? [
{
href: referenceForProvidedAPI(desc),
name: desc.displayName,
component: React.memo(
() => (
<ProvidedAPIPage
csv={obj}
kind={referenceForProvidedAPI(desc)}
namespace={obj.metadata.namespace}
/>
),
_.isEqual,
),
},
...acc,
]
: acc,
[],
),
);
};
type ExtraResources = { subscriptions: SubscriptionKind[] };
Expand Down
Expand Up @@ -47,6 +47,7 @@ import { RootState } from '@console/internal/redux';
import * as plugins from '@console/internal/plugins';
import { ClusterServiceVersionModel } from '../models';
import { ClusterServiceVersionKind } from '../types';
import { isInternalObject, getInternalAPIReferences, getInternalObjects } from '../utils';
import { StatusDescriptor } from './descriptors/status';
import { SpecDescriptor } from './descriptors/spec';
import { StatusCapability, Descriptor } from './descriptors/types';
Expand Down Expand Up @@ -251,10 +252,12 @@ const inFlightStateToProps = ({ k8s }: RootState) => ({
export const ProvidedAPIsPage = connect(inFlightStateToProps)((props: ProvidedAPIsPageProps) => {
const { obj } = props;
const { owned = [] } = obj.spec.customresourcedefinitions;
const internalObjects = getInternalObjects(obj.metadata.annotations);
const internalAPIs = getInternalAPIReferences(obj.metadata.annotations, obj);
const firehoseResources = owned.reduce((resources, desc) => {
const reference = referenceForProvidedAPI(desc);
const model = modelFor(reference);
return model
return model && !internalAPIs.some((api) => api === reference)
? [
...resources,
{
Expand All @@ -279,7 +282,13 @@ export const ProvidedAPIsPage = connect(inFlightStateToProps)((props: ProvidedAP
const createProps =
owned.length > 1
? {
items: owned.reduce((acc, crd) => ({ ...acc, [crd.name]: crd.displayName }), {}),
items: owned.reduce(
(acc, crd) =>
!isInternalObject(internalObjects, crd.name)
? { ...acc, [crd.name]: crd.displayName }
: acc,
{},
),
createLink,
}
: { to: owned.length === 1 ? createLink(owned[0].name) : null };
Expand Down
34 changes: 34 additions & 0 deletions frontend/packages/operator-lifecycle-manager/src/utils.ts
@@ -0,0 +1,34 @@
import * as _ from 'lodash';
import { ObjectMetadata } from '@console/internal/module/k8s';
import { ClusterServiceVersionKind } from './types';
import { referenceForProvidedAPI } from './components';

export const getInternalObjects = (annotations: ObjectMetadata['annotations']): string[] => {
const internals: string = _.get(annotations, 'operators.operatorframework.io/internal-objects');
if (!internals) {
return [];
}
try {
return JSON.parse(internals);
} catch (e) {
// eslint-disable-next-line no-console
console.error('Error parsing internal object annotation.', e);
return [];
}
};

export const isInternalObject = (internalObjects: string[], objectName: string): boolean =>
internalObjects.some((obj) => obj === objectName);

export const getInternalAPIReferences = (
annotations: ObjectMetadata['annotations'],
csv: ClusterServiceVersionKind,
): string[] => {
const { owned } = csv.spec.customresourcedefinitions;
const internalObjects = getInternalObjects(annotations);
return owned.reduce(
(acc, obj) =>
isInternalObject(internalObjects, obj.name) ? [referenceForProvidedAPI(obj), ...acc] : acc,
[],
);
};

0 comments on commit 50c8811

Please sign in to comment.