Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: PV, PVC, and configMaps not displaying correctly for the volume … #66

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 18 additions & 17 deletions internal/adapter/persistentvolume.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
11 changes: 4 additions & 7 deletions internal/adapter/store/volume/configmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand Down