...

Source file src/github.com/redhat-developer/odo/pkg/storage/utils.go

Documentation: github.com/redhat-developer/odo/pkg/storage

     1  package storage
     2  
     3  import (
     4  	"fmt"
     5  
     6  	"github.com/redhat-developer/odo/pkg/kclient"
     7  	odolabels "github.com/redhat-developer/odo/pkg/labels"
     8  	"github.com/redhat-developer/odo/pkg/util"
     9  )
    10  
    11  // getPVCNameFromStorageName returns the PVC associated with the given storage
    12  func getPVCNameFromStorageName(client kclient.ClientInterface, storageName string) (string, error) {
    13  	var selector = odolabels.Builder().WithStorageName(storageName).Selector()
    14  	pvcs, err := client.ListPVCNames(selector)
    15  	if err != nil {
    16  		return "", fmt.Errorf("unable to get PVC names for selector %v: %w", selector, err)
    17  	}
    18  	numPVCs := len(pvcs)
    19  	if numPVCs != 1 {
    20  		return "", fmt.Errorf("expected exactly one PVC attached to storage %v, but got %v, %v", storageName, numPVCs, pvcs)
    21  	}
    22  	return pvcs[0], nil
    23  }
    24  
    25  // generatePVCName generates a PVC name from the Devfile volume name, component name and app name
    26  func generatePVCName(volName, componentName, appName string) (string, error) {
    27  
    28  	pvcName, err := util.NamespaceKubernetesObject(volName, componentName)
    29  	if err != nil {
    30  		return "", fmt.Errorf("unable to create namespaced name: %w", err)
    31  	}
    32  
    33  	pvcName, err = util.NamespaceKubernetesObject(pvcName, appName)
    34  	if err != nil {
    35  		return "", fmt.Errorf("unable to create namespaced name: %w", err)
    36  	}
    37  
    38  	return pvcName, nil
    39  }
    40  
    41  // ConvertListLocalToMachine converts storage config list to StorageList type
    42  func ConvertListLocalToMachine(storageListConfig []LocalStorage) StorageList {
    43  
    44  	var storageListLocal []Storage
    45  
    46  	for _, storeLocal := range storageListConfig {
    47  		s := NewStorage(storeLocal.Name, storeLocal.Size, storeLocal.Path, storeLocal.Ephemeral)
    48  		s.Spec.ContainerName = storeLocal.Container
    49  		storageListLocal = append(storageListLocal, s)
    50  	}
    51  
    52  	return NewStorageList(storageListLocal)
    53  }
    54  

View as plain text