github.com/mirantis/virtlet@v1.5.2-0.20191204181327-1659b8a48e9b/pkg/libvirttools/filesystem_volumesource.go (about)

     1  /*
     2  Copyright 2018 Mirantis
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  you may not use this file except in compliance with the License.
     6  You may obtain a copy of the License at
     7  
     8      http://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    16  
    17  package libvirttools
    18  
    19  import (
    20  	"fmt"
    21  	"path"
    22  	"strings"
    23  
    24  	"github.com/Mirantis/virtlet/pkg/metadata/types"
    25  )
    26  
    27  // GetFileSystemVolumes using prepared by kubelet volumes and contained in pod sandbox
    28  // annotations prepares volumes to be passed to libvirt as a DomainFileSystem definitions.
    29  func GetFileSystemVolumes(config *types.VMConfig, owner volumeOwner) ([]VMVolume, error) {
    30  	var fsVolumes []VMVolume
    31  	for index, mount := range config.Mounts {
    32  		if isRegularFile(mount.HostPath) ||
    33  			strings.Contains(mount.HostPath, flexvolumeSubdir) ||
    34  			strings.Contains(mount.HostPath, "kubernetes.io~secret") ||
    35  			strings.Contains(mount.HostPath, "kubernetes.io~configmap") {
    36  			continue
    37  		}
    38  
    39  		// `Index` is used to avoid causing conflicts as multiple host paths can have the same `path.Base`
    40  		volumeDirName := fmt.Sprintf("virtlet_%s_%s_%d", config.DomainUUID, path.Base(mount.HostPath), index)
    41  		volumeMountPoint := path.Join(owner.SharedFilesystemPath(), volumeDirName)
    42  		fsVolume := &filesystemVolume{
    43  			volumeBase:       volumeBase{config, owner},
    44  			mount:            mount,
    45  			volumeMountPoint: volumeMountPoint,
    46  			chownRecursively: config.ParsedAnnotations.VirtletChown9pfsMounts,
    47  		}
    48  		fsVolumes = append(fsVolumes, fsVolume)
    49  	}
    50  
    51  	return fsVolumes, nil
    52  }