Skip to content

Commit

Permalink
Look for specific file instead of first file.
Browse files Browse the repository at this point in the history
Instead of listing the mounted VDDK arguments directory and filtering
out hidden files, just hard-code the expected file name and ConfigMap
key.

Signed-off-by: Matthew Arnold <[email protected]>
  • Loading branch information
mrnold committed Jan 7, 2025
1 parent fa0a87a commit 0fe6322
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 20 deletions.
2 changes: 1 addition & 1 deletion doc/datavolumes.md
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ spec:

#### Extra VDDK Configuration Options

The VDDK library itself looks in a configuration file (such as `/etc/vmware/config`) for extra options to fine tune data transfers. To pass these options through to the VDDK, store the configuration file contents in a ConfigMap and add a `cdi.kubevirt.io/storage.pod.vddk.extraargs` annotation to the DataVolume specification. The ConfigMap will be mounted to the importer pod as a volume, and the first file in the mounted directory will be passed to the VDDK. This means that the ConfigMap must be placed in the same namespace as the DataVolume, and the ConfigMap should only have one file entry.
The VDDK library itself looks in a configuration file (such as `/etc/vmware/config`) for extra options to fine tune data transfers. To pass these options through to the VDDK, store the configuration file contents in a ConfigMap with the key `vddk-config-file` and add a `cdi.kubevirt.io/storage.pod.vddk.extraargs` annotation to the DataVolume specification. The ConfigMap will be mounted to the importer pod as a volume, and the mount directory will have a file named `vddk-config-file` with the contents of the file. This means that the ConfigMap must be placed in the same namespace as the DataVolume, and the ConfigMap should only have one file entry, `vddk-config-file`.

[Example annotation](../manifests/example/vddk-args-annotation.yaml)
[Example ConfigMap](../manifests/example/vddk-args-configmap.yaml)
Expand Down
4 changes: 4 additions & 0 deletions pkg/common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,10 @@ const (
AwaitingVDDK = "AwaitingVDDK"
// VddkArgsDir is the path to the volume mount containing extra VDDK arguments
VddkArgsDir = "/vddk-args"
// VddkArgsVolName is the name of the volume referencing the extra VDDK arguments ConfigMap
VddkArgsVolName = "vddk-extra-args"
// VddkArgsKeyName is the name of the key that must be present in the VDDK arguments ConfigMap
VddkArgsKeyName = "vddk-config-file"

// UploadContentTypeHeader is the header upload clients may use to set the content type explicitly
UploadContentTypeHeader = "x-cdi-content-type"
Expand Down
4 changes: 2 additions & 2 deletions pkg/controller/import-controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -1009,7 +1009,7 @@ func makeImporterContainerSpec(args *importerPodArgs) []corev1.Container {
}
if args.vddkExtraArgs != nil {
containers[0].VolumeMounts = append(containers[0].VolumeMounts, corev1.VolumeMount{
Name: VddkArgsVolName,
Name: common.VddkArgsVolName,
MountPath: common.VddkArgsDir,
})
}
Expand Down Expand Up @@ -1086,7 +1086,7 @@ func makeImporterVolumeSpec(args *importerPodArgs) []corev1.Volume {
}
if args.vddkExtraArgs != nil {
volumes = append(volumes, corev1.Volume{
Name: VddkArgsVolName,
Name: common.VddkArgsVolName,
VolumeSource: corev1.VolumeSource{
ConfigMap: &v1.ConfigMapVolumeSource{
LocalObjectReference: v1.LocalObjectReference{
Expand Down
3 changes: 0 additions & 3 deletions pkg/controller/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,6 @@ const (
//nolint:gosec // This is not a real secret
SecretVolName = "cdi-secret-vol"

// VddkArgsVolName is the name of the volume referencing the extra VDDK arguments ConfigMap
VddkArgsVolName = "vddk-extra-args"

// AnnOwnerRef is used when owner is in a different namespace
AnnOwnerRef = cc.AnnAPIGroup + "/storage.ownerRef"

Expand Down
17 changes: 4 additions & 13 deletions pkg/image/nbdkit.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"bufio"
"fmt"
"io"
"io/fs"
"os"
"os/exec"
"path/filepath"
Expand Down Expand Up @@ -240,23 +239,15 @@ func getVddkPluginPath() NbdkitPlugin {
// importer pod. Just look for the first file in the mounted directory, and
// pass that through nbdkit via the "config=" option.
func getVddkConfig() (string, error) {
withHidden, err := os.ReadDir(common.VddkArgsDir)
path := filepath.Join(common.VddkArgsDir, common.VddkArgsKeyName)
_, err := os.Stat(path)
if err != nil {
if os.IsNotExist(err) { // No extra arguments ConfigMap specified, so mount directory does not exist
if os.IsNotExist(err) { // No configuration file found, so no extra arguments to give to VDDK
return "", nil
}
return "", err
}
files := []fs.DirEntry{}
for _, file := range withHidden { // Ignore hidden files
if !strings.HasPrefix(file.Name(), ".") {
files = append(files, file)
}
}
if len(files) < 1 {
return "", fmt.Errorf("no VDDK configuration files found under %s", common.VddkArgsDir)
}
path := filepath.Join(common.VddkArgsDir, files[0].Name())

return path, nil
}

Expand Down
2 changes: 1 addition & 1 deletion tests/datavolume_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1192,7 +1192,7 @@ var _ = Describe("[vendor:[email protected]][level:component]DataVolume tests",
Name: "vddk-extra-args-map",
},
Data: map[string]string{ // Must match vddk-test-plugin
"vddk-config-file": "VixDiskLib.nfcAio.Session.BufSizeIn64KB=16",
common.VddkArgsKeyName: "VixDiskLib.nfcAio.Session.BufSizeIn64KB=16",
},
}
_, err := f.K8sClient.CoreV1().ConfigMaps(f.Namespace.Name).Create(context.TODO(), &extraArguments, metav1.CreateOptions{})
Expand Down

0 comments on commit 0fe6322

Please sign in to comment.