-
Notifications
You must be signed in to change notification settings - Fork 24
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
Use getTemplateVirtualMachineObject in template utils #678
Use getTemplateVirtualMachineObject in template utils #678
Conversation
/lgtm nice ! |
/retest |
/retest-required Please review the full test history for this PR and help us cut down flakes. |
|
||
export const getTemplateProviderName = (template: V1Template): string => | ||
getAnnotation(template, ANNOTATIONS.providerName, null) || | ||
getAnnotation(template, ANNOTATIONS.providerDisplayName, null); | ||
|
||
export const getTemplateWorkload = (template: V1Template): WORKLOADS => | ||
template?.objects[0]?.spec?.template?.metadata?.annotations?.[VM_WORKLOAD_ANNOTATION]; | ||
export const getTemplateWorkload = (template: V1Template): string => |
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 getTemplateWorkload = (template: V1Template): string => | |
export const getTemplateWorkload = (template: V1Template): WORKLOADS => |
you should not change the signature of a common lib method
( if you do, you need to go over the code and make sure it's ok )
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 changed that because it didn't work, compilation was failing which is obvious if you think deeper about the change we did here. Tried many things and wasn't able to use the better type. But I haven't tried the force cast yet...
/retest-required Please review the full test history for this PR and help us cut down flakes. |
e5a836d
to
de61088
Compare
getTemplateVirtualMachineObject(template)?.spec?.template?.metadata?.annotations?.[ | ||
VM_WORKLOAD_ANNOTATION | ||
] as WORKLOADS; |
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.
getTemplateVirtualMachineObject(template)?.spec?.template?.metadata?.annotations?.[ | |
VM_WORKLOAD_ANNOTATION | |
] as WORKLOADS; | |
{ | |
const workload = getTemplateVirtualMachineObject(template)?.spec?.template?.metadata?.annotations?.[ | |
VM_WORKLOAD_ANNOTATION | |
]; | |
return workload in WORKLOADS ? workload as WORKLOADS : null; | |
} |
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'd prefer the actual version, as it is shorter and self explanatory enough. Returns undefined if other workload profile than one of the three values present, and then "Other" is displayed 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.
Returns
undefined
if other workload
can you check, as
does not check the value is actually a workload [1].
another option to force WORKLOADS
is to do
return WORKLOADS[workload as WORKLOADS]
[1] https://www.typescriptlang.org/docs/handbook/2/everyday-types.html#type-assertions
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.
Okay. And so this leads me to ask about the correct behavior for editing workload profile:
What do we want to display in the Edit Workload profile modal, if there is other workload profile, other than one of those 3, present in the template's yaml? (I can create such a template easily, when editing the yaml when creating a template)
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.
we currently do 'Other', which is fine ...
do you think showing the verbatim value from the yaml makes more sense ?
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 it "not nice"? What does it mean? TS is fine with that. The return value is a string which is what we want, plus WORKLOADS is giving an extra and useful information for the other developers about what we expect there in most of the cases.
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 it "not nice"?
it's not correct, it will create a variable with type A
but the value will be of type B
, this is not correct,
types are used to help you assert that the value is of a type, if you use as
without checking the value
you break the typing mechanism.
for example:
enum WORKLOADS {
desktop = 'desktop',
server = 'server',
highperformance = 'highperformance',
}
const a = 'hi'
const b = 'desktop'
const returnsWorlads = (input: string): WORKLOADS => input as WORKLOADS;
const aWorkload: WORKLOADS = returnsWorlads(a);
// do something that assume aWorkload is of type WORKLOADS
// and it may crash or not depending on the input
console.log( returnsWorlads(aWorkload) ) // hi
const bWorkload: WORKLOADS = returnsWorlads(b);
// do something that assume aWorkload is of type WORKLOADS
// and it may crash or not depending on the input
console.log( returnsWorlads(bWorkload) ) // desktop
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 it works like that and IMO this is the behavior we want here now. I don't see here any conflict with what I've written earlier.
Btw, originally, at the beginning of this conversation, there was string
return type, but you didn't like 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.
there was string return type, but you didn't like it...
:-) i liked it, but the tests failed
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.
The tests failed because I forgot to change type to string in some related places, but you had a problem with not using WORKLOADS type, originally.
de61088
to
1e278e1
Compare
1e278e1
to
4baeee2
Compare
Use getTemplateVirtualMachineObject function to get the VM object where needed, instead of hardcoced template.objects[0].
4baeee2
to
9e89b60
Compare
/lgtm |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: hstastna, yaacov 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 |
@hstastna: The following test failed, say
Full PR test history. Your PR dashboard. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. I understand the commands that are listed here. |
📝 Description
This is a small refactoring PR related to:
using
getTemplateVirtualMachineObject
function to get the VM object where needed, instead of hardcocedtemplate.objects[0]
, in the template utils/selectors.