-
Notifications
You must be signed in to change notification settings - Fork 29
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
Remove oldObject
parameter from CreateK8sCR
#87
Remove oldObject
parameter from CreateK8sCR
#87
Conversation
internal/controllers/utils/utils.go
Outdated
@@ -31,7 +31,11 @@ func CreateK8sCR(ctx context.Context, c client.Client, | |||
return err | |||
} | |||
|
|||
// Check if the CR already exists. | |||
// Create an empty object of the same type of the new object. We will use it to store the | |||
// fetch the current state. |
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.
// fetch the current state. | |
// fetch of the current state. |
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 @irinamihai, I will fix 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.
Done.
Currently the `CreateK8sCR` function receives an `oldObject` parameter that is needed because the function doesn't know how to create an empty object of the same type of the object that is going to be created. But that can be solved using reflection, something like this: ```go // Create an empty object of the same type of the new object. We will use it to store the // fetch the current state. objectType := reflect.TypeOf(newObject).Elem() oldObject := reflect.New(objectType).Interface().(client.Object) ``` This patch does that and removes the `oldObject` parameter, which simplifies the code that calls the `CreateK8sCR` function. Signed-off-by: Juan Hernandez <[email protected]>
5f2722c
to
b3a0703
Compare
/lgtm |
/approve |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: irinamihai 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 |
Currently the
CreateK8sCR
function receives anoldObject
parameter that is needed because the function doesn't know how to create an empty object of the same type of the object that is going to be created. But that can be solved using reflection, something like this:This patch does that and removes the
oldObject
parameter, which simplifies the code that calls theCreateK8sCR
function.