Skip to content

Commit

Permalink
fix: add the logic of removing the finalizer
Browse files Browse the repository at this point in the history
  • Loading branch information
Pluviophile225 committed Sep 7, 2023
1 parent 8b8c6e1 commit cee9928
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
10 changes: 10 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,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
}
Expand Down
10 changes: 10 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,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
}
10 changes: 10 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,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
}
Expand Down

0 comments on commit cee9928

Please sign in to comment.