Skip to content

Commit

Permalink
fix: add the logic of removing the finalizer (openyurtio#1695)
Browse files Browse the repository at this point in the history
  • Loading branch information
Pluviophile225 authored Sep 14, 2023
1 parent 893f117 commit 6006a94
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
11 changes: 11 additions & 0 deletions pkg/yurtiotdock/controllers/device_syncer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -198,6 +200,15 @@ 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 {
klog.V(5).ErrorS(err, "fail to remove finalizer of Device on Kubernetes", "Device", kd.Name)
return err
}
}
return nil
}
Expand Down
11 changes: 11 additions & 0 deletions pkg/yurtiotdock/controllers/deviceprofile_syncer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -213,6 +215,15 @@ 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 {
klog.V(5).ErrorS(err, "fail to remove finalizer of DeviceProfile on Kubernetes", "DeviceProfile", kdp.Name)
return err
}
}
return nil
}
11 changes: 11 additions & 0 deletions pkg/yurtiotdock/controllers/deviceservice_syncer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -197,6 +199,15 @@ 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 {
klog.V(5).ErrorS(err, "fail to remove finalizer of DeviceService on Kubernetes", "DeviceService", kds.Name)
return err
}
}
return nil
}
Expand Down

0 comments on commit 6006a94

Please sign in to comment.