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

⚠️ Add client.SubResourceWriter #2072

Conversation

alvaroaleman
Copy link
Member

@alvaroaleman alvaroaleman commented Nov 28, 2022

This change adds a SubResourceWriter to the client package that can be used to Create, Update or Patch arbitrary subresources.

This fixes the majority of #172, the only thing missing for it to close would be to add subresource Get, as I think there is no existing usage of subresource Delete.

Relative to #1922 the main changes are:

  • Use distinct options for subresource Update and Patch which makes this a breaking change
  • Add subresource Create, needed for example for ServiceAccount tokens

Supersedes and thereby closes #1922
Supersedes and thereby closes #2015

/cc @FillZpp @joelanford @sbueringer

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Nov 28, 2022
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: alvaroaleman

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 approved Indicates a PR has been approved by an approver from all required OWNERS files. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Nov 28, 2022
@alvaroaleman alvaroaleman force-pushed the support-subresource-modification branch from 04f01e0 to 7620718 Compare November 28, 2022 03:06
pkg/client/options.go Outdated Show resolved Hide resolved
pkg/client/options.go Outdated Show resolved Hide resolved
@alvaroaleman alvaroaleman force-pushed the support-subresource-modification branch from 7620718 to 5f89d78 Compare November 28, 2022 23:03
pkg/client/typed_client.go Outdated Show resolved Hide resolved
type StatusWriter interface {
// SubResourceClient knows how to create a client which can update subresource
// for kubernetes objects.
type SubResourceClient interface {
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we add a TODO comment for SubResourceReader and those non-CRUD subresources?

Copy link
Member Author

Choose a reason for hiding this comment

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

Not sure, I think by then we would rename the SubResourceWriter

This change adds a SubResourceWriter to the client package that can be
used to Create, Update or Patch arbitrary subresources.

Co-authored-by: Sergey Zagursky <[email protected]>
@alvaroaleman alvaroaleman force-pushed the support-subresource-modification branch from 5f89d78 to d7724aa Compare November 29, 2022 23:09
@FillZpp
Copy link
Contributor

FillZpp commented Nov 30, 2022

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Nov 30, 2022
@k8s-ci-robot k8s-ci-robot merged commit 262268f into kubernetes-sigs:master Nov 30, 2022
@FillZpp
Copy link
Contributor

FillZpp commented Nov 30, 2022

Whoops, didn't notice it is approved, maybe I should have added a /hold. Not sure if someone else has any comment.

shafeeqes added a commit to shafeeqes/gardener that referenced this pull request Dec 20, 2022
shafeeqes added a commit to shafeeqes/gardener that referenced this pull request Dec 20, 2022
shafeeqes added a commit to shafeeqes/gardener that referenced this pull request Dec 20, 2022
shafeeqes added a commit to shafeeqes/gardener that referenced this pull request Dec 20, 2022
shafeeqes added a commit to shafeeqes/gardener that referenced this pull request Dec 20, 2022
shafeeqes added a commit to shafeeqes/gardener that referenced this pull request Dec 21, 2022
shafeeqes added a commit to shafeeqes/gardener that referenced this pull request Dec 21, 2022
shafeeqes added a commit to shafeeqes/gardener that referenced this pull request Dec 21, 2022
shafeeqes added a commit to shafeeqes/gardener that referenced this pull request Dec 21, 2022
shafeeqes added a commit to shafeeqes/gardener that referenced this pull request Dec 21, 2022
shafeeqes added a commit to shafeeqes/gardener that referenced this pull request Jan 2, 2023
k8s-ci-robot pushed a commit that referenced this pull request Jan 9, 2023
* Add additional SubResource* functions for FieldOwner

This enhances #2072 to allow FieldOwner work with SubResources to set the
FieldManager option.

* Typos

* Apply gofmt -s

* Add tests for FieldOwner
shafeeqes added a commit to shafeeqes/gardener that referenced this pull request Jan 9, 2023
shafeeqes added a commit to shafeeqes/gardener that referenced this pull request Jan 11, 2023
shafeeqes added a commit to shafeeqes/gardener that referenced this pull request Jan 12, 2023
shafeeqes added a commit to shafeeqes/gardener that referenced this pull request Jan 16, 2023
shafeeqes added a commit to shafeeqes/gardener that referenced this pull request Jan 19, 2023
shafeeqes added a commit to shafeeqes/gardener that referenced this pull request Jan 23, 2023
shafeeqes added a commit to shafeeqes/gardener that referenced this pull request Jan 24, 2023
tiraboschi added a commit to tiraboschi/hyperconverged-cluster-operator that referenced this pull request Jan 27, 2023
- github.com/onsi/ginkgo/v2 v2.5.1 -> v2.7.0
- github.com/onsi/gomega v1.24.1 -> v1.26.0
- github.com/openshift/library-go v0.0.0-20221129182131-19da1bc0df5f -> v0.0.0-20221216200640-2a52b7ce52f9
- github.com/operator-framework/api v0.17.1 -> v0.17.3
- github.com/samber/lo v1.36.0 -> v1.37.0
- golang.org/x/tools v0.3.0 -> v0.4.0
- k8s.io/* v0.25.4 -> v0.26.1
- k8s.io/kube-openapi v0.0.0-20221123214604-86e75ddd809a -> v0.0.0-20221207184640-f3cff1453715
- sigs.k8s.io/controller-runtime v0.13.1 -> v0.14.1
- sigs.k8s.io/controller-tools v0.10.0 -> v0.11.1

Consume client.SubResourceWriter from sigs.k8s.io/controller-runtime,
see: kubernetes-sigs/controller-runtime#2072

Signed-off-by: Simone Tiraboschi <[email protected]>
shafeeqes added a commit to shafeeqes/gardener that referenced this pull request Jan 27, 2023
kubevirt-bot pushed a commit to kubevirt/hyperconverged-cluster-operator that referenced this pull request Jan 27, 2023
- github.com/onsi/ginkgo/v2 v2.5.1 -> v2.7.0
- github.com/onsi/gomega v1.24.1 -> v1.26.0
- github.com/openshift/library-go v0.0.0-20221129182131-19da1bc0df5f -> v0.0.0-20221216200640-2a52b7ce52f9
- github.com/operator-framework/api v0.17.1 -> v0.17.3
- github.com/samber/lo v1.36.0 -> v1.37.0
- golang.org/x/tools v0.3.0 -> v0.4.0
- k8s.io/* v0.25.4 -> v0.26.1
- k8s.io/kube-openapi v0.0.0-20221123214604-86e75ddd809a -> v0.0.0-20221207184640-f3cff1453715
- sigs.k8s.io/controller-runtime v0.13.1 -> v0.14.1
- sigs.k8s.io/controller-tools v0.10.0 -> v0.11.1

Consume client.SubResourceWriter from sigs.k8s.io/controller-runtime,
see: kubernetes-sigs/controller-runtime#2072

Signed-off-by: Simone Tiraboschi <[email protected]>
k8s-infra-cherrypick-robot pushed a commit to k8s-infra-cherrypick-robot/controller-runtime that referenced this pull request Jan 29, 2023
This enhances kubernetes-sigs#2072 to allow FieldOwner work with SubResources to set the
FieldManager option.
k8s-ci-robot pushed a commit that referenced this pull request Jan 29, 2023
* Add additional SubResource* functions for FieldOwner

This enhances #2072 to allow FieldOwner work with SubResources to set the
FieldManager option.

* Typos

* Apply gofmt -s

* Add tests for FieldOwner

---------

Co-authored-by: David Schmitt <[email protected]>
shafeeqes added a commit to shafeeqes/gardener that referenced this pull request Jan 30, 2023
gardener-prow bot pushed a commit to gardener/gardener that referenced this pull request Jan 31, 2023
…`v0.14.1` (#7248)

* Update `k8s.io/*` to `v0.26.0`

* Update `sigs.k8s.io/controller-runtime` to `v0.14.1`

* Set `RecoverPanic` globally for the manager of `controller-manager` controllers

* Set `RecoverPanic` globally for the manager of `gardenlet` controllers

* Set `RecoverPanic` globally for the manager of `operator` controllers

* Set `RecoverPanic` globally for the manager of `resource-manager` controllers

* Set `RecoverPanic` globally for the manager of `scheduler` controllers

* Set `RecoverPanic` globally in manager options for extension controllers

* Change RecoverPanic bool to bool pointer for other controllers

* Run `make generate`

* Set `AllowInvalidLabelValueInSelector` to true in LabelSelectorValidationOptions for backwards compatibility

See kubernetes/kubernetes#113699 for more details

* Drop `Not` predicate util function in favor of controller-runtime `predicate.Not`

* Drop `NewClientWithFieldSelectorSupport` function in favor of controller-runtime `WithIndex` function

kubernetes-sigs/controller-runtime/pull/2025

* Use `Build()` function for all controllers

* Use Subresource client for `shoots/binding` and drop generated clientset

* Use Subresource client for `shoots/adminkubeconfig` and drop generated clientset

* Use Status() client for Status

Ref: kubernetes-sigs/controller-runtime#2072

* Adapt unit tests with mock StatusWriter

* Add "ValidatingAdmissionPolicy" to default admission plugins

* Adapt changes related to removed fields in kube-proxy config

* Add unit test cases for "#IsAdmissionPluginSupported" function

* Update envtest version

* Return error from `informer.AddEventHandler`

* Copy onsi/gomega/format package also to gomegacheck testdata

* Address PR review feedback

* Vendor current `etcd-druid` master

* Use `builder.Watches()` wherever possible

* Call `etcdOptions.Complete()` for gardener apiserver config

etcd-encryption is supported out-of-the-box now.
ref: kubernetes/kubernetes#112789

* Use Subresource client for `serviceaccounts/token` wherever possible

* Update `ahmetb/gen-crd-api-reference-docs` to `0.3.0`

* Update `sigs.k8s.io/controller-tools` to `v0.11.0`

Update to `v0.11.1` once kubernetes/kubernetes/pull/114617 is released.
In k8s v0.26.0 the CRD generation is broken.

* Remove unneeded dependencies for `gardener-scheduler` from skaffold.yaml

* Hardcode `RecoverPanic` to true for extensions controller

* Use `k8s.io/apimachinery/pkg/util/sets` and drop copied packages

* Drop ready check for garden informer sync for gardenlet

Adding ready check to manager is not possible after it's started, since controller-runtime, `v0.11.0`. However the check was broken, and it is now fixed in kubernetes-sigs/controller-runtime#2090, so we have to drop this.

* Adapt `provider-local` webhook

* Address PR review feedback

* Fix panic in ManagedSeed controller

Contexts: from this PR, we're not setting RecoverPanic to true in tests

* Vendor `etcd-druid` `v0.15.3`

* Update `k8s.io/*` and `controller-runtime`

k8s.io/* - 0.26.0=>0.26.1
controller-tools - 0.11.0=>0.11.1

* Run `make generate`

* Rebase

* Address PR review feedback

* Fix failing test

* Adapt `highavailabilityconfig` webhook integration test

`autoscaling/v2beta2.HorizontalPodAutoscaler` is removed in v1.26.
Ref: https://kubernetes.io/docs/reference/using-api/deprecation-guide/#v1-26

* Use `apiutil.NewDynamicRESTMapper` for Manager cache in tests

Co-authored-by: Rafael Franzke <[email protected]>

* Don't set `RecoverPanic` for os extensions in AddToManager

This is not required since we call `mgrOpts.Options()` here : https://github.com/gardener/gardener/blob/c9cb564d1adad0a1ecf9d44f23fb249bcf946a79/extensions/pkg/controller/operatingsystemconfig/oscommon/app/app.go#L88

* Truncate time in test to microsecond precision

Ref: kubernetes/kubernetes#111936

* Rebase

---------

Co-authored-by: Rafael Franzke <[email protected]>
george-angel added a commit to utilitywarehouse/kube-applier that referenced this pull request Feb 6, 2023
andrerun pushed a commit to andrerun/gardener that referenced this pull request Jul 6, 2023
…`v0.14.1` (gardener#7248)

* Update `k8s.io/*` to `v0.26.0`

* Update `sigs.k8s.io/controller-runtime` to `v0.14.1`

* Set `RecoverPanic` globally for the manager of `controller-manager` controllers

* Set `RecoverPanic` globally for the manager of `gardenlet` controllers

* Set `RecoverPanic` globally for the manager of `operator` controllers

* Set `RecoverPanic` globally for the manager of `resource-manager` controllers

* Set `RecoverPanic` globally for the manager of `scheduler` controllers

* Set `RecoverPanic` globally in manager options for extension controllers

* Change RecoverPanic bool to bool pointer for other controllers

* Run `make generate`

* Set `AllowInvalidLabelValueInSelector` to true in LabelSelectorValidationOptions for backwards compatibility

See kubernetes/kubernetes#113699 for more details

* Drop `Not` predicate util function in favor of controller-runtime `predicate.Not`

* Drop `NewClientWithFieldSelectorSupport` function in favor of controller-runtime `WithIndex` function

kubernetes-sigs/controller-runtime/pull/2025

* Use `Build()` function for all controllers

* Use Subresource client for `shoots/binding` and drop generated clientset

* Use Subresource client for `shoots/adminkubeconfig` and drop generated clientset

* Use Status() client for Status

Ref: kubernetes-sigs/controller-runtime#2072

* Adapt unit tests with mock StatusWriter

* Add "ValidatingAdmissionPolicy" to default admission plugins

* Adapt changes related to removed fields in kube-proxy config

* Add unit test cases for "#IsAdmissionPluginSupported" function

* Update envtest version

* Return error from `informer.AddEventHandler`

* Copy onsi/gomega/format package also to gomegacheck testdata

* Address PR review feedback

* Vendor current `etcd-druid` master

* Use `builder.Watches()` wherever possible

* Call `etcdOptions.Complete()` for gardener apiserver config

etcd-encryption is supported out-of-the-box now.
ref: kubernetes/kubernetes#112789

* Use Subresource client for `serviceaccounts/token` wherever possible

* Update `ahmetb/gen-crd-api-reference-docs` to `0.3.0`

* Update `sigs.k8s.io/controller-tools` to `v0.11.0`

Update to `v0.11.1` once kubernetes/kubernetes/pull/114617 is released.
In k8s v0.26.0 the CRD generation is broken.

* Remove unneeded dependencies for `gardener-scheduler` from skaffold.yaml

* Hardcode `RecoverPanic` to true for extensions controller

* Use `k8s.io/apimachinery/pkg/util/sets` and drop copied packages

* Drop ready check for garden informer sync for gardenlet

Adding ready check to manager is not possible after it's started, since controller-runtime, `v0.11.0`. However the check was broken, and it is now fixed in kubernetes-sigs/controller-runtime#2090, so we have to drop this.

* Adapt `provider-local` webhook

* Address PR review feedback

* Fix panic in ManagedSeed controller

Contexts: from this PR, we're not setting RecoverPanic to true in tests

* Vendor `etcd-druid` `v0.15.3`

* Update `k8s.io/*` and `controller-runtime`

k8s.io/* - 0.26.0=>0.26.1
controller-tools - 0.11.0=>0.11.1

* Run `make generate`

* Rebase

* Address PR review feedback

* Fix failing test

* Adapt `highavailabilityconfig` webhook integration test

`autoscaling/v2beta2.HorizontalPodAutoscaler` is removed in v1.26.
Ref: https://kubernetes.io/docs/reference/using-api/deprecation-guide/#v1-26

* Use `apiutil.NewDynamicRESTMapper` for Manager cache in tests

Co-authored-by: Rafael Franzke <[email protected]>

* Don't set `RecoverPanic` for os extensions in AddToManager

This is not required since we call `mgrOpts.Options()` here : https://github.com/gardener/gardener/blob/c9cb564d1adad0a1ecf9d44f23fb249bcf946a79/extensions/pkg/controller/operatingsystemconfig/oscommon/app/app.go#L88

* Truncate time in test to microsecond precision

Ref: kubernetes/kubernetes#111936

* Rebase

---------

Co-authored-by: Rafael Franzke <[email protected]>
@andriisoldatenko
Copy link

In the original PR #1922, there was a problem with updating the finalizer.

Can someone please explain how to implement it with the new client.SubResourceWriter, assuming we want to update ONLY the finalizer of deployment and don't have permission to update the entire object?

Thanks in advance, and sorry for commenting merged PR.

@sbueringer
Copy link
Member

I dont' know how to do it, but I would recommend opening a new issue. If that is already possible directly with client-go we might be able to infer from that how it could be done with the controller-runtime client.

I think in any case it would be good to have an example / test covering that scenario

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. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants