Skip to content

Add "controllerutil" helpers for applyconfigurations (SSA) #2674

Open

Description

@erikgb

We are making extensive use of the helpers defined in https://github.com/kubernetes-sigs/controller-runtime/blob/main/pkg/controller/controllerutil/controllerutil.go, and while migrating our controllers to SSA we had to create our own modified copies based on corev1/metav1 applyconfigurations.

I think it could make sense adding a SSA-flavoured edition of these simple (but useful) helpers to controller-runtime. And I would be happy to submit a PR if you agree. The most challenging is probably to decide the package name/location. WDYT @alvaroaleman @vincepri @sbueringer?

Activity

  1. troy0820 commented on Feb 5, 2024

    @troy0820
    Member

    /kind support feature

  2. added
    kind/supportCategorizes issue or PR as a support question.
    kind/featureCategorizes issue or PR as related to a new feature.
    on Feb 5, 2024
  3. troy0820 commented on Mar 8, 2024

    @troy0820
    Member

    The tricky part here is the applyconfigurations that are not available for custom resources. (Should we deal with controller-tools to have that be created when you scaffold kubebuilder?)

    Do we only plan to support this for corev1 and the like? I think server side apply was looking to be done on the client.Client interface as well. Doing this in controllerutils may help migrate that to the interface. I'm interested in this as well.

  4. erikgb commented on Mar 9, 2024

    @erikgb
    MemberAuthor

    I just want to add the same helper as we have for the normal types. Here is an example from the modified helper we are using now:

    import (
    	"fmt"
    
    	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
    	"k8s.io/apimachinery/pkg/runtime"
    	metav1ac "k8s.io/client-go/applyconfigurations/meta/v1"
    	"k8s.io/utils/ptr"
    	"sigs.k8s.io/controller-runtime/pkg/client/apiutil"
    )
    
    // SetControllerReference sets owner as a Controller OwnerReference on controlled.
    // This is used for garbage collection of the controlled object and for
    // reconciling the owner object on changes to controlled (with a Watch + EnqueueRequestForOwner).
    func SetControllerReference(owner metav1.Object, controlled *metav1ac.ObjectMetaApplyConfiguration, scheme *runtime.Scheme) error {
    	// Validate the owner.
    	ro, ok := owner.(runtime.Object)
    	if !ok {
    		return fmt.Errorf("%T is not a runtime.Object, cannot call SetControllerReference", owner)
    	}
    	if err := validateOwner(owner, controlled); err != nil {
    		return err
    	}
    
    	gvk, err := apiutil.GVKForObject(ro, scheme)
    	if err != nil {
    		return err
    	}
    	controlled.WithOwnerReferences(
    		metav1ac.OwnerReference().
    			WithAPIVersion(gvk.GroupVersion().String()).
    			WithKind(gvk.Kind).
    			WithName(owner.GetName()).
    			WithUID(owner.GetUID()).
    			WithBlockOwnerDeletion(true).
    			WithController(true),
    	)
    	return nil
    }
  5. erikgb commented on Mar 9, 2024

    @erikgb
    MemberAuthor

    This might be possible to solve with generics also. I can look into a generics solution, as it will probably make the code more compact with less duplication.

  6. k8s-triage-robot commented on Jun 7, 2024

    @k8s-triage-robot

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

    This bot triages un-triaged issues 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 issue is closed

    You can:

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

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

    /lifecycle stale

  7. added
    lifecycle/staleDenotes an issue or PR has remained open with no activity and has become stale.
    on Jun 7, 2024
  8. erikgb commented on Jun 7, 2024

    @erikgb
    MemberAuthor

    /remove-lifecycle stale

    Still wanted/needed, but we'll probably have to wait for kubernetes/kubernetes#118138.

  9. removed
    lifecycle/staleDenotes an issue or PR has remained open with no activity and has become stale.
    on Jun 7, 2024
  10. erikgb commented on Jun 28, 2024

    @erikgb
    MemberAuthor

    /remove-kind support

    I think this is a valid feature request that will benefit the community. But we probably have to wait for 1. class SSA support in c/r before adding it.

  11. k8s-triage-robot commented on Sep 26, 2024

    @k8s-triage-robot

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

    This bot triages un-triaged issues 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 issue is closed

    You can:

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

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

    /lifecycle stale

  12. added
    lifecycle/staleDenotes an issue or PR has remained open with no activity and has become stale.
    on Sep 26, 2024
  13. sbueringer commented on Sep 27, 2024

    @sbueringer
    Member

    /remove-lifecycle stale
    /lifecycle frozen

  14. added
    lifecycle/frozenIndicates that an issue or PR should not be auto-closed due to staleness.
    and removed
    lifecycle/staleDenotes an issue or PR has remained open with no activity and has become stale.
    on Sep 27, 2024
  15. caozhuozi commented on Nov 27, 2024

    @caozhuozi
    Contributor

    👀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    kind/featureCategorizes issue or PR as related to a new feature.lifecycle/frozenIndicates that an issue or PR should not be auto-closed due to staleness.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions