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
refactor + fix: Cleanup proxy bundle #526
Conversation
/cc @codingben @0xFelix |
e6aae63
to
8ce3734
Compare
@akrejcir IMHO it's code E.g. |
o, err := yamlv2.Marshal(&obj) | ||
if err != nil { | ||
return err | ||
func validateBundle(bundle *Bundle) error { |
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 think validateBundle
it's too general naming and validateBundleObjects
would be better.
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 disagree. It validates that the Bundle
struct is correct and can be used.
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, but it didn't mention what kind of validation it does. Maybe validateBundleParameters
.
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 is only one function that does validation on Bundle
, so it does all the validation. IMHO it's not needed to be more specific. If there would be multiple functions, then yes.
} | ||
} | ||
err = runtime.DefaultUnstructuredConverter.FromUnstructured(obj.UnstructuredContent(), destObj) | ||
if err != nil { |
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.
What about make it shorter:
if err := runtime.DefaultUnstructuredConverter.FromUnstructured(obj.UnstructuredContent(), destObj); err != nil {
return nil, err
}
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 line is already quite long. I prefer it this way.
for { | ||
obj := &unstructured.Unstructured{} | ||
err := decoder.Decode(&obj) | ||
if err == io.EOF { |
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.
If you like it:
if err := decoder.Decode(&obj); err == io.EOF {
return bundle, nil
}
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 err
is checked multiple times, and this change would limit its scope only to the inside of the if
statement.
9de100c
to
9ccb818
Compare
/retest |
1 similar comment
/retest |
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 it really necessary to "half-hardcode" the expected bundle resources into the operand and then to load their values from the bundle YAML? Can't we either define the resources completely in code or load them just from the YAML?
@@ -91,3 +99,29 @@ func loadBundleFromBytes(data []byte) (*Bundle, error) { | |||
} | |||
} | |||
} | |||
|
|||
func validateBundle(bundle *Bundle) error { | |||
missingFields := make([]string, 0, 6) |
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.
Do we gain something by explicitly sizing the slice?
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 gain a little bit of performance for no change in readability.
Also, the commit messages are a bit sparse. Could you give some more context, please? |
9ccb818
to
c0cdaf1
Compare
We cannot define the resources in ssp operator code, because they can change when a new version of I think we can think of a more generic solution as part of the SSP cleanup epic. |
Can you please change PR title from |
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 maybe move bundle-test.yaml
and bundle-test-incorrect.yaml
to test-yamls
folder or something. It's up to you.
/lgtm
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 some comments.
We cannot define the resources in ssp operator code, because they can change when a new version of vm-console-proxy is released. Loading them only from yaml would be good, but the reconciliation code needs to know the types of resources, so it can use the correct update functions.
TTO can load resources from the pipeline / task manifests without knowing exactly which resources it will encounter. It only has a list of known kinds it can handle / reconcile. Can't you do the same?
kind := obj.GetKind() | ||
|
||
var destObj any | ||
switch obj.GetKind() { |
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.
switch kind := obj.GetKind(); kind
?
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.
Or if you need the kind
var later, use it here too?
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 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.
Reading of the vm-console-proxy bundle fails, if the yaml bundle contains an object with unexpected kind. Signed-off-by: Andrej Krejcir <akrejcir@redhat.com>
Simplify code that loads vm-console-proxy bundle. Signed-off-by: Andrej Krejcir <akrejcir@redhat.com>
Validate that no field in Bundle is nil. Signed-off-by: Andrej Krejcir <akrejcir@redhat.com>
c0cdaf1
to
22f6fbe
Compare
It will be some work, so we can add an Issue. |
Kudos, SonarCloud Quality Gate passed! 0 Bugs No Coverage information |
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
/approve |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: akrejcir 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 |
What this PR does / why we need it:
vm-console-proxy-bundle
moduleRelease note: