From ac43fe7f6efef5132a170f1f124949d9c9d0d232 Mon Sep 17 00:00:00 2001 From: Shelley-BaoYue Date: Wed, 11 Sep 2024 15:52:16 +0800 Subject: [PATCH] fix pvc deleted abnormally Signed-off-by: Shelley-BaoYue --- .../typed/core/v1/persistentvolume_bridge.go | 2 +- .../storage/v1/volumeattachment_bridge_test.go | 18 +++++++++--------- edge/pkg/metamanager/client/metaclient.go | 4 ++-- .../pkg/metamanager/client/persistentvolume.go | 13 ++++++------- 4 files changed, 18 insertions(+), 19 deletions(-) diff --git a/edge/pkg/edged/kubeclientbridge/typed/core/v1/persistentvolume_bridge.go b/edge/pkg/edged/kubeclientbridge/typed/core/v1/persistentvolume_bridge.go index 7c7cfe8018e..a586bf7e58a 100644 --- a/edge/pkg/edged/kubeclientbridge/typed/core/v1/persistentvolume_bridge.go +++ b/edge/pkg/edged/kubeclientbridge/typed/core/v1/persistentvolume_bridge.go @@ -41,5 +41,5 @@ type PersistentVolumesBridge struct { // Get takes name of the persistentVolume, and returns the corresponding persistentVolume object, and an error if there is any. func (c *PersistentVolumesBridge) Get(_ context.Context, name string, options metav1.GetOptions) (result *corev1.PersistentVolume, err error) { - return c.MetaClient.PersistentVolumes(metav1.NamespaceDefault).Get(name, options) + return c.MetaClient.PersistentVolumes().Get(name, options) } diff --git a/edge/pkg/edged/kubeclientbridge/typed/storage/v1/volumeattachment_bridge_test.go b/edge/pkg/edged/kubeclientbridge/typed/storage/v1/volumeattachment_bridge_test.go index 15f42de51f6..8aad64bc687 100644 --- a/edge/pkg/edged/kubeclientbridge/typed/storage/v1/volumeattachment_bridge_test.go +++ b/edge/pkg/edged/kubeclientbridge/typed/storage/v1/volumeattachment_bridge_test.go @@ -57,15 +57,15 @@ func (f *mockMetaClient) VolumeAttachments(_ string) client.VolumeAttachmentsInt return f.volumeAttachments } -func (f *mockMetaClient) Pods(string) client.PodsInterface { return nil } -func (f *mockMetaClient) PodStatus(string) client.PodStatusInterface { return nil } -func (f *mockMetaClient) ConfigMaps(string) client.ConfigMapsInterface { return nil } -func (f *mockMetaClient) Nodes(string) client.NodesInterface { return nil } -func (f *mockMetaClient) NodeStatus(string) client.NodeStatusInterface { return nil } -func (f *mockMetaClient) Secrets(string) client.SecretsInterface { return nil } -func (f *mockMetaClient) ServiceAccountToken() client.ServiceAccountTokenInterface { return nil } -func (f *mockMetaClient) ServiceAccounts(string) client.ServiceAccountInterface { return nil } -func (f *mockMetaClient) PersistentVolumes(string) client.PersistentVolumesInterface { return nil } +func (f *mockMetaClient) Pods(string) client.PodsInterface { return nil } +func (f *mockMetaClient) PodStatus(string) client.PodStatusInterface { return nil } +func (f *mockMetaClient) ConfigMaps(string) client.ConfigMapsInterface { return nil } +func (f *mockMetaClient) Nodes(string) client.NodesInterface { return nil } +func (f *mockMetaClient) NodeStatus(string) client.NodeStatusInterface { return nil } +func (f *mockMetaClient) Secrets(string) client.SecretsInterface { return nil } +func (f *mockMetaClient) ServiceAccountToken() client.ServiceAccountTokenInterface { return nil } +func (f *mockMetaClient) ServiceAccounts(string) client.ServiceAccountInterface { return nil } +func (f *mockMetaClient) PersistentVolumes() client.PersistentVolumesInterface { return nil } func (f *mockMetaClient) PersistentVolumeClaims(string) client.PersistentVolumeClaimsInterface { return nil } diff --git a/edge/pkg/metamanager/client/metaclient.go b/edge/pkg/metamanager/client/metaclient.go index ec3bc60fd0c..ea8a15f4e9c 100644 --- a/edge/pkg/metamanager/client/metaclient.go +++ b/edge/pkg/metamanager/client/metaclient.go @@ -70,8 +70,8 @@ func (m *metaClient) PodStatus(namespace string) PodStatusInterface { } // New PersistentVolumes metaClient -func (m *metaClient) PersistentVolumes(namespace string) PersistentVolumesInterface { - return newPersistentVolumes(namespace, m.send) +func (m *metaClient) PersistentVolumes() PersistentVolumesInterface { + return newPersistentVolumes(m.send) } // New PersistentVolumeClaims metaClient diff --git a/edge/pkg/metamanager/client/persistentvolume.go b/edge/pkg/metamanager/client/persistentvolume.go index 02a2fa38215..c7d08701255 100644 --- a/edge/pkg/metamanager/client/persistentvolume.go +++ b/edge/pkg/metamanager/client/persistentvolume.go @@ -10,11 +10,12 @@ import ( "github.com/kubeedge/beehive/pkg/core/model" "github.com/kubeedge/kubeedge/edge/pkg/common/message" "github.com/kubeedge/kubeedge/edge/pkg/common/modules" + v2 "github.com/kubeedge/kubeedge/edge/pkg/metamanager/dao/v2" ) // PersistentVolumesGetter is interface to get client PersistentVolumes type PersistentVolumesGetter interface { - PersistentVolumes(namespace string) PersistentVolumesInterface + PersistentVolumes() PersistentVolumesInterface } // PersistentVolumesInterface is interface for client PersistentVolumes @@ -26,14 +27,12 @@ type PersistentVolumesInterface interface { } type persistentvolumes struct { - namespace string - send SendInterface + send SendInterface } -func newPersistentVolumes(n string, s SendInterface) *persistentvolumes { +func newPersistentVolumes(s SendInterface) *persistentvolumes { return &persistentvolumes{ - namespace: n, - send: s, + send: s, } } @@ -50,7 +49,7 @@ func (c *persistentvolumes) Delete(string) error { } func (c *persistentvolumes) Get(name string, _ metav1.GetOptions) (*api.PersistentVolume, error) { - resource := fmt.Sprintf("%s/%s/%s", c.namespace, "persistentvolume", name) + resource := fmt.Sprintf("%s/%s/%s", v2.NullNamespace, "persistentvolume", name) pvMsg := message.BuildMsg(modules.MetaGroup, "", modules.EdgedModuleName, resource, model.QueryOperation, nil) msg, err := c.send.SendSync(pvMsg) if err != nil {