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

Filter out Internal APIs in Installed Operators #3877

Merged
merged 1 commit into from
Jan 23, 2020
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
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(
spadgett marked this conversation as resolved.
Show resolved Hide resolved
(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(
Copy link
Contributor

Choose a reason for hiding this comment

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

Based on my comment above:

providedAPIsFor(obj)
  .filter((desc) => !isInternalObject(internalObjects, desc.name))
  .map((desc) => ({
    href: referenceForProvidedAPI(desc),
    name: desc.displayName,
    component: React.memo(
      () => (
        <ProvidedAPIPage
          csv={obj}
          kind={referenceForProvidedAPI(desc)}
          namespace={obj.metadata.namespace}
        />
      ),
      _.isEqual,
    ),
  }));

(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,
bipuladh marked this conversation as resolved.
Show resolved Hide resolved
),
},
...acc,
]
: acc,
[],
),
);
};
type ExtraResources = { subscriptions: SubscriptionKind[] };
Expand Down
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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);
spadgett marked this conversation as resolved.
Show resolved Hide resolved
} 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,
[],
);
};