@@ -52,7 +52,7 @@ import (
5252 "github.com/arangodb/arangosync-client/client"
5353 "github.com/rs/zerolog"
5454 apiextensionsclient "k8s.io/apiextensions-apiserver/pkg/client/clientset/clientset"
55- metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
55+ meta "k8s.io/apimachinery/pkg/apis/meta/v1"
5656 "k8s.io/client-go/kubernetes"
5757 "k8s.io/client-go/tools/record"
5858
@@ -381,7 +381,7 @@ func (d *Deployment) handleArangoDeploymentUpdatedEvent(ctx context.Context) err
381381 // Get the most recent version of the deployment from the API server
382382 ctxChild , cancel := globals .GetGlobalTimeouts ().Kubernetes ().WithTimeout (ctx )
383383 defer cancel ()
384- current , err := d .deps .DatabaseCRCli .DatabaseV1 ().ArangoDeployments (d .apiObject .GetNamespace ()).Get (ctxChild , d .apiObject .GetName (), metav1 .GetOptions {})
384+ current , err := d .deps .DatabaseCRCli .DatabaseV1 ().ArangoDeployments (d .apiObject .GetNamespace ()).Get (ctxChild , d .apiObject .GetName (), meta .GetOptions {})
385385 if err != nil {
386386 log .Debug ().Err (err ).Msg ("Failed to get current version of deployment from API server" )
387387 if k8sutil .IsNotFound (err ) {
@@ -465,21 +465,22 @@ func (d *Deployment) updateCRStatus(ctx context.Context, force ...bool) error {
465465 }
466466
467467 // Send update to API server
468- ns := d .apiObject .GetNamespace ()
469- depls := d .deps .DatabaseCRCli .DatabaseV1 ().ArangoDeployments (ns )
470- update := d .apiObject .DeepCopy ()
468+ depls := d .deps .DatabaseCRCli .DatabaseV1 ().ArangoDeployments (d .GetNamespace ())
471469 attempt := 0
472470 for {
473471 attempt ++
474- update .Status = d .status .last
475- if update .GetDeletionTimestamp () == nil {
476- ensureFinalizers (update )
472+ if d .apiObject .GetDeletionTimestamp () == nil {
473+ ensureFinalizers (d .apiObject )
477474 }
478475
479476 var newAPIObject * api.ArangoDeployment
480477 err := globals .GetGlobalTimeouts ().Kubernetes ().RunWithTimeout (ctx , func (ctxChild context.Context ) error {
481- var err error
482- newAPIObject , err = depls .Update (ctxChild , update , metav1.UpdateOptions {})
478+ p , err := patch .NewPatch (patch .ItemReplace (patch .NewPath ("status" ), d .status .last )).Marshal ()
479+ if err != nil {
480+ return err
481+ }
482+
483+ newAPIObject , err = depls .Patch (ctxChild , d .GetName (), types .JSONPatchType , p , meta.PatchOptions {})
483484
484485 return err
485486 })
@@ -488,21 +489,8 @@ func (d *Deployment) updateCRStatus(ctx context.Context, force ...bool) error {
488489 d .apiObject = newAPIObject
489490 return nil
490491 }
491- if attempt < 10 && k8sutil .IsConflict (err ) {
492- // API object may have been changed already,
493- // Reload api object and try again
494- var current * api.ArangoDeployment
495-
496- err = globals .GetGlobalTimeouts ().Kubernetes ().RunWithTimeout (ctx , func (ctxChild context.Context ) error {
497- var err error
498- current , err = depls .Get (ctxChild , update .GetName (), metav1.GetOptions {})
499-
500- return err
501- })
502- if err == nil {
503- update = current .DeepCopy ()
504- continue
505- }
492+ if attempt < 10 {
493+ continue
506494 }
507495 if err != nil {
508496 d .deps .Log .Debug ().Err (err ).Msg ("failed to patch ArangoDeployment status" )
@@ -535,7 +523,7 @@ func (d *Deployment) updateCRSpec(ctx context.Context, newSpec api.DeploymentSpe
535523 var newAPIObject * api.ArangoDeployment
536524 err := globals .GetGlobalTimeouts ().Kubernetes ().RunWithTimeout (ctx , func (ctxChild context.Context ) error {
537525 var err error
538- newAPIObject , err = d .deps .DatabaseCRCli .DatabaseV1 ().ArangoDeployments (ns ).Update (ctxChild , update , metav1 .UpdateOptions {})
526+ newAPIObject , err = d .deps .DatabaseCRCli .DatabaseV1 ().ArangoDeployments (ns ).Update (ctxChild , update , meta .UpdateOptions {})
539527
540528 return err
541529 })
@@ -551,7 +539,7 @@ func (d *Deployment) updateCRSpec(ctx context.Context, newSpec api.DeploymentSpe
551539
552540 err = globals .GetGlobalTimeouts ().Kubernetes ().RunWithTimeout (ctx , func (ctxChild context.Context ) error {
553541 var err error
554- current , err = d .deps .DatabaseCRCli .DatabaseV1 ().ArangoDeployments (ns ).Get (ctxChild , update .GetName (), metav1 .GetOptions {})
542+ current , err = d .deps .DatabaseCRCli .DatabaseV1 ().ArangoDeployments (ns ).Get (ctxChild , update .GetName (), meta .GetOptions {})
555543
556544 return err
557545 })
@@ -568,7 +556,7 @@ func (d *Deployment) updateCRSpec(ctx context.Context, newSpec api.DeploymentSpe
568556}
569557
570558// isOwnerOf returns true if the given object belong to this deployment.
571- func (d * Deployment ) isOwnerOf (obj metav1 .Object ) bool {
559+ func (d * Deployment ) isOwnerOf (obj meta .Object ) bool {
572560 ownerRefs := obj .GetOwnerReferences ()
573561 if len (ownerRefs ) < 1 {
574562 return false
@@ -583,9 +571,9 @@ func (d *Deployment) isOwnerOf(obj metav1.Object) bool {
583571func (d * Deployment ) lookForServiceMonitorCRD () {
584572 var err error
585573 if d .GetScope ().IsNamespaced () {
586- _ , err = d .deps .KubeMonitoringCli .ServiceMonitors (d .GetNamespace ()).List (context .Background (), metav1 .ListOptions {})
574+ _ , err = d .deps .KubeMonitoringCli .ServiceMonitors (d .GetNamespace ()).List (context .Background (), meta .ListOptions {})
587575 } else {
588- _ , err = d .deps .KubeExtCli .ApiextensionsV1 ().CustomResourceDefinitions ().Get (context .Background (), "servicemonitors.monitoring.coreos.com" , metav1 .GetOptions {})
576+ _ , err = d .deps .KubeExtCli .ApiextensionsV1 ().CustomResourceDefinitions ().Get (context .Background (), "servicemonitors.monitoring.coreos.com" , meta .GetOptions {})
589577 }
590578 log := d .deps .Log
591579 log .Debug ().Msgf ("Looking for ServiceMonitor CRD..." )
@@ -637,7 +625,7 @@ func (d *Deployment) ApplyPatch(ctx context.Context, p ...patch.Item) error {
637625
638626 ctxChild , cancel := globals .GetGlobalTimeouts ().Kubernetes ().WithTimeout (ctx )
639627 defer cancel ()
640- depl , err := c .Patch (ctxChild , d .apiObject .GetName (), types .JSONPatchType , data , metav1 .PatchOptions {})
628+ depl , err := c .Patch (ctxChild , d .apiObject .GetName (), types .JSONPatchType , data , meta .PatchOptions {})
641629 if err != nil {
642630 return err
643631 }
0 commit comments