controller-runtime icon indicating copy to clipboard operation
controller-runtime copied to clipboard

:sparkles: Fakeclient: Add apply support

Open alvaroaleman opened this issue 1 year ago • 2 comments

I don't think this change should be merged, but leaving it here for future reference before I forget about it.

Ref https://github.com/kubernetes-sigs/controller-runtime/issues/2341

This change is a POC for adding apply patch support to the fake client.

This relies on the upstream support for this which is implemented in a new FieldManagedObjectTracker. There are two major problems with this for us though:

  1. It requires a type converter which gets initialized with a parser that knows how the type look like. It doesn't look like it is possible to pass multiple parsers, which means the resulting client can only deal with the set of types the parser knows about, for example what is in client-go but it will not work with CRDs
  2. We have some code that wants to look at the object after it was patched to check if its valid - Since this is implemented in the tracker, it doesn't look like its possible to dry run the patch

alvaroaleman avatar Oct 14 '24 03:10 alvaroaleman

Skipping CI for Draft Pull Request. If you want CI signal for your change, please convert it to an actual PR. You can still manually trigger a test run with /test all

k8s-ci-robot avatar Oct 14 '24 03:10 k8s-ci-robot

The Kubernetes project currently lacks enough contributors to adequately respond to all PRs.

This bot triages PRs according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the PR is closed

You can:

  • Mark this PR as fresh with /remove-lifecycle stale
  • Close this PR with /close
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/lifecycle stale

k8s-triage-robot avatar Feb 08 '25 22:02 k8s-triage-robot

/lifecycle frozen This is a requested feature so I'd like to keep this open to demonstrate the challenges. I personally will not be working further on it though.

alvaroaleman avatar Feb 08 '25 22:02 alvaroaleman

@alvaroaleman: The lifecycle/frozen label cannot be applied to Pull Requests.

In response to this:

/lifecycle frozen This is a requested feature so I'd like to keep this open to demonstrate the challenges. I personally will not be working further on it though.

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-sigs/prow repository.

k8s-ci-robot avatar Feb 08 '25 22:02 k8s-ci-robot

The lifecycle/frozen label can not be applied to PRs.

This bot removes lifecycle/frozen from PRs because:

  • Commenting /lifecycle frozen on a PR has not worked since March 2021
  • PRs that remain open for >150 days are unlikely to be easily rebased

You can:

  • Rebase this PR and attempt to get it merged
  • Close this PR with /close

Please send feedback to sig-contributor-experience at kubernetes/community.

/remove-lifecycle frozen

k8s-triage-robot avatar Feb 09 '25 01:02 k8s-triage-robot

The Kubernetes project currently lacks enough active contributors to adequately respond to all PRs.

This bot triages PRs according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the PR is closed

You can:

  • Mark this PR as fresh with /remove-lifecycle rotten
  • Close this PR with /close
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/lifecycle rotten

k8s-triage-robot avatar Apr 07 '25 04:04 k8s-triage-robot

@alvaroaleman I ran into this myself but was able to verify that this PR solves it well enough for my own needs at least.

Is there anything I can do to help land this in a release?

tomasaschan avatar Apr 11 '25 05:04 tomasaschan

@tomasaschan this can not be merged in its current form, we need support in the upstream tracker for reloading the scheme and find a way to avoid breaking everyone by adding the managed fields.

alvaroaleman avatar Apr 11 '25 21:04 alvaroaleman

The Kubernetes project currently lacks enough active contributors to adequately respond to all issues and PRs.

This bot triages PRs according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the PR is closed

You can:

  • Reopen this PR with /reopen
  • Mark this PR as fresh with /remove-lifecycle rotten
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/close

k8s-triage-robot avatar May 11 '25 22:05 k8s-triage-robot

@k8s-triage-robot: Closed this PR.

In response to this:

The Kubernetes project currently lacks enough active contributors to adequately respond to all issues and PRs.

This bot triages PRs according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the PR is closed

You can:

  • Reopen this PR with /reopen
  • Mark this PR as fresh with /remove-lifecycle rotten
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/close

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-sigs/prow repository.

k8s-ci-robot avatar May 11 '25 22:05 k8s-ci-robot

@fsommar I think there's an old (probably closed PR, or intermediate step later refactored away) attempt at using this to test repo-enabler, if you're curious to test it on a "live" code base.

tomasaschan avatar Jun 14 '25 11:06 tomasaschan

@fsommar I think there's an old (probably closed PR, or intermediate step later refactored away) attempt at using this to test repo-enabler, if you're curious to test it on a "live" code base.

I found usages of client-go fakes in an old immutator commit 759c336c833e420e0b0ff33dc5f06229540b88b7 on PR#20 fwiw, but not controller-runtime fakes. IIRC you tried controller-runtime fakes first and decided to pivot to use client-go, which had the same issue in the end (I can't find those first attempts in a pushed commit). And now it's using envtest.

We have some upcoming work using controller-runtime likely in July. I'll try it out then, as I have a short vacation first!

fsommar avatar Jun 17 '25 08:06 fsommar

Here's the corresponding client-go fake issue, for reference: https://github.com/kubernetes/kubernetes/issues/133549

tomasaschan avatar Jun 17 '25 11:06 tomasaschan

Nice! Thx for working on this.

My comments are mostly around improving test coverage and godoc a bit

sbueringer avatar Jun 19 '25 06:06 sbueringer

@tomasaschan @fsommar could you please find a different place for your comments that are not about feedback to the code changes in here to avoid polluting this? Thanks!

alvaroaleman avatar Jun 19 '25 16:06 alvaroaleman

@alvaroaleman Last one from my side: https://github.com/kubernetes-sigs/controller-runtime/pull/2981#discussion_r2169194034

sbueringer avatar Jun 26 '25 14:06 sbueringer

/lgtm /approve

sbueringer avatar Jun 26 '25 17:06 sbueringer

LGTM label has been added.

Git tree hash: 2b9d7c67fa6bf77671bde55014a360b49b49e0fd

k8s-ci-robot avatar Jun 26 '25 17:06 k8s-ci-robot

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: alvaroaleman, sbueringer

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:
  • ~~OWNERS~~ [alvaroaleman,sbueringer]

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 avatar Jun 26 '25 17:06 k8s-ci-robot