Cluster information:
Kubernetes version: v1.25.7
example
package main
import (
"context"
"fmt"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/tools/clientcmd"
)
func main() {
config, err := clientcmd.BuildConfigFromFlags("", "path_to_kubeconfig")
if err != nil {
panic(err.Error())
}
clientset, err := kubernetes.NewForConfig(config)
if err != nil {
panic(err.Error())
}
aiClient, err := aiclient.NewForConfig(config)
if err != nil {
panic(err.Error())
}
deploymentsClient := clientset.AppsV1().Deployments("kube-system")
deployment, err := deploymentsClient.Get(context.TODO(), "coredns", metav1.GetOptions{})
if err != nil {
panic(err.Error())
}
deployment.ResourceVersion = ""
replicas := int32(3)
deployment.Spec.Replicas = &replicas
_, err = deploymentsClient.Update(context.TODO(), deployment, metav1.UpdateOptions{})
if err != nil {
panic(err.Error())
}
}
Why can the deployment be updated successfully after the ResourceVersion is set to “”? but the custom resource cannot?