forked from devfile/devworkspace-operator
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix devfile#1097 Signed-off-by: Andrew Obuchowicz <aobuchow@redhat.com>
- Loading branch information
Showing
4 changed files
with
96 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
// | ||
// Copyright (c) 2019-2023 Red Hat, Inc. | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
|
||
package workspace | ||
|
||
import ( | ||
"github.com/devfile/api/v2/pkg/apis/workspaces/v1alpha2" | ||
|
||
"github.com/devfile/devworkspace-operator/pkg/common" | ||
) | ||
|
||
// Adds a Devfile volume to the DevWorkspaceTemplateSpec and mounts the volume to `/home/user/` for every | ||
// container component defined in the DevWorkspaceTemplateSpec by adding additional volumeMounts. | ||
// The DevWorkspaceTemplateSpec remains unchanged if any of its container components already mount a volume to `/home/user/`. | ||
func AddHomeVolumeAndVolumeMount(devWorkspaceTemplateSpec *v1alpha2.DevWorkspaceTemplateSpec) { | ||
homeUserDirPath := "/home/user/" | ||
homeVolumeName := "persistentHome" | ||
|
||
homeVolume := v1alpha2.Component{ | ||
Name: homeVolumeName, | ||
ComponentUnion: v1alpha2.ComponentUnion{ | ||
Volume: &v1alpha2.VolumeComponent{}, | ||
}, | ||
} | ||
homeVolumeMount := v1alpha2.VolumeMount{ | ||
Name: homeVolumeName, | ||
Path: homeUserDirPath, | ||
} | ||
|
||
for _, component := range devWorkspaceTemplateSpec.Components { | ||
if component.Container == nil { | ||
continue | ||
} | ||
for _, volumeMount := range component.Container.VolumeMounts { | ||
if volumeMount.Path == homeUserDirPath { | ||
// If a volume is already being mounted to /home/user/, it takes precedence | ||
// over the DWO-provisioned home directory volume. | ||
return | ||
} | ||
} | ||
} | ||
|
||
devWorkspaceTemplateSpec.Components = append(devWorkspaceTemplateSpec.Components, homeVolume) | ||
for _, component := range devWorkspaceTemplateSpec.Components { | ||
if component.Container == nil { | ||
continue | ||
} | ||
component.Container.VolumeMounts = append(component.Container.VolumeMounts, homeVolumeMount) | ||
} | ||
} | ||
|
||
func NeedsPersistentHomeDirectory(workspace *common.DevWorkspaceWithConfig) bool { | ||
return *workspace.Config.Workspace.PersistUserHome.Enabled | ||
} |