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

refactor: generic resources #681

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

VanillaSpoon
Copy link
Contributor

@VanillaSpoon VanillaSpoon commented Nov 7, 2023

Issue link

closes #686

What changes have been made

This Pr is a refactor of the GenericResources within MCAD with the separation of repeated logic into reusable functions, removal of commented out code, and movement of functions to utils, and helper files.

This refactor is aimed and improving readability, and reducing repetition.

Verification steps

Checks

  • I've made sure the tests are passing.
  • Testing Strategy
    • Unit tests
    • Manual tests
    • Testing is not required for this change

Copy link

openshift-ci bot commented Nov 7, 2023

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign asm582 for approval. For more information see the Kubernetes Code Review Process.

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@VanillaSpoon VanillaSpoon requested a review from asm582 November 10, 2023 14:32
Copy link

@ronensc ronensc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@VanillaSpoon I haven't gone through the whole code but it certainly looks better! :)

klog.Errorf("[getAppWrapperCompletionStatus] Error unmarshalling, err=%#v", err)
unstruct, err := genericresource.UnmarshalToUnstructured(objectName.Raw)
if err != nil {
klog.Errorf("[getAppWrapperCompletionStatus] Error: %v", err)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

UnmarshalToUnstructured() also logs this error. Do we need to log it again here?

Comment on lines 585 to 587
unstruct, err := genericresource.UnmarshalToUnstructured(objectName.Raw)
if err != nil {
klog.Errorf("[getAppWrapperCompletionStatus] Error: %v", err)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it make sense to continue the loop iteration if err != nil?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the feedback @ronensc :)

You are correct, we could exit the loop here, as if there is an error returned the remainder of the logic wont be operational.

However, I would be hesitant making adjustments in this pr, It may be worth looking into error handling overall separately.

Comment on lines 73 to 75
namespaced := true
// todo:DELETEME dd := common.KubeClient.Discovery()
dd := gr.clients.Discovery()
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An easy win could be deleting the comment that wants to be deleted :)

}


// checks if object has replicas and containers field
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// checks if object has replicas and containers field
// hasFields checks if obj has replicas and containers field

return isFound, replicas, objContainers
}

// checks if object has pod template spec and add new labels
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// checks if object has pod template spec and add new labels
// addLabelsToPodTemplateField checks if unstruct has pod template spec and adds new labels

name := ""
// todo:DELETEME dd := common.KubeClient.Discovery()
dd := gr.clients.Discovery()
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An easy win could be deleting the comment that wants to be deleted :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Refactor Generic Resources
3 participants