diff --git a/internal/adapter/persistentvolume.go b/internal/adapter/persistentvolume.go index 49b33fc..e0b3d5d 100644 --- a/internal/adapter/persistentvolume.go +++ b/internal/adapter/persistentvolume.go @@ -118,28 +118,29 @@ func (adapter *KubeDockerAdapter) listPersistentVolumes(ctx context.Context) (co persistentVolumes := []core.PersistentVolume{} for _, volume := range volumeList.Volumes { - var boundPVCConfigMap *corev1.ConfigMap + if volume.Labels[k2dtypes.NamespaceNameLabelKey] == "" { + var boundPVCConfigMap *corev1.ConfigMap + + for _, configMap := range configMaps.Items { + if configMap.Labels[k2dtypes.PersistentVolumeNameLabelKey] == volume.Name { + boundPVCConfigMap = &configMap + break + } + } - for _, configMap := range configMaps.Items { - if configMap.Labels[k2dtypes.PersistentVolumeNameLabelKey] == volume.Name { - boundPVCConfigMap = &configMap - break + if boundPVCConfigMap == nil { + adapter.logger.Debugw("unable to retrieve system configmap for volume, setting phase to released and no claim reference", + "volume", volume.Name, + ) } - } - if boundPVCConfigMap == nil { - adapter.logger.Debugw("unable to retrieve system configmap for volume, setting phase to released and no claim reference", - "volume", volume.Name, - ) - } + persistentVolume, err := adapter.converter.ConvertVolumeToPersistentVolume(volume, boundPVCConfigMap) + if err != nil { + return core.PersistentVolumeList{}, fmt.Errorf("unable to convert Docker volume to PersistentVolume: %w", err) + } - persistentVolume, err := adapter.converter.ConvertVolumeToPersistentVolume(volume, boundPVCConfigMap) - if err != nil { - return core.PersistentVolumeList{}, fmt.Errorf("unable to convert Docker volume to PersistentVolume: %w", err) + persistentVolumes = append(persistentVolumes, persistentVolume) } - - persistentVolumes = append(persistentVolumes, persistentVolume) - } return core.PersistentVolumeList{ diff --git a/internal/adapter/store/volume/configmap.go b/internal/adapter/store/volume/configmap.go index a6fd119..843a2e8 100644 --- a/internal/adapter/store/volume/configmap.go +++ b/internal/adapter/store/volume/configmap.go @@ -9,7 +9,6 @@ import ( "github.com/docker/docker/errdefs" "github.com/portainer/k2d/internal/adapter/errors" "github.com/portainer/k2d/internal/adapter/types" - "github.com/portainer/k2d/pkg/maputils" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/kubernetes/pkg/apis/core" @@ -162,15 +161,13 @@ func (store *VolumeStore) GetConfigMaps(namespace string) (core.ConfigMapList, e func (store *VolumeStore) StoreConfigMap(configMap *corev1.ConfigMap) error { volumeName := buildConfigMapVolumeName(configMap.Name, configMap.Namespace) - labels := map[string]string{ - ResourceTypeLabelKey: ConfigMapResourceType, - types.NamespaceNameLabelKey: configMap.Namespace, - } - maputils.MergeMapsInPlace(labels, configMap.Labels) + // override is required for the configmap to be treated as the k2d system configmap + configMap.Labels[types.NamespaceNameLabelKey] = configMap.Namespace + configMap.Labels[ResourceTypeLabelKey] = ConfigMapResourceType volume, err := store.cli.VolumeCreate(context.TODO(), volume.CreateOptions{ Name: volumeName, - Labels: labels, + Labels: configMap.Labels, }) if err != nil { return fmt.Errorf("unable to create Docker volume: %w", err)