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

Remove oldObject parameter from CreateK8sCR #87

Conversation

jhernand
Copy link
Collaborator

@jhernand jhernand commented Apr 11, 2024

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:

// Create an empty object of the same type of the new object. We will use it to
// 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.

@openshift-ci openshift-ci bot requested review from danielerez and irinamihai April 11, 2024 13:10
@@ -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.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
// fetch the current state.
// fetch of the current state.

Copy link
Collaborator Author

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.

Copy link
Collaborator Author

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]>
@jhernand jhernand force-pushed the remove_old_object_parameter_from_createk8scr branch from 5f2722c to b3a0703 Compare April 11, 2024 13:35
@irinamihai
Copy link
Collaborator

/lgtm

@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Apr 11, 2024
@irinamihai
Copy link
Collaborator

/approve

Copy link

openshift-ci bot commented Apr 11, 2024

[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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-ci openshift-ci bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Apr 11, 2024
@openshift-merge-bot openshift-merge-bot bot merged commit 377955e into openshift-kni:main Apr 11, 2024
8 checks passed
@jhernand jhernand deleted the remove_old_object_parameter_from_createk8scr branch April 11, 2024 16:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. lgtm Indicates that a PR is ready to be merged.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants