diff --git a/pkg/kubenest/manifest/controlplane/etcd/mainfests_deployment.go b/pkg/kubenest/manifest/controlplane/etcd/mainfests_deployment.go index df6ff98aa..dfa407bb0 100644 --- a/pkg/kubenest/manifest/controlplane/etcd/mainfests_deployment.go +++ b/pkg/kubenest/manifest/controlplane/etcd/mainfests_deployment.go @@ -57,11 +57,7 @@ spec: - --listen-peer-urls=http://[::]:{{ .EtcdListenPeerPort }} - --advertise-client-urls=https://{{ .EtcdClientService }}.{{ .Namespace }}.svc.cluster.local:{{ .EtcdListenClientPort }} - --initial-cluster={{ .InitialCluster }} - {{ if .IPV6First }} - - --initial-advertise-peer-urls=http://[$(PODIP)]:2380 - {{ else }} - - --initial-advertise-peer-urls=http://$(PODIP):2380 - {{ end }} + - --initial-advertise-peer-urls=http://$(VIRTUAL_ETCD_NAME).{{ .EtcdPeerServiceName }}.{{ .Namespace }}.svc.cluster.local:2380 - --initial-cluster-state=new - --client-cert-auth=true - --trusted-ca-file=/etc/virtualcluster/pki/etcd/etcd-ca.crt diff --git a/pkg/kubenest/util/helper.go b/pkg/kubenest/util/helper.go index 35797fd6a..771ac14c1 100644 --- a/pkg/kubenest/util/helper.go +++ b/pkg/kubenest/util/helper.go @@ -12,7 +12,6 @@ import ( v1 "k8s.io/api/core/v1" rbacv1 "k8s.io/api/rbac/v1" apierrors "k8s.io/apimachinery/pkg/api/errors" - kerrors "k8s.io/apimachinery/pkg/api/errors" "k8s.io/apimachinery/pkg/api/meta" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" @@ -20,19 +19,28 @@ import ( utilyaml "k8s.io/apimachinery/pkg/util/yaml" "k8s.io/client-go/dynamic" clientset "k8s.io/client-go/kubernetes" + "k8s.io/client-go/util/retry" "k8s.io/klog/v2" "sigs.k8s.io/yaml" ) func CreateOrUpdateService(client clientset.Interface, svc *v1.Service) error { - _, err := client.CoreV1().Services(svc.GetNamespace()).Update(context.TODO(), svc, metav1.UpdateOptions{}) + _, err := client.CoreV1().Services(svc.GetNamespace()).Create(context.TODO(), svc, metav1.CreateOptions{}) if err != nil { - if !apierrors.IsNotFound(err) { - return err - } + if err := retry.RetryOnConflict(retry.DefaultRetry, func() error { + currentSvc, err := client.CoreV1().Services(svc.GetNamespace()).Get(context.TODO(), svc.GetName(), metav1.GetOptions{}) + if err != nil { + return err + } - _, err := client.CoreV1().Services(svc.GetNamespace()).Create(context.TODO(), svc, metav1.CreateOptions{}) - if err != nil { + svc.ResourceVersion = currentSvc.ResourceVersion + + _, err = client.CoreV1().Services(svc.GetNamespace()).Update(context.TODO(), svc, metav1.UpdateOptions{}) + if err != nil { + return err + } + return nil + }); err != nil { return err } } @@ -297,7 +305,7 @@ func ApplyObject(dynamicClient dynamic.Interface, obj *unstructured.Unstructured // Get the existing resource existingObj, err := resourceClient.Get(context.TODO(), name, metav1.GetOptions{}) if err != nil { - if kerrors.IsNotFound(err) { + if apierrors.IsNotFound(err) { // If not found, create the resource _, err = resourceClient.Create(context.TODO(), obj, metav1.CreateOptions{}) if err != nil { @@ -451,7 +459,7 @@ func ReplaceObject(dynamicClient dynamic.Interface, obj *unstructured.Unstructur // Get the existing resource _, err := resourceClient.Get(context.TODO(), name, metav1.GetOptions{}) if err != nil { - if kerrors.IsNotFound(err) { + if apierrors.IsNotFound(err) { // If not found, create the resource _, err = resourceClient.Create(context.TODO(), obj, metav1.CreateOptions{}) if err != nil {