Skip to content

Commit

Permalink
fix(dev-catalog): reject the internal objects when creating objects o…
Browse files Browse the repository at this point in the history
…ut from CSV
  • Loading branch information
abhinandan13jan committed Dec 3, 2019
1 parent 82b4695 commit 0dcaf8a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
18 changes: 18 additions & 0 deletions frontend/packages/operator-lifecycle-manager/src/dev-catalog.ts
Expand Up @@ -4,6 +4,22 @@ import { ClusterServiceVersionKind } from './types';
import { referenceForProvidedAPI, providedAPIsFor } from './components';
import * as operatorLogo from './operator.svg';

const isInternal = (crd: { name: string }): boolean => {
const internalOpListString = _.get(
crd,
['csv', 'metadata', 'annotations', 'operators.operatorframework.io/internal-objects'],
'[]',
);
try {
const internalOpList = internalOpListString.slice(1, -1).split(','); // JSON.parse fails or returns improper structure
if (!internalOpList.length || internalOpList.length === 0) return false;
return !!internalOpList.find((op) => op.slice(1, -1) === crd.name);
} catch {
/* eslint-disable-next-line no-console */
console.error('Failed to parse CSV annotation: Invalid JSON structure');
return false;
}
};
export const normalizeClusterServiceVersions = (
clusterServiceVersions: ClusterServiceVersionKind[],
): K8sResourceKind[] => {
Expand All @@ -24,6 +40,8 @@ export const normalizeClusterServiceVersions = (
: all.concat([cur]),
[],
)
// remove internal CRDs
.filter((crd) => !isInternal(crd))
.map((desc) => ({
// NOTE: Faking a real k8s object to avoid fetching all CRDs
obj: {
Expand Down
10 changes: 1 addition & 9 deletions frontend/public/components/catalog/catalog-page.tsx
Expand Up @@ -114,15 +114,7 @@ export class CatalogListPage extends React.Component<CatalogListPageProps, Catal
...projectTemplateItems,
];

//blacklisting all CRDs with annotation 'operators.operatorframework.io/internal-object' set to true
const filteredItems = _.reject(items, [
'obj',
'metadata',
'annotations',
'operators.operatorframework.io/internal-object',
]);

return _.sortBy(filteredItems, 'tileName');
return _.sortBy(items, 'tileName');
}

normalizeClusterServiceClasses(serviceClasses) {
Expand Down

0 comments on commit 0dcaf8a

Please sign in to comment.