From cee9928736c7210592a7e5868f2c41ab3b09fb3f Mon Sep 17 00:00:00 2001 From: Pluviophile225 <670233802@qq.com> Date: Thu, 7 Sep 2023 16:14:57 +0800 Subject: [PATCH] fix: add the logic of removing the finalizer --- pkg/yurtiotdock/controllers/device_syncer.go | 10 ++++++++++ pkg/yurtiotdock/controllers/deviceprofile_syncer.go | 10 ++++++++++ pkg/yurtiotdock/controllers/deviceservice_syncer.go | 10 ++++++++++ 3 files changed, 30 insertions(+) diff --git a/pkg/yurtiotdock/controllers/device_syncer.go b/pkg/yurtiotdock/controllers/device_syncer.go index 64e30c8dc36..36f5bc93f58 100644 --- a/pkg/yurtiotdock/controllers/device_syncer.go +++ b/pkg/yurtiotdock/controllers/device_syncer.go @@ -18,10 +18,12 @@ package controllers import ( "context" + "encoding/json" "strings" "time" apierrors "k8s.io/apimachinery/pkg/api/errors" + "k8s.io/apimachinery/pkg/types" "k8s.io/klog/v2" "sigs.k8s.io/controller-runtime/pkg/client" ctrlmgr "sigs.k8s.io/controller-runtime/pkg/manager" @@ -198,6 +200,14 @@ func (ds *DeviceSyncer) deleteDevices(redundantKubeDevices map[string]*iotv1alph "DeviceName", kd.Name) return err } + patchData, _ := json.Marshal(map[string]interface{}{ + "metadata": map[string]interface{}{ + "finalizers": []string{}, + }, + }) + if err := ds.Client.Patch(context.TODO(), kd, client.RawPatch(types.MergePatchType, patchData)); err != nil { + return err + } } return nil } diff --git a/pkg/yurtiotdock/controllers/deviceprofile_syncer.go b/pkg/yurtiotdock/controllers/deviceprofile_syncer.go index 5ae3390f8e5..53cecb789f1 100644 --- a/pkg/yurtiotdock/controllers/deviceprofile_syncer.go +++ b/pkg/yurtiotdock/controllers/deviceprofile_syncer.go @@ -18,10 +18,12 @@ package controllers import ( "context" + "encoding/json" "strings" "time" apierrors "k8s.io/apimachinery/pkg/api/errors" + "k8s.io/apimachinery/pkg/types" "k8s.io/klog/v2" "sigs.k8s.io/controller-runtime/pkg/client" ctrlmgr "sigs.k8s.io/controller-runtime/pkg/manager" @@ -213,6 +215,14 @@ func (dps *DeviceProfileSyncer) deleteDeviceProfiles(redundantKubeDeviceProfiles "DeviceProfile", kdp.Name) return err } + patchData, _ := json.Marshal(map[string]interface{}{ + "metadata": map[string]interface{}{ + "finalizers": []string{}, + }, + }) + if err := dps.Client.Patch(context.TODO(), kdp, client.RawPatch(types.MergePatchType, patchData)); err != nil { + return err + } } return nil } diff --git a/pkg/yurtiotdock/controllers/deviceservice_syncer.go b/pkg/yurtiotdock/controllers/deviceservice_syncer.go index 30a6e59b5c4..4bef403f5fb 100644 --- a/pkg/yurtiotdock/controllers/deviceservice_syncer.go +++ b/pkg/yurtiotdock/controllers/deviceservice_syncer.go @@ -17,10 +17,12 @@ package controllers import ( "context" + "encoding/json" "strings" "time" apierrors "k8s.io/apimachinery/pkg/api/errors" + "k8s.io/apimachinery/pkg/types" "k8s.io/klog/v2" "sigs.k8s.io/controller-runtime/pkg/client" ctrlmgr "sigs.k8s.io/controller-runtime/pkg/manager" @@ -197,6 +199,14 @@ func (ds *DeviceServiceSyncer) deleteDeviceServices(redundantKubeDeviceServices "DeviceService", kds.Name) return err } + patchData, _ := json.Marshal(map[string]interface{}{ + "metadata": map[string]interface{}{ + "finalizers": []string{}, + }, + }) + if err := ds.Client.Patch(context.TODO(), kds, client.RawPatch(types.MergePatchType, patchData)); err != nil { + return err + } } return nil }