Replies: 1 comment
-
Hi @hzyfox, The following example might help you out ```go
package controllers
import (
"context"
"k8s.io/apimachinery/pkg/runtime"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
"k8s.io/api/autoscaling/v1"
)
func (r *YourReconciler) GetAndUpdateScale(ctx context.Context, namespace string, name string, desiredReplicas int32) error {
scale := &v1.Scale{}
scaleKey := client.ObjectKey{
Namespace: namespace,
Name: name,
}
// Fetch current scale of the Deployment
if err := r.Get(ctx, scaleKey, scale); err != nil {
return err
}
// Update the replica count in the retrieved scale object
scale.Spec.Replicas = desiredReplicas
// Update the scale in the cluster
if err := r.Update(ctx, scale); err != nil {
return err
}
return nil
} The same approach it seems to applies to For further details on using subresources with controller-runtime, you might want to check out the official controller-runtime documentation and the Kubebuilder book. Suggestion: It might be helpful to review the content of this PR: kubebuilder PR #3596. It offers a comprehensive guide that might clarify how things operate in Kubebuider/Controller runtime. I hope that helps you out So, I am closing this one. However, if you think that it should be re-opened please feel free to do so, |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Is There a client like status clinet to get and update Scale subresource which belong to k8s internal workload (eg. Deployment, Statefulset) or User Defined Workalod (eg. Open Krusie Statefulset)?
And how to build a Scale Client from scratch with golang ?
Beta Was this translation helpful? Give feedback.
All reactions