From f875e8c752105b9da4a8d2ab86e962e4bf7e0137 Mon Sep 17 00:00:00 2001 From: Thuan Vo Date: Tue, 9 Jul 2024 15:28:57 -0700 Subject: [PATCH 1/3] fix: consider apiVersion when getting example yaml for crds Solves #56. When getting example YAMLs for CRDs, apiVersion should be considered in cases where a CRD is shipped with >= 2 versions. Signed-off-by: Thuan Vo --- frontend/src/utils/operatorTypes.ts | 1 + frontend/src/utils/operatorUtils.ts | 15 +++++++++++---- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/frontend/src/utils/operatorTypes.ts b/frontend/src/utils/operatorTypes.ts index abc7ace..53a5458 100644 --- a/frontend/src/utils/operatorTypes.ts +++ b/frontend/src/utils/operatorTypes.ts @@ -198,6 +198,7 @@ export type NormalizedOperatorChannel = { export type NormalizedCrdPreview = { name: string kind: string + version: string displayName: string description: string yamlExample: object | null diff --git a/frontend/src/utils/operatorUtils.ts b/frontend/src/utils/operatorUtils.ts index 6078f17..13ce5db 100644 --- a/frontend/src/utils/operatorUtils.ts +++ b/frontend/src/utils/operatorUtils.ts @@ -40,7 +40,7 @@ const normalizeCapabilityLevel = (capability: string) => { /** * Search for deployment example by kind */ -const getExampleYAML = (kind: string, operator: operatorTypes.Operator): object | null => { +const getExampleYAML = (kind: string, version: string, operator: operatorTypes.Operator): object | null => { const examples = _.get(operator, 'metadata.annotations.alm-examples'); if (!examples) { return null; @@ -53,7 +53,13 @@ const getExampleYAML = (kind: string, operator: operatorTypes.Operator): object yamlExamples = JSON.parse(examples); } - return _.find(yamlExamples, { kind }); + return _.find(yamlExamples, (resource) => { + const apiVersionSplit = resource.apiVersion?.split('/'); + if (apiVersionSplit.length > 2) { + throw new Error("Example resource YAML has invalid apiVersion.") + } + return resource?.kind === kind && (apiVersionSplit.length === 2? apiVersionSplit[1]: resource.apiVersion) === version; + }); } catch (e) { return null; } @@ -75,12 +81,13 @@ export const mergeDescriptions = (operator: operatorTypes.Operator) => { -const normalizeCRD = (crd: operatorTypes.CustomResourceFile, operator: operatorTypes.Operator): operatorTypes.NormalizedCrdPreview => ({ +const normalizeCRD = (crd: operatorTypes.OperatorOwnedCrd, operator: operatorTypes.Operator): operatorTypes.NormalizedCrdPreview => ({ name: _.get(crd, 'name', 'Name Not Available'), kind: crd.kind, + version: crd.version, displayName: _.get(crd, 'displayName', 'Name Not Available'), description: _.get(crd, 'description', 'No description available'), - yamlExample: getExampleYAML(crd.kind, operator) + yamlExample: getExampleYAML(crd.kind, crd.version, operator) }); const normalizeCRDs = (operator: operatorTypes.Operator) => { From f49e8b3ee1d37ad88719dd49513d6c667dfa7ce9 Mon Sep 17 00:00:00 2001 From: Thuan Vo Date: Tue, 9 Jul 2024 16:17:28 -0700 Subject: [PATCH 2/3] feat: display version next to crd name Signed-off-by: Thuan Vo --- frontend/src/components/CustomResourceDefinitionsView.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/src/components/CustomResourceDefinitionsView.tsx b/frontend/src/components/CustomResourceDefinitionsView.tsx index 0cda15c..2f4b65b 100644 --- a/frontend/src/components/CustomResourceDefinitionsView.tsx +++ b/frontend/src/components/CustomResourceDefinitionsView.tsx @@ -28,7 +28,7 @@ const CustomResourceDefinitionsView: React.FC {customResourceDefinitions.map(crd => (
-
{crd.displayName}
+
{crd.displayName} ({crd.version})
{crd.description}
{showExamples && ( From 6579c21825bb0413f1f87aed047846c129a6902a Mon Sep 17 00:00:00 2001 From: Thuan Vo Date: Tue, 9 Jul 2024 16:17:42 -0700 Subject: [PATCH 3/3] chore: apply lint fixes Signed-off-by: Thuan Vo --- frontend/src/components/editor/BundleDownloader.js | 5 +---- frontend/src/components/editor/RulesEditor.js | 12 ++++++++++-- frontend/src/pages/operatorHub/OperatorHub.js | 7 ++----- 3 files changed, 13 insertions(+), 11 deletions(-) diff --git a/frontend/src/components/editor/BundleDownloader.js b/frontend/src/components/editor/BundleDownloader.js index 9649fb3..3146f60 100644 --- a/frontend/src/components/editor/BundleDownloader.js +++ b/frontend/src/components/editor/BundleDownloader.js @@ -259,7 +259,4 @@ const mapStateToProps = state => ({ operatorPackage: state.editorState.operatorPackage }); -export default connect( - mapStateToProps, - mapDispatchToProps -)(OperatorBundleDownloader); +export default connect(mapStateToProps, mapDispatchToProps)(OperatorBundleDownloader); diff --git a/frontend/src/components/editor/RulesEditor.js b/frontend/src/components/editor/RulesEditor.js index f23628b..7d11ada 100755 --- a/frontend/src/components/editor/RulesEditor.js +++ b/frontend/src/components/editor/RulesEditor.js @@ -83,10 +83,18 @@ class RulesEditor extends React.Component { if (selections.includes('*') && selections.length > 1) { const prevSelections = _.get(rule, field); if (prevSelections.includes('*')) { - this.updateRule(rule, field, _.filter(selections, selection => selection !== '*')); + this.updateRule( + rule, + field, + _.filter(selections, selection => selection !== '*') + ); return; } - this.updateRule(rule, field, _.filter(selections, selection => selection === '*')); + this.updateRule( + rule, + field, + _.filter(selections, selection => selection === '*') + ); return; } diff --git a/frontend/src/pages/operatorHub/OperatorHub.js b/frontend/src/pages/operatorHub/OperatorHub.js index c696659..48971ab 100755 --- a/frontend/src/pages/operatorHub/OperatorHub.js +++ b/frontend/src/pages/operatorHub/OperatorHub.js @@ -612,7 +612,7 @@ class OperatorHub extends React.Component { {_.map(this.sortCategories(categories), category => (
{category === selectedCategory && (