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

fix: consider apiVersion when getting example yaml for crds #60

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion frontend/src/components/CustomResourceDefinitionsView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const CustomResourceDefinitionsView: React.FC<CustomResourceDefinitionsViewProps
<div className="oh-crd-tile-view">
{customResourceDefinitions.map(crd => (
<div className="oh-crd-tile" key={crd.name}>
<div className="oh-crd-tile__title">{crd.displayName}</div>
<div className="oh-crd-tile__title">{crd.displayName} ({crd.version})</div>
<div className="oh-crd-tile__rule" />
<div className="oh-crd-tile__description">{crd.description}</div>
{showExamples && (
Expand Down
5 changes: 1 addition & 4 deletions frontend/src/components/editor/BundleDownloader.js
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,4 @@ const mapStateToProps = state => ({
operatorPackage: state.editorState.operatorPackage
});

export default connect(
mapStateToProps,
mapDispatchToProps
)(OperatorBundleDownloader);
export default connect(mapStateToProps, mapDispatchToProps)(OperatorBundleDownloader);
12 changes: 10 additions & 2 deletions frontend/src/components/editor/RulesEditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
7 changes: 2 additions & 5 deletions frontend/src/pages/operatorHub/OperatorHub.js
Original file line number Diff line number Diff line change
Expand Up @@ -612,7 +612,7 @@ class OperatorHub extends React.Component {
{_.map(this.sortCategories(categories), category => (
<div key={category} className={`oh-category-item ${category === selectedCategory ? 'selected' : ''}`}>
<button className="oh-category-item__select" onClick={e => this.categorySelect(e, category)}>
{category.length == 0 ? 'All' : category}
{category.length === 0 ? 'All' : category}
</button>
{category === selectedCategory && (
<button className="oh-category-item__deselect" onClick={e => this.categorySelect(e, '')}>
Expand Down Expand Up @@ -890,7 +890,4 @@ const mapStateToProps = state => ({
...state.viewState
});

export default connect(
mapStateToProps,
mapDispatchToProps
)(OperatorHub);
export default connect(mapStateToProps, mapDispatchToProps)(OperatorHub);
1 change: 1 addition & 0 deletions frontend/src/utils/operatorTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ export type NormalizedOperatorChannel = {
export type NormalizedCrdPreview = {
name: string
kind: string
version: string
displayName: string
description: string
yamlExample: object | null
Expand Down
15 changes: 11 additions & 4 deletions frontend/src/utils/operatorUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}
Expand All @@ -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) => {
Expand Down