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

✨ Introduce controllerutil.Object interface #898

Merged
merged 3 commits into from
May 20, 2020

Conversation

ruromero
Copy link
Contributor

Signed-off-by: ruromero rromerom@redhat.com

Introduce an interface that combines metav1.Object and runtime.Object as discussed in #594

The main purpose of this interface is to reduce type conversions between the two and provide generic method signatures that can show potential errors at compile time and help developers to write simpler code.

This can make reconsider many places in this library and dependent ones its usage each time a cast is done, usually like the following:

//metav1.Object -> runtime.Object
ro, ok := owner.(runtime.Object)

//runtime.Object -> metav1.Object
o, err := meta.Accessor(obj)

An example where this interface can be used is https://github.com/kubernetes-sigs/controller-runtime/blob/master/pkg/controller/controllerutil/controllerutil.go#L95

Signed-off-by: ruromero <rromerom@redhat.com>
@k8s-ci-robot
Copy link
Contributor

Thanks for your pull request. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

📝 Please follow instructions at https://git.k8s.io/community/CLA.md#the-contributor-license-agreement to sign the CLA.

It may take a couple minutes for the CLA signature to be fully registered; after that, please reply here with a new comment and we'll verify. Thanks.


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.

@k8s-ci-robot k8s-ci-robot added the cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. label Apr 14, 2020
@k8s-ci-robot
Copy link
Contributor

Welcome @ruromero!

It looks like this is your first PR to kubernetes-sigs/controller-runtime 🎉. Please refer to our pull request process documentation to help your PR have a smooth ride to approval.

You will be prompted by a bot to use commands during the review process. Do not be afraid to follow the prompts! It is okay to experiment. Here is the bot commands documentation.

You can also check if kubernetes-sigs/controller-runtime has its own contribution guidelines.

You may want to refer to our testing guide if you run into trouble with your tests not passing.

If you are having difficulty getting your pull request seen, please follow the recommended escalation practices. Also, for tips and tricks in the contribution process you may want to read the Kubernetes contributor cheat sheet. We want to make sure your contribution gets all the attention it needs!

Thank you, and welcome to Kubernetes. 😃

@k8s-ci-robot
Copy link
Contributor

Hi @ruromero. Thanks for your PR.

I'm waiting for a kubernetes-sigs member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

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.

@k8s-ci-robot k8s-ci-robot added the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Apr 14, 2020
@k8s-ci-robot k8s-ci-robot added the size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. label Apr 14, 2020
@ruromero ruromero changed the title :sparkles Introduce KubernetesResource interface ✨ Introduce KubernetesResource interface Apr 14, 2020
@ruromero
Copy link
Contributor Author

Added CLA

@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. and removed cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. labels Apr 14, 2020
Copy link
Member

@joelanford joelanford left a comment

Choose a reason for hiding this comment

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

As @Adirio mentioned here, it might be useful to figure out where we're currently making type assertions in one direction or the other and decide whether we want to update those function signatures as well.

Not sure if that's a blocker for introducing the type though.

Lastly, I know I mentioned in an SDK issue that we should discuss adding this union type to controller-runtime, but now that I'm looking closer and see that metav1.Object and runtime.Object are both provided by k8s.io/apimachinery I wonder if we should pursue adding this there?


// KubernetesResource allows functions to work indistinctly with any resource that
// implements both Object interfaces.
type KubernetesResource interface {
Copy link
Member

Choose a reason for hiding this comment

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

Given that this is a union of two *.Object types would it be more intuitive for this to also include Object in the name?

Also, I wonder if the client package is the most appropriate place for this type. Nothing is really jumping out to me as an alternate though. Perhaps pkg/controller/controllerutil? 🤷‍♂️

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Renamed and moved

Signed-off-by: ruromero <rromerom@redhat.com>
@DirectXMan12
Copy link
Contributor

decide whether we want to update those function signatures as well.

Yeah, I think we want to do that. I think there's actually situations where some of those aren't a breaking change (I seem to recall adding additional interfaces to a compound interface casts transparently or something, but I'd have to double check).

@vincepri
Copy link
Member

Given that this lives under controllerutil, could we just call it Object instead of KubernetesObject ?

@vincepri
Copy link
Member

/ok-to-test

@k8s-ci-robot k8s-ci-robot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Apr 24, 2020
@k8s-ci-robot k8s-ci-robot added size/S Denotes a PR that changes 10-29 lines, ignoring generated files. and removed size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels May 6, 2020
@k8s-ci-robot k8s-ci-robot added size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. and removed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels May 6, 2020
Signed-off-by: ruromero <rromerom@redhat.com>
@ruromero
Copy link
Contributor Author

ruromero commented May 6, 2020

renamed @vincepri

@vincepri
Copy link
Member

vincepri commented May 6, 2020

/lgtm
/assign @DirectXMan12

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label May 6, 2020
@vincepri
Copy link
Member

/retitle ✨ Introduce controllerutil.Object interface

@k8s-ci-robot k8s-ci-robot changed the title ✨ Introduce KubernetesResource interface ✨ Introduce controllerutil.Object interface May 13, 2020
@vincepri vincepri added this to the v0.6.0 milestone May 13, 2020
Copy link
Member

@vincepri vincepri left a comment

Choose a reason for hiding this comment

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

/approve

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: ruromero, vincepri

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

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label May 20, 2020
@vincepri
Copy link
Member

Should we backport this? I'd be useful for other projects as well

@luxas
Copy link

luxas commented Jul 8, 2020

Thanks for this change 💯!
I'd love to have this under core k8s.io/apimachinery.
Would someone be up for "backporting" this to there?

@vincepri
Copy link
Member

vincepri commented Jul 8, 2020

@luxas Happy to help, although need some pointers to where we should place this interface :)

@luxas
Copy link

luxas commented Jul 14, 2020

Without knowing exactly, maybe https://pkg.go.dev/k8s.io/apimachinery@v0.18.5/pkg/api/meta?tab=doc would be a good place?

amisevsk added a commit to amisevsk/devworkspace-operator that referenced this pull request Aug 4, 2021
Prep code for supporting k8s 1.21:

* Add context.Context parameter to Reconcile() functions [1]
* Add RBAC get/create/update coordination.k8s.io/v1 Leases (replacing a
  configmap for leader election locks) [2]
* Adapt event handler code to reflect simplification [3]
* Adapt to apimachinery/pkg/runtime Log deprecation (replaced with
  pkg/client Log) [4]
* client.Object is preferred in favor of runtime.Object (v0.7.0 release) [5]
* Use admission/v1 instead of v1beta1 for webhook requests [6]

[1] - kubernetes-sigs/controller-runtime#1054
[2] - kubernetes-sigs/controller-runtime#1144
[3] - kubernetes-sigs/controller-runtime#1119
[4] - kubernetes-sigs/controller-runtime#1105
[5] - kubernetes-sigs/controller-runtime#898
      kubernetes-sigs/controller-runtime#1118
[6] - kubernetes-sigs/controller-runtime#1284

kubernetes-sigs/controller-runtime@a32b29d
Signed-off-by: Angel Misevski <amisevsk@redhat.com>
amisevsk added a commit to amisevsk/devworkspace-operator that referenced this pull request Aug 10, 2021
Prep code for supporting k8s 1.21:

* Add context.Context parameter to Reconcile() functions [1]
* Add RBAC get/create/update coordination.k8s.io/v1 Leases (replacing a
  configmap for leader election locks) [2]
* Adapt event handler code to reflect simplification [3]
* Adapt to apimachinery/pkg/runtime Log deprecation (replaced with
  pkg/client Log) [4]
* client.Object is preferred in favor of runtime.Object (v0.7.0 release) [5]
* Use admission/v1 instead of v1beta1 for webhook requests [6]

[1] - kubernetes-sigs/controller-runtime#1054
[2] - kubernetes-sigs/controller-runtime#1144
[3] - kubernetes-sigs/controller-runtime#1119
[4] - kubernetes-sigs/controller-runtime#1105
[5] - kubernetes-sigs/controller-runtime#898
      kubernetes-sigs/controller-runtime#1118
[6] - kubernetes-sigs/controller-runtime#1284

kubernetes-sigs/controller-runtime@a32b29d
Signed-off-by: Angel Misevski <amisevsk@redhat.com>
sleshchenko pushed a commit to amisevsk/devworkspace-operator that referenced this pull request Aug 11, 2021
Prep code for supporting k8s 1.21:

* Add context.Context parameter to Reconcile() functions [1]
* Add RBAC get/create/update coordination.k8s.io/v1 Leases (replacing a
  configmap for leader election locks) [2]
* Adapt event handler code to reflect simplification [3]
* Adapt to apimachinery/pkg/runtime Log deprecation (replaced with
  pkg/client Log) [4]
* client.Object is preferred in favor of runtime.Object (v0.7.0 release) [5]
* Use admission/v1 instead of v1beta1 for webhook requests [6]

[1] - kubernetes-sigs/controller-runtime#1054
[2] - kubernetes-sigs/controller-runtime#1144
[3] - kubernetes-sigs/controller-runtime#1119
[4] - kubernetes-sigs/controller-runtime#1105
[5] - kubernetes-sigs/controller-runtime#898
      kubernetes-sigs/controller-runtime#1118
[6] - kubernetes-sigs/controller-runtime#1284

kubernetes-sigs/controller-runtime@a32b29d
Signed-off-by: Angel Misevski <amisevsk@redhat.com>
amisevsk added a commit to amisevsk/devworkspace-operator that referenced this pull request Aug 12, 2021
Prep code for supporting k8s 1.21:

* Add context.Context parameter to Reconcile() functions [1]
* Add RBAC get/create/update coordination.k8s.io/v1 Leases (replacing a
  configmap for leader election locks) [2]
* Adapt event handler code to reflect simplification [3]
* Adapt to apimachinery/pkg/runtime Log deprecation (replaced with
  pkg/client Log) [4]
* client.Object is preferred in favor of runtime.Object (v0.7.0 release) [5]
* Use admission/v1 instead of v1beta1 for webhook requests [6]

[1] - kubernetes-sigs/controller-runtime#1054
[2] - kubernetes-sigs/controller-runtime#1144
[3] - kubernetes-sigs/controller-runtime#1119
[4] - kubernetes-sigs/controller-runtime#1105
[5] - kubernetes-sigs/controller-runtime#898
      kubernetes-sigs/controller-runtime#1118
[6] - kubernetes-sigs/controller-runtime#1284

kubernetes-sigs/controller-runtime@a32b29d
Signed-off-by: Angel Misevski <amisevsk@redhat.com>
amisevsk added a commit to amisevsk/devworkspace-operator that referenced this pull request Aug 12, 2021
Prep code for supporting k8s 1.21:

* Add context.Context parameter to Reconcile() functions [1]
* Add RBAC get/create/update coordination.k8s.io/v1 Leases (replacing a
  configmap for leader election locks) [2]
* Adapt event handler code to reflect simplification [3]
* Adapt to apimachinery/pkg/runtime Log deprecation (replaced with
  pkg/client Log) [4]
* client.Object is preferred in favor of runtime.Object (v0.7.0 release) [5]
* Use admission/v1 instead of v1beta1 for webhook requests [6]

[1] - kubernetes-sigs/controller-runtime#1054
[2] - kubernetes-sigs/controller-runtime#1144
[3] - kubernetes-sigs/controller-runtime#1119
[4] - kubernetes-sigs/controller-runtime#1105
[5] - kubernetes-sigs/controller-runtime#898
      kubernetes-sigs/controller-runtime#1118
[6] - kubernetes-sigs/controller-runtime#1284

kubernetes-sigs/controller-runtime@a32b29d
Signed-off-by: Angel Misevski <amisevsk@redhat.com>
amisevsk added a commit to amisevsk/devworkspace-operator that referenced this pull request Aug 12, 2021
Prep code for supporting k8s 1.21:

* Add context.Context parameter to Reconcile() functions [1]
* Add RBAC get/create/update coordination.k8s.io/v1 Leases (replacing a
  configmap for leader election locks) [2]
* Adapt event handler code to reflect simplification [3]
* Adapt to apimachinery/pkg/runtime Log deprecation (replaced with
  pkg/client Log) [4]
* client.Object is preferred in favor of runtime.Object (v0.7.0 release) [5]
* Use admission/v1 instead of v1beta1 for webhook requests [6]

[1] - kubernetes-sigs/controller-runtime#1054
[2] - kubernetes-sigs/controller-runtime#1144
[3] - kubernetes-sigs/controller-runtime#1119
[4] - kubernetes-sigs/controller-runtime#1105
[5] - kubernetes-sigs/controller-runtime#898
      kubernetes-sigs/controller-runtime#1118
[6] - kubernetes-sigs/controller-runtime#1284

kubernetes-sigs/controller-runtime@a32b29d
Signed-off-by: Angel Misevski <amisevsk@redhat.com>
JPinkney pushed a commit to devfile/devworkspace-operator that referenced this pull request Aug 30, 2021
Prep code for supporting k8s 1.21:

* Add context.Context parameter to Reconcile() functions [1]
* Add RBAC get/create/update coordination.k8s.io/v1 Leases (replacing a
  configmap for leader election locks) [2]
* Adapt event handler code to reflect simplification [3]
* Adapt to apimachinery/pkg/runtime Log deprecation (replaced with
  pkg/client Log) [4]
* client.Object is preferred in favor of runtime.Object (v0.7.0 release) [5]
* Use admission/v1 instead of v1beta1 for webhook requests [6]

[1] - kubernetes-sigs/controller-runtime#1054
[2] - kubernetes-sigs/controller-runtime#1144
[3] - kubernetes-sigs/controller-runtime#1119
[4] - kubernetes-sigs/controller-runtime#1105
[5] - kubernetes-sigs/controller-runtime#898
      kubernetes-sigs/controller-runtime#1118
[6] - kubernetes-sigs/controller-runtime#1284

kubernetes-sigs/controller-runtime@a32b29d
Signed-off-by: Angel Misevski <amisevsk@redhat.com>
sleshchenko pushed a commit to devfile/devworkspace-operator that referenced this pull request Sep 2, 2021
Prep code for supporting k8s 1.21:

* Add context.Context parameter to Reconcile() functions [1]
* Add RBAC get/create/update coordination.k8s.io/v1 Leases (replacing a
  configmap for leader election locks) [2]
* Adapt event handler code to reflect simplification [3]
* Adapt to apimachinery/pkg/runtime Log deprecation (replaced with
  pkg/client Log) [4]
* client.Object is preferred in favor of runtime.Object (v0.7.0 release) [5]
* Use admission/v1 instead of v1beta1 for webhook requests [6]

[1] - kubernetes-sigs/controller-runtime#1054
[2] - kubernetes-sigs/controller-runtime#1144
[3] - kubernetes-sigs/controller-runtime#1119
[4] - kubernetes-sigs/controller-runtime#1105
[5] - kubernetes-sigs/controller-runtime#898
      kubernetes-sigs/controller-runtime#1118
[6] - kubernetes-sigs/controller-runtime#1284

kubernetes-sigs/controller-runtime@a32b29d
Signed-off-by: Angel Misevski <amisevsk@redhat.com>
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. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. size/XS Denotes a PR that changes 0-9 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants