You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Add "controllerutil" helpers for applyconfigurations (SSA) #2674
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?
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.
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).funcSetControllerReference(owner metav1.Object, controlled*metav1ac.ObjectMetaApplyConfiguration, scheme*runtime.Scheme) error {
// Validate the owner.ro, ok:=owner.(runtime.Object)
if!ok {
returnfmt.Errorf("%T is not a runtime.Object, cannot call SetControllerReference", owner)
}
iferr:=validateOwner(owner, controlled); err!=nil {
returnerr
}
gvk, err:=apiutil.GVKForObject(ro, scheme)
iferr!=nil {
returnerr
}
controlled.WithOwnerReferences(
metav1ac.OwnerReference().
WithAPIVersion(gvk.GroupVersion().String()).
WithKind(gvk.Kind).
WithName(owner.GetName()).
WithUID(owner.GetUID()).
WithBlockOwnerDeletion(true).
WithController(true),
)
returnnil
}
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.
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.
Activity
troy0820 commentedon Feb 5, 2024
/kind support feature
troy0820 commentedon Mar 8, 2024
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.
erikgb commentedon Mar 9, 2024
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:
erikgb commentedon Mar 9, 2024
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.
k8s-triage-robot commentedon Jun 7, 2024
The Kubernetes project currently lacks enough contributors to adequately respond to all issues.
This bot triages un-triaged issues according to the following rules:
lifecycle/staleis appliedlifecycle/stalewas applied,lifecycle/rottenis appliedlifecycle/rottenwas applied, the issue is closedYou can:
/remove-lifecycle stale/closePlease send feedback to sig-contributor-experience at kubernetes/community.
/lifecycle stale
erikgb commentedon Jun 7, 2024
/remove-lifecycle stale
Still wanted/needed, but we'll probably have to wait for kubernetes/kubernetes#118138.
erikgb commentedon Jun 28, 2024
/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.
k8s-triage-robot commentedon Sep 26, 2024
The Kubernetes project currently lacks enough contributors to adequately respond to all issues.
This bot triages un-triaged issues according to the following rules:
lifecycle/staleis appliedlifecycle/stalewas applied,lifecycle/rottenis appliedlifecycle/rottenwas applied, the issue is closedYou can:
/remove-lifecycle stale/closePlease send feedback to sig-contributor-experience at kubernetes/community.
/lifecycle stale
sbueringer commentedon Sep 27, 2024
/remove-lifecycle stale
/lifecycle frozen
caozhuozi commentedon Nov 27, 2024
👀