Skip to content
This repository was archived by the owner on Apr 1, 2026. It is now read-only.
Merged
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
13 changes: 0 additions & 13 deletions pkg/devfile/adapters/common/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,6 @@ type AdapterContext struct {
Devfile devfileParser.DevfileObj // Devfile is the object returned by the Devfile parser
}

// DevfileVolume is a struct for Devfile volume that is common to all the adapters
type DevfileVolume struct {
Name string
ContainerPath string
Size string
}

// Storage is a struct that is common to all the adapters
type Storage struct {
Name string
Volume DevfileVolume
}

// PushParameters is a struct containing the parameters to be used when pushing to a devfile component
type PushParameters struct {
Path string // Path refers to the parent folder containing the source code to push up to a component
Expand Down
38 changes: 0 additions & 38 deletions pkg/devfile/adapters/common/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ import (
"k8s.io/klog"

devfilev1 "github.com/devfile/api/v2/pkg/apis/workspaces/v1alpha2"
devfileParser "github.com/devfile/library/pkg/devfile/parser"
parsercommon "github.com/devfile/library/pkg/devfile/parser/data/v2/common"
"github.com/openshift/odo/pkg/envinfo"
)

// PredefinedDevfileCommands encapsulates constants for predefined devfile commands
Expand Down Expand Up @@ -132,42 +130,6 @@ func getCommandsByGroup(commands []devfilev1.Command, groupType devfilev1.Comman
return filteredCommands
}

// GetVolumes iterates through the components in the devfile and returns a map of container name to the devfile volumes
func GetVolumes(devfileObj devfileParser.DevfileObj) (map[string][]DevfileVolume, error) {
containerComponents, err := devfileObj.Data.GetDevfileContainerComponents(parsercommon.DevfileOptions{})
if err != nil {
return nil, err
}
volumeComponents, err := devfileObj.Data.GetDevfileVolumeComponents(parsercommon.DevfileOptions{})
if err != nil {
return nil, err
}

// containerNameToVolumes is a map of the Devfile container name to the Devfile container Volumes
containerNameToVolumes := make(map[string][]DevfileVolume)
for _, containerComp := range containerComponents {
for _, volumeMount := range containerComp.Container.VolumeMounts {
size := DefaultVolumeSize

// check if there is a volume component name against the container component volume mount name
for _, volumeComp := range volumeComponents {
if volumeComp.Name == volumeMount.Name && len(volumeComp.Volume.Size) > 0 {
// If there is a volume size mentioned in the devfile, use it
size = volumeComp.Volume.Size
}
}

vol := DevfileVolume{
Name: volumeMount.Name,
ContainerPath: envinfo.GetVolumeMountPath(volumeMount),
Size: size,
}
containerNameToVolumes[containerComp.Name] = append(containerNameToVolumes[containerComp.Name], vol)
}
}
return containerNameToVolumes, nil
}

// IsRestartRequired checks if restart required for run command
func IsRestartRequired(hotReload bool, runModeChanged bool) bool {
if runModeChanged || !hotReload {
Expand Down
155 changes: 0 additions & 155 deletions pkg/devfile/adapters/common/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,161 +13,6 @@ import (
"github.com/devfile/library/pkg/testingutil"
)

func TestGetVolumes(t *testing.T) {

size := "4Gi"

tests := []struct {
name string
component []devfilev1.Component
wantContainerNameToVolumes map[string][]DevfileVolume
wantErr bool
}{
{
name: "Case 1: Valid devfile with container referencing a volume component",
component: []devfilev1.Component{testingutil.GetFakeContainerComponent("comp1"), testingutil.GetFakeVolumeComponent("myvolume1", size)},
wantContainerNameToVolumes: map[string][]DevfileVolume{
"comp1": {
{
Name: "myvolume1",
Size: size,
ContainerPath: "/my/volume/mount/path1",
},
},
},
},
{
name: "Case 2: Valid devfile with container referencing multiple volume components",
component: []devfilev1.Component{
testingutil.GetFakeVolumeComponent("myvolume1", size),
testingutil.GetFakeVolumeComponent("myvolume2", size),
testingutil.GetFakeVolumeComponent("myvolume3", size),
{
Name: "mycontainer",
ComponentUnion: devfilev1.ComponentUnion{
Container: &devfilev1.ContainerComponent{
Container: devfilev1.Container{
Image: "image",
VolumeMounts: []devfilev1.VolumeMount{
{
Name: "myvolume1",
Path: "/myvolume1",
},
{
Name: "myvolume2",
Path: "/myvolume2",
},
},
},
},
},
},
},
wantContainerNameToVolumes: map[string][]DevfileVolume{
"mycontainer": {
{
Name: "myvolume1",
Size: size,
ContainerPath: "/myvolume1",
},
{
Name: "myvolume2",
Size: size,
ContainerPath: "/myvolume2",
},
},
},
},
{
name: "Case 3: Valid devfile with container referencing no volume component",
component: []devfilev1.Component{testingutil.GetFakeContainerComponent("comp1"), testingutil.GetFakeVolumeComponent("myvolume2", size)},
wantContainerNameToVolumes: map[string][]DevfileVolume{
"comp1": {
{
Name: "myvolume1",
Size: "1Gi",
ContainerPath: "/my/volume/mount/path1",
},
},
},
},
{
name: "Case 4: Valid devfile with no container volume mounts",
component: []devfilev1.Component{
testingutil.GetFakeVolumeComponent("myvolume2", size),
{
Name: "mycontainer",
ComponentUnion: devfilev1.ComponentUnion{
Container: &devfilev1.ContainerComponent{
Container: devfilev1.Container{
Image: "image",
},
},
},
},
},
wantContainerNameToVolumes: map[string][]DevfileVolume{},
},
{
name: "Case 5: Valid devfile with container referencing no volume mount path",
component: []devfilev1.Component{
testingutil.GetFakeVolumeComponent("myvolume1", size),
{
Name: "mycontainer",
ComponentUnion: devfilev1.ComponentUnion{
Container: &devfilev1.ContainerComponent{
Container: devfilev1.Container{
Image: "image",
VolumeMounts: []devfilev1.VolumeMount{
{
Name: "myvolume1",
},
},
},
},
},
},
},
wantContainerNameToVolumes: map[string][]DevfileVolume{
"mycontainer": {
{
Name: "myvolume1",
Size: "4Gi",
ContainerPath: "/myvolume1",
},
},
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
devObj := devfileParser.DevfileObj{
Data: func() data.DevfileData {
devfileData, err := data.NewDevfileData(string(data.APIVersion200))
if err != nil {
t.Error(err)
}
err = devfileData.AddComponents(tt.component)
if err != nil {
t.Error(err)
}
return devfileData
}(),
}

containerNameToVolumes, err := GetVolumes(devObj)
if (err != nil) != tt.wantErr {
t.Errorf("GetVolumes() error = %v, wantErr %v", err, tt.wantErr)
}

if !reflect.DeepEqual(containerNameToVolumes, tt.wantContainerNameToVolumes) {
t.Errorf("TestGetVolumes error - got %v wanted %v", containerNameToVolumes, tt.wantContainerNameToVolumes)
}
})
}

}

func TestIsEnvPresent(t *testing.T) {

envName := "myenv"
Expand Down
24 changes: 5 additions & 19 deletions pkg/devfile/adapters/docker/component/adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
devfilev1 "github.com/devfile/api/v2/pkg/apis/workspaces/v1alpha2"
"github.com/openshift/odo/pkg/devfile/adapters/common"

"github.com/openshift/odo/pkg/devfile/adapters/docker/storage"
"github.com/openshift/odo/pkg/devfile/adapters/docker/utils"
"github.com/openshift/odo/pkg/lclient"
"github.com/openshift/odo/pkg/log"
Expand All @@ -33,14 +32,11 @@ type Adapter struct {
Client lclient.Client
*common.GenericAdapter

containerNameToVolumes map[string][]common.DevfileVolume
uniqueStorage []common.Storage
volumeNameToDockerVolName map[string]string
devfileBuildCmd string
devfileRunCmd string
supervisordVolumeName string
projectVolumeName string
containers []types.Container
devfileBuildCmd string
devfileRunCmd string
supervisordVolumeName string
projectVolumeName string
containers []types.Container
}

// getPod lazily records and retrieves the containers associated with the component associated with this adapter
Expand Down Expand Up @@ -87,16 +83,6 @@ func (a Adapter) Push(parameters common.PushParameters) (err error) {
return errors.Wrapf(err, "unable to determine if component %s exists", a.ComponentName)
}

// Process the volumes defined in the devfile
a.containerNameToVolumes, err = common.GetVolumes(a.Devfile)
if err != nil {
return err
}
a.uniqueStorage, a.volumeNameToDockerVolName, err = storage.ProcessVolumes(&a.Client, a.ComponentName, a.containerNameToVolumes)
if err != nil {
return errors.Wrapf(err, "unable to process volumes for component %s", a.ComponentName)
}

a.devfileBuildCmd = parameters.DevfileBuildCmd
a.devfileRunCmd = parameters.DevfileRunCmd

Expand Down
17 changes: 0 additions & 17 deletions pkg/devfile/adapters/docker/component/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,6 @@ func (a Adapter) createComponent() (err error) {
// Loop over each container component and start a container for it
for _, comp := range containerComponents {
var dockerVolumeMounts []mount.Mount
for _, vol := range a.containerNameToVolumes[comp.Name] {

volMount := mount.Mount{
Type: mount.TypeVolume,
Source: a.volumeNameToDockerVolName[vol.Name],
Target: vol.ContainerPath,
}
dockerVolumeMounts = append(dockerVolumeMounts, volMount)
}
err = a.pullAndStartContainer(dockerVolumeMounts, comp)
if err != nil {
return errors.Wrapf(err, "unable to pull and start container %s for component %s", comp.Name, componentName)
Expand Down Expand Up @@ -83,14 +74,6 @@ func (a Adapter) updateComponent() (componentExists bool, err error) {
}

var dockerVolumeMounts []mount.Mount
for _, vol := range a.containerNameToVolumes[comp.Name] {
volMount := mount.Mount{
Type: mount.TypeVolume,
Source: a.volumeNameToDockerVolName[vol.Name],
Target: vol.ContainerPath,
}
dockerVolumeMounts = append(dockerVolumeMounts, volMount)
}
if len(containers) == 0 {
log.Infof("\nCreating Docker resources for component %s", a.ComponentName)

Expand Down
24 changes: 0 additions & 24 deletions pkg/devfile/adapters/docker/storage/adapter.go

This file was deleted.

1 change: 0 additions & 1 deletion pkg/devfile/adapters/docker/storage/adapter_test.go

This file was deleted.

Loading