From 295b94f284925dcadb2825921365469cd8bdfd95 Mon Sep 17 00:00:00 2001
From: Abhi <abhinandan13jan@gmail.com>
Date: Thu, 21 Nov 2019 18:46:16 +0530
Subject: [PATCH 1/2] fix(dev-catalog): reject the internal objects when
 creating objects out from CSV

---
 .../src/dev-catalog.ts                         | 18 ++++++++++++++++++
 .../public/components/catalog/catalog-page.tsx | 10 +---------
 2 files changed, 19 insertions(+), 9 deletions(-)

diff --git a/frontend/packages/operator-lifecycle-manager/src/dev-catalog.ts b/frontend/packages/operator-lifecycle-manager/src/dev-catalog.ts
index e13c1ac035c..2992402d52c 100644
--- a/frontend/packages/operator-lifecycle-manager/src/dev-catalog.ts
+++ b/frontend/packages/operator-lifecycle-manager/src/dev-catalog.ts
@@ -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 = JSON.parse(internalOpListString); // JSON.parse fails if incorrect annotation structure
+    if (!Array.isArray(internalOpList) || internalOpList.length === 0) return false;
+    return internalOpList.some((op) => op === 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[] => {
@@ -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: {
diff --git a/frontend/public/components/catalog/catalog-page.tsx b/frontend/public/components/catalog/catalog-page.tsx
index a4bf0101e97..8206787804c 100644
--- a/frontend/public/components/catalog/catalog-page.tsx
+++ b/frontend/public/components/catalog/catalog-page.tsx
@@ -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) {

From d2dcbf0e4aaf3bdaa06766a170ab1a096ff921e3 Mon Sep 17 00:00:00 2001
From: Abhinandan Das <abhinandan13jan@gmail.com>
Date: Fri, 6 Dec 2019 12:51:22 +0530
Subject: [PATCH 2/2] Update
 frontend/packages/operator-lifecycle-manager/src/dev-catalog.ts

Co-Authored-By: Jon Jackson <jonjacks@redhat.com>
---
 frontend/packages/operator-lifecycle-manager/src/dev-catalog.ts | 1 -
 1 file changed, 1 deletion(-)

diff --git a/frontend/packages/operator-lifecycle-manager/src/dev-catalog.ts b/frontend/packages/operator-lifecycle-manager/src/dev-catalog.ts
index 2992402d52c..3a41173e707 100644
--- a/frontend/packages/operator-lifecycle-manager/src/dev-catalog.ts
+++ b/frontend/packages/operator-lifecycle-manager/src/dev-catalog.ts
@@ -12,7 +12,6 @@ const isInternal = (crd: { name: string }): boolean => {
   );
   try {
     const internalOpList = JSON.parse(internalOpListString); // JSON.parse fails if incorrect annotation structure
-    if (!Array.isArray(internalOpList) || internalOpList.length === 0) return false;
     return internalOpList.some((op) => op === crd.name);
   } catch {
     /* eslint-disable-next-line no-console */