@@ -24,14 +24,17 @@ import (
2424 "context"
2525 "time"
2626
27- "github.com/arangodb/kube-arangodb/pkg/util/errors"
28- inspectorInterface "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector"
29-
3027 v1 "k8s.io/api/core/v1"
28+ meta "k8s.io/apimachinery/pkg/apis/meta/v1"
29+ "k8s.io/apimachinery/pkg/types"
3130
31+ "github.com/arangodb/kube-arangodb/pkg/deployment/patch"
3232 "github.com/arangodb/kube-arangodb/pkg/metrics"
3333 "github.com/arangodb/kube-arangodb/pkg/util"
34+ "github.com/arangodb/kube-arangodb/pkg/util/errors"
35+ "github.com/arangodb/kube-arangodb/pkg/util/globals"
3436 "github.com/arangodb/kube-arangodb/pkg/util/k8sutil"
37+ inspectorInterface "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector"
3538 pvcv1 "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/persistentvolumeclaim/v1"
3639)
3740
@@ -76,6 +79,26 @@ func (r *Resources) InspectPVCs(ctx context.Context, cachedStatus inspectorInter
7679 return nil
7780 }
7881
82+ owner := r .context .GetAPIObject ().AsOwner ()
83+ if k8sutil .UpdateOwnerRefToObjectIfNeeded (pvc .GetObjectMeta (), & owner ) {
84+ q := patch .NewPatch (patch .ItemReplace (patch .NewPath ("metadata" , "ownerReferences" ), pvc .ObjectMeta .OwnerReferences ))
85+ d , err := q .Marshal ()
86+ if err != nil {
87+ log .Debug ().Err (err ).Msg ("Failed to prepare PVC patch (ownerReferences)" )
88+ return errors .WithStack (err )
89+ }
90+
91+ err = globals .GetGlobalTimeouts ().Kubernetes ().RunWithTimeout (ctx , func (ctxChild context.Context ) error {
92+ _ , err := r .context .PersistentVolumeClaimsModInterface ().Patch (ctxChild , pvc .GetName (), types .JSONPatchType , d , meta.PatchOptions {})
93+ return err
94+ })
95+
96+ if err != nil {
97+ log .Debug ().Err (err ).Msg ("Failed to update PVC (ownerReferences)" )
98+ return errors .WithStack (err )
99+ }
100+ }
101+
79102 if k8sutil .IsPersistentVolumeClaimMarkedForDeletion (pvc ) {
80103 // Process finalizers
81104 if x , err := r .runPVCFinalizers (ctx , pvc , group , memberStatus ); err != nil {
0 commit comments