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
Show csv icon in topology for operator backed services #3787
Show csv icon in topology for operator backed services #3787
Conversation
2ad0848
to
730dfc6
Compare
/assign @christianvogt |
|
||
export const getImageForCSVIcon = (csv) => | ||
_.get(csv, 'spec.icon') | ||
? `data:${_.get(csv, 'spec.icon', [])[0].mediatype};base64,${ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
assigning default as []
so in case of default it may break as [0]
would be undefined
and we would access mediatype
on that
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
expect((topologyTransformedData[keys[0]].data as WorkloadData).builderImage).toBe(nodejsIcon); | ||
}); | ||
|
||
it('should return builder image icon for nodejs', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: it would be good to use different description in it
block for this one and above
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, that was because of copy paste job. Updated the description.
@@ -23,4 +23,8 @@ export type OverviewItem<T = K8sResourceKind> = { | |||
revisions?: K8sResourceKind[]; | |||
}; | |||
|
|||
export type OperatorBackedServiceKindMap = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this in shared?
Seems very specific to topology.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Its being used by knative-plugin
as well that's why I had to add it to console-shared
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But knative-plugin depends on dev-console for contributing to topology.
You should be enhancing the TopologyDataObject
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is not actually part of TopologyDataObject
. So, moved the type definition to topology-types.ts
file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right. I misread where it was. But topology-types.ts
is a better home for it.
import * as operatorLogo from '../images/operator.svg'; | ||
|
||
export const getImageForCSVIcon = (csv) => | ||
_.get(csv, 'spec.icon') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of using get
at three places, probably store it as a const
. And to address what Jai said you can do this or something similar
const icon = _.get(csv, 'spec.icon', []);
!_.isEmpty(icon) ? `data:${icon[0].mediatype};base64,${icon[0].base64data}` : operatorLogo
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
f35946a
to
67f8373
Compare
/retest |
67f8373
to
b0fa8d8
Compare
/retest |
@@ -0,0 +1 @@ | |||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 258.51 258.51"><defs><style>.cls-1{fill:#d1d1d1;}.cls-2{fill:#8d8d8f;}</style></defs><title>Asset 4</title><g id="Layer_2" data-name="Layer 2"><g id="Layer_1-2" data-name="Layer 1"><path class="cls-1" d="M129.25,20A109.1,109.1,0,0,1,206.4,206.4,109.1,109.1,0,1,1,52.11,52.11,108.45,108.45,0,0,1,129.25,20m0-20h0C58.16,0,0,58.16,0,129.25H0c0,71.09,58.16,129.26,129.25,129.26h0c71.09,0,129.26-58.17,129.26-129.26h0C258.51,58.16,200.34,0,129.25,0Z"/><path class="cls-2" d="M177.54,103.41H141.66L154.9,65.76c1.25-4.4-2.33-8.76-7.21-8.76H102.93a7.32,7.32,0,0,0-7.4,6l-10,69.61c-.59,4.17,2.89,7.89,7.4,7.89h36.9L115.55,197c-1.12,4.41,2.48,8.55,7.24,8.55a7.58,7.58,0,0,0,6.47-3.48L184,113.85C186.86,109.24,183.29,103.41,177.54,103.41Z"/></g></g></svg> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are 2 other instances of what looks to be the same file:
- public/imgs
- packages/operator-lifecycle-management/src
Can we consolidate and settle on a single instance.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have another PR that touches the same area. That's why I didn't make changes there, I plan to do that in another PR. Or if the other PR gets in first I can add that change in this one.
import * as operatorLogo from '../images/operator.svg'; | ||
|
||
export const getImageForCSVIcon = (csv) => { | ||
const icon = _.get(csv, 'spec.icon', []); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FWIW, I think you can do this now:
const icon = _.get(csv, 'spec.icon', []); | |
const icon = csv?.spec?.icon || []; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the suggestion. I was not aware that typescript has been upgraded in console.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, we also need to update prettier to be able to use this feature.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah interesting, I turned off my watcher for my review version of OpenShift... does it to something crazy?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Its throwing an error saying expression expected
after the ?.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmmm ... I didn't see any inline eslint errors when I wrote it :/ ah well, maybe for a future time then.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now, i've broken eslint-prettier-plugin
trying to update prettier
. Should look at this in another PR. I can raise one after this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't bother with it. There's already a PR up to upgrade eslint. We cannot use the feature yet.
import * as _ from 'lodash'; | ||
import * as operatorLogo from '../images/operator.svg'; | ||
|
||
export const getImageForCSVIcon = (csv) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Type csv? It's a K8sResourceKind
in your tests, is there a definition shared we can use? Something like ClusterServiceVersionKind
? Can we import from the operator-lifecycle-manager
? Is this the right type?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that is the correct type. Updated it..
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So after talking to Christian, he suggests we do not make this dependency. It pollutes what the shared
package is trying to do. So in order to keep this, he suggested putting it into dev-console
. Does that seem viable?
@@ -125,25 +131,33 @@ export const createTopologyNodeData = ( | |||
const deploymentsLabels = _.get(deploymentConfig, 'metadata.labels', {}); | |||
const deploymentsAnnotations = _.get(deploymentConfig, 'metadata.annotations', {}); | |||
const nodeResourceKind = _.get(deploymentConfig, 'metadata.ownerReferences[0].kind'); | |||
const operatorBackedService = nodeResourceKind in operatorBackedServiceKindMap; | |||
const getNodeIcon = () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any reason this was made a function? Seems like it's only used once and lazy computing isn't helping in this case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No specific reason for making it a function. Just didn't want to write a big ternary operator expression.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think you need to go to either extreme... you can just create the variables inline (instead of wrapped in a function) and just use the result from the return
in the spot where you call it now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated.
); | ||
}); | ||
operatorBackedServiceKindMap = installedOperators.reduce((kindMap, csv) => { | ||
_.get(csv, 'spec.customresourcedefinitions.owned').forEach((crd) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there any concern that an installed operator would not have CRDs? Is this somehow guaranteed by the spec never to be missing?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Based on the Operator SDK - https://github.com/operator-framework/operator-sdk#workflow, there can be operators which do not provide any CRDs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess my question is more about your _.get
doesn't handle a fallback if it is missing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But, I am yet to find an operator from OperatorHub which is not providing any APIs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suppose I am being overly cautious... defaulting it to an array saves us from a NPE if it happens. 🤷♂ It probably isn't needed one way or the other though. Just a recommendation for being "defensive" in programming.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added default array. It's good to be cautious. :)
8d806a9
to
18fe2e2
Compare
export const getImageForCSVIcon = (csv: ClusterServiceVersionKind) => { | ||
const icon: ClusterServiceVersionIcon = _.get(csv, 'spec.icon', []); | ||
return !_.isEmpty(icon) ? `data:${icon[0].mediatype};base64,${icon[0].base64data}` : operatorLogo; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Importing '@console/operator-lifecycle-manager'
from @console-shared
is bad.
To remove this dependency, perhaps you type the param as much simpler type to match the CSV icon:
type Icon = { base64data: string; mediatype: string };
export const getOperatorIcon = (icon: Icon[]) => {
/kind feature |
18fe2e2
to
76630c2
Compare
/hold |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just some weirdness with the API
|
||
type CSVIcon = { base64data: string; mediatype: string }; | ||
|
||
export const getImageForCSVIcon = (icon: CSVIcon[]) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
export const getImageForCSVIcon = (icon: CSVIcon[]) => { | |
export const getImageForCSVIcons = (icons: CSVIcon[]) => { |
More importantly, why are you passing an array only to grab the first one?
|
||
const csvIcon = | ||
operatorBackedService && | ||
getImageForCSVIcon(_.get(operatorBackedServiceKindMap[nodeResourceKind], 'spec.icon', [])); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Per my other comment ... Perhaps [0]
here to simplify the utility api?
/hold cancel |
@rohitkrai03 needs rebase. |
@andrewballantyne Yeah, this was because of circular dependency. I encountered this on Friday and reverted back the OLM package changes. But seems like I forgot to force push the changes. SHould work now. I've updated the PR. |
0799c6a
to
c9e0007
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/lgtm
I don't have the powers to give the approve label in olm and shared, so @christianvogt will have to weigh in there. But looks good to me.
const mockCSV = _.cloneDeep(sampleClusterServiceVersions.data[0]); | ||
const icon = _.get(mockCSV, 'spec.icon.0'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You don't need topology test data for this unit test.
Please update to use an object that matches type CSVIcon
.
Looks like there is a topology specific test added later on that captures this same data flow.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
c9e0007
to
0ac5c00
Compare
0ac5c00
to
f1b1375
Compare
/lgtm |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: andrewballantyne, christianvogt, rohitkrai03 The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
/retest Please review the full test history for this PR and help us cut down flakes. |
6 similar comments
/retest Please review the full test history for this PR and help us cut down flakes. |
/retest Please review the full test history for this PR and help us cut down flakes. |
/retest Please review the full test history for this PR and help us cut down flakes. |
/retest Please review the full test history for this PR and help us cut down flakes. |
/retest Please review the full test history for this PR and help us cut down flakes. |
/retest Please review the full test history for this PR and help us cut down flakes. |
Jira Issue - https://issues.redhat.com/browse/ODC-2455
This PR -
Screenshot @openshift/team-devconsole-ux -