Skip to content

Commit

Permalink
Add "ephermeral" option in preference.yaml
Browse files Browse the repository at this point in the history
  • Loading branch information
Aditi Sharma committed Dec 17, 2020
1 parent 2274dcd commit cbed088
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 34 deletions.
49 changes: 24 additions & 25 deletions pkg/devfile/adapters/kubernetes/component/adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import (

devfilev1 "github.com/devfile/api/pkg/apis/workspaces/v1alpha2"
"github.com/openshift/odo/pkg/component"
"github.com/openshift/odo/pkg/preference"

"github.com/openshift/odo/pkg/config"
"github.com/openshift/odo/pkg/devfile/adapters/common"
"github.com/openshift/odo/pkg/devfile/adapters/kubernetes/storage"
Expand Down Expand Up @@ -301,16 +303,28 @@ func (a Adapter) createOrUpdateComponent(componentExists bool, ei envinfo.EnvSpe
initContainers = append(initContainers, supervisordInitContainer)

containerNameToVolumes := common.GetVolumes(a.Devfile)
containerNameToVolumes["odosource"] = []common.DevfileVolume{
{
Name: utils.OdoSourceVolume,
Size: "2Gi",
},

pref, err := preference.New()
if err != nil {
return err
}

if !pref.GetEphermeralSourceVolume() {

// If ephermeral volume is false, then we need to add to source volume in the map to create pvc.
containerNameToVolumes["odosource"] = []common.DevfileVolume{
{
Name: utils.OdoSourceVolume,
Size: utils.OdoSourceVolumeSize,
},
}
}

var odoSourcePVCName string

var uniqueStorages []common.Storage
volumeNameToPVCName := make(map[string]string)
processedVolumes := make(map[string]bool)
var odoSourcePVCName string

// Get a list of all the unique volume names and generate their PVC names
// we do not use the volume components which are unique here because
Expand Down Expand Up @@ -357,33 +371,18 @@ func (a Adapter) createOrUpdateComponent(componentExists bool, ei envinfo.EnvSpe
return err
}

// remove odo source volume from these maps as we do not want to pass source volume in GetPVCAndVolumeMount
// we are mounting odo source volume seperately
delete(volumeNameToPVCName, utils.OdoSourceVolume)
delete(containerNameToVolumes, "odosource")

// Get PVC volumes and Volume Mounts
containers, pvcVolumes, err := storage.GetPVCAndVolumeMount(containers, volumeNameToPVCName, containerNameToVolumes)
if err != nil {
return err
}

// (adi)Implementation for PVC as source volume.
// Add condition here for ephermeral
/* odoSourcePVCName, err := storage.GeneratePVCNameFromDevfileVol(utils.OdoSourceVolume, componentName)
if err != nil {
return err
}
SourcePvc := common.Storage{
Name: odoSourcePVCName,
Volume: common.DevfileVolume{
Name: utils.OdoSourceVolume,
// TODO(adi): Add size constant here
Size: "2Gi",
},
}
uniqueStorages = append(uniqueStorages, SourcePvc) */

odoMandatoryVolumes := utils.GetOdoContainerVolumes(false, odoSourcePVCName)
odoMandatoryVolumes := utils.GetOdoContainerVolumes(odoSourcePVCName)

selectorLabels := map[string]string{
"component": componentName,
Expand Down
6 changes: 3 additions & 3 deletions pkg/devfile/adapters/kubernetes/storage/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,13 @@ func CreateComponentStorage(Client *kclient.Client, storages []common.Storage, c
func Create(Client *kclient.Client, name, size, componentName, pvcName string) (*corev1.PersistentVolumeClaim, error) {

label := map[string]string{
"component": componentName,
"component": componentName,
labels.DevfileStorageLabel: name,
}

if strings.Contains(pvcName, kutils.OdoSourceVolume) {
// Add label for source pvc
label[labels.SourcePVCLabel] = name
} else {
label[labels.DevfileStorageLabel] = name
}

objectMeta := generator.GetObjectMeta(pvcName, Client.Namespace, label, nil)
Expand Down
7 changes: 5 additions & 2 deletions pkg/devfile/adapters/kubernetes/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,16 @@ const (

// OdoSourceVolume is the constant containing the name of the emptyDir volume containing the project source
OdoSourceVolume = "odo-projects"

// OdoSourceVolumeSize specifies size for odo source volume.
OdoSourceVolumeSize = "2Gi"
)

// GetOdoContainerVolumes returns the mandatory Kube volumes for an Odo component
func GetOdoContainerVolumes(ephemeral bool, sourcePVCName string) []corev1.Volume {
func GetOdoContainerVolumes(sourcePVCName string) []corev1.Volume {
var sourceVolume corev1.Volume

if !ephemeral {
if sourcePVCName != "" {
sourceVolume = corev1.Volume{
Name: OdoSourceVolume,
VolumeSource: corev1.VolumeSource{
Expand Down
11 changes: 11 additions & 0 deletions pkg/preference/preference.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ const (

// DefaultRegistryCacheTime is time (in minutes) for how long odo will cache information from Devfile registry
DefaultRegistryCacheTime = 15

// EphermeralSourceVolume specifies if ephermeral volumes needs to be used as source volume.
EphermeralSourceVolume = "ephermeral"
)

// TimeoutSettingDescription is human-readable description for the timeout setting
Expand Down Expand Up @@ -154,6 +157,8 @@ type OdoSettings struct {

// RegistryCacheTime how long odo should cache information from registry
RegistryCacheTime *int `yaml:"RegistryCacheTime,omitempty"`

EphermeralSourceVolume *bool `yaml:"ephermeral,omitempty"`
}

// Registry includes the registry metadata
Expand Down Expand Up @@ -481,6 +486,12 @@ func (c *PreferenceInfo) GetUpdateNotification() bool {
return util.GetBoolOrDefault(c.OdoSettings.UpdateNotification, true)
}

// GetEphermeralSourceVolume returns the value of ephermeral from preferences
// and if absent then returns default
func (c *PreferenceInfo) GetEphermeralSourceVolume() bool {
return util.GetBoolOrDefault(c.OdoSettings.EphermeralSourceVolume, false)
}

// GetNamePrefix returns the value of Prefix from preferences
// and if absent then returns default
func (c *PreferenceInfo) GetNamePrefix() string {
Expand Down
6 changes: 2 additions & 4 deletions pkg/storage/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -605,10 +605,8 @@ func DevfileListMounted(kClient *kclient.Client, componentName string) (StorageL
return StorageList{}, nil
}

var labels = make(map[string]string)
labels[storagelabels.SourcePVCLabel] = "odo-projects"
labels["component"] = componentName
selector := util.ConvertLabelsToSelector(labels)
selector := fmt.Sprintf("component=%s,%s!=odo-projects", componentName, storagelabels.SourcePVCLabel)

pvcs, err := kClient.ListPVCs(selector)
if err != nil {
return StorageList{}, errors.Wrapf(err, "unable to get PVC using selector %v", storagelabels.StorageLabel)
Expand Down

0 comments on commit cbed088

Please sign in to comment.