-
Notifications
You must be signed in to change notification settings - Fork 615
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3877 from bipuladh/olm-internal-test
Filter out Internal APIs in Installed Operators
- Loading branch information
Showing
3 changed files
with
92 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} 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, | ||
[], | ||
); | ||
}; |