Skip to content

Commit

Permalink
Merge pull request #3877 from bipuladh/olm-internal-test
Browse files Browse the repository at this point in the history
Filter out Internal APIs in Installed Operators
  • Loading branch information
openshift-merge-robot committed Jan 23, 2020
2 parents 95ee149 + 4ee8510 commit 9f1009b
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 32 deletions.
Expand Up @@ -81,6 +81,7 @@ import {
SubscriptionState,
} from '../types';
import { subscriptionForCSV, getSubscriptionStatus } from '../status/csv-status';
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 @@ -587,22 +588,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 internalObjects = getInternalObjects(props.csv);
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(internalObjects, 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 @@ -771,24 +782,34 @@ export const ClusterServiceVersionsDetailsPage: React.FC<ClusterServiceVersionsD
props,
) => {
const instancePagesFor = (obj: ClusterServiceVersionKind) => {
const internalObjects = getInternalObjects(obj);
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 @@ -314,10 +315,12 @@ const inFlightStateToProps = ({ k8s }: RootState) => ({
export const ProvidedAPIsPage = connect(inFlightStateToProps)((props: ProvidedAPIsPageProps) => {
const { obj } = props;
const { owned = [] } = obj.spec.customresourcedefinitions;
const internalObjects = getInternalObjects(obj);
const internalAPIs = getInternalAPIReferences(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 @@ -342,7 +345,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
30 changes: 30 additions & 0 deletions frontend/packages/operator-lifecycle-manager/src/utils.ts
@@ -0,0 +1,30 @@
import { ClusterServiceVersionKind, CRDDescription } from './types';
import { referenceForProvidedAPI } from './components';

export const getInternalObjects = (csv: ClusterServiceVersionKind) => {
const internals: string =
csv?.metadata?.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 = (csv: ClusterServiceVersionKind): string[] => {
const owned: CRDDescription[] = csv?.spec?.customresourcedefinitions?.owned || [];
const internalObjects = getInternalObjects(csv);
return owned.reduce(
(acc, obj) =>
isInternalObject(internalObjects, obj.name) ? [referenceForProvidedAPI(obj), ...acc] : acc,
[],
);
};

0 comments on commit 9f1009b

Please sign in to comment.