Commit Graph

205 Commits

Author SHA1 Message Date
Arnon Gilboa
f4cbf296e3
Fix ImagePullFailed handling in DIC controller (#3576)
Add DataVolume not-Running condition reason ImagePullFailedReason for
DataImportCron controller deletion of erroneous DVs.

In [test_id:8266] we exercise this flow by injecting a nonexistent
digest for the registry import, which did not lead us to the
ImagePullFailed flow but the usual GenericError one, as the container
status got the InvalidImageName reason because the digest was not 64
long. Fixed that.

Added InvalidImageName reason as a trigger of ImagePullFailed as
well.

Signed-off-by: Arnon Gilboa <agilboa@redhat.com>
2025-01-01 16:22:18 +01:00
Alexander Wels
a12446110b
Ensure scratch space is large enough to hold disk image (#3384)
* Ensure scratch space is large enough to hold disk image

It is possible the source image is fully allocated
and in that case the scratch space would not be large
enough to hold the disk image. This takes fsOverhead
into account when calculating the scratch space size.

Signed-off-by: Alexander Wels <awels@redhat.com>

* Fix bug when copying the size of the pvc for the scratchspace
This was not copying but re-using the same struct. This caused the
size of the regular PVC to be overwritten by the scratchspace PVC
in certain conditions.

Use storage stanza instead of pvc stanza in the cloner tests.

Signed-off-by: Alexander Wels <awels@redhat.com>

---------

Signed-off-by: Alexander Wels <awels@redhat.com>
2024-09-03 07:38:09 +02:00
Michael Henriksen
073336b16c
Make upload client/server certs configurable (#3252)
* Add client cert config to CDI resource

Signed-off-by: Michael Henriksen <mhenriks@redhat.com>

* make client certs configurable

Signed-off-by: Michael Henriksen <mhenriks@redhat.com>

* Create uploadserver.Config

Signed-off-by: Michael Henriksen <mhenriks@redhat.com>

* uploadserver should read certs from files

Signed-off-by: Michael Henriksen <mhenriks@redhat.com>

* make sure to not close doneChan when error occurs

generally tighten up handling of "done" "uploading" and "processing"

Signed-off-by: Michael Henriksen <mhenriks@redhat.com>

* add deadline support to uploadserver

Signed-off-by: Michael Henriksen <mhenriks@redhat.com>

* Add deadline support to upload controller

Signed-off-by: Michael Henriksen <mhenriks@redhat.com>

* clone controller should use configured client cert duration

Signed-off-by: Michael Henriksen <mhenriks@redhat.com>

* make lint check happy

Signed-off-by: Michael Henriksen <mhenriks@redhat.com>

* Extend existing func test to validate client certs configurable and will be rotated

Signed-off-by: Michael Henriksen <mhenriks@redhat.com>

* Use deadline/rotation for clone pods as well

Forgot about the case where a source PVC may be in use.  Bay be a big delay from when target pod is created and source.

Signed-off-by: Michael Henriksen <mhenriks@redhat.com>

---------

Signed-off-by: Michael Henriksen <mhenriks@redhat.com>
2024-06-03 22:39:34 +02:00
Edu Gómez Escandell
8bd9355fd1
Enable Gosec linter (#3283)
* Move gosec into golangci-lint

Remove gosec target and scripts and use the golangci-lint linter
This ensures we stay up-to-date (so long as golangci-lint is up to date
too).

Signed-off-by: Edu Gómez Escandell <egomez@redhat.com>

* G601: Disable for-loop variable aliassing warning (not relevant fro Go>=1.22)

Signed-off-by: Edu Gómez Escandell <egomez@redhat.com>

* G101: Ignore warning about plain-text credentials

They are false positives

Signed-off-by: Edu Gómez Escandell <egomez@redhat.com>

* G102: Don't listen to all interfaces

Signed-off-by: Edu Gómez Escandell <egomez@redhat.com>

* G107: Ignore potentially tainted GET requests

They are all in test code

Signed-off-by: Edu Gómez Escandell <egomez@redhat.com>

* G109: Avoid integer overflows after parsing strings

Signed-off-by: Edu Gómez Escandell <egomez@redhat.com>

* G110: Potential DoS vulnerability via decompression bomb

Signed-off-by: Edu Gómez Escandell <egomez@redhat.com>

* G112: Potential Slowloris Attack because ReadHeaderTimeout is not configured

Signed-off-by: Edu Gómez Escandell <egomez@redhat.com>

* G114: Use of net/http serve function that has no support for setting timeouts

Signed-off-by: Edu Gómez Escandell <egomez@redhat.com>

* G204: Subprocess launched with a potential tainted input or cmd arguments

Signed-off-by: Edu Gómez Escandell <egomez@redhat.com>

* G305: File traversal when extracting zip/tar archive

Signed-off-by: Edu Gómez Escandell <egomez@redhat.com>

* G306: Expect WriteFile permissions to be 0600 or less

Signed-off-by: Edu Gómez Escandell <egomez@redhat.com>

* Bugfix: Misuse of file descriptor flags in file permission bits

os.WriteFile always uses O_WRONLY|O_CREATE|O_TRUNC, the third argument
is for the file's permission bits. This code is misleading, it will
truncate the file and not append to it. For that you'd need
os.Openfile(path, os.O_APPEND, 0600)

I also simplified the unnecessary []byte conversion.

Signed-off-by: Edu Gómez Escandell <egomez@redhat.com>

* G401: Use of weak cryptographic primitive

Signed-off-by: Edu Gómez Escandell <egomez@redhat.com>

* G402: Insecure TLS

Signed-off-by: Edu Gómez Escandell <egomez@redhat.com>

* G404: Use of weak random number generator (math/rand instead of crypto/rand)

Signed-off-by: Edu Gómez Escandell <egomez@redhat.com>

* G501: Blocklisted import crypto/md5: weak cryptographic primitive

Signed-off-by: Edu Gómez Escandell <egomez@redhat.com>

* Run autoformatters

Unrelated to the PR but this way we keep everything formatted

Signed-off-by: Edu Gómez Escandell <egomez@redhat.com>

* Remove references to gosec in the makefile

Gosec has been moved into Golangci-lint

Signed-off-by: Edu Gómez Escandell <egomez@redhat.com>

---------

Signed-off-by: Edu Gómez Escandell <egomez@redhat.com>
2024-05-30 16:29:33 +02:00
Edu Gómez Escandell
0e750262a3
Enable autoformatting linters (#3179)
* Enable gofmt linter

From the docs:

> Gofmt checks whether code was gofmt-ed. By default this tool runs with
> -s option to check for code simplification.

https://golangci-lint.run/usage/linters/#gofmt

Signed-off-by: Edu Gómez Escandell <egomez@redhat.com>

* Run gomft on the project

Ran this command after adding the gofmt linter:

	golangci-lint run ./... --fix

Signed-off-by: Edu Gómez Escandell <egomez@redhat.com>

* Enable whitespace linter

From the docs:
> Whitespace is a linter that checks for unnecessary newlines at the
> start and end of functions, if, for, etc.

https://golangci-lint.run/usage/linters/#whitespace

Signed-off-by: Edu Gómez Escandell <egomez@redhat.com>

* Run whitespace on the project

Ran this command after adding the whitespace linter:

	golangci-lint run ./... --fix

Signed-off-by: Edu Gómez Escandell <egomez@redhat.com>

* Enable GCI linter

Per the docs:

> Gci controls Go package import order and makes it always deterministic.

https://golangci-lint.run/usage/linters/#gci

NOTE: I noticed that many files separate their imports in a particular
way, so I set the linter to enforce this standard.

Signed-off-by: Edu Gómez Escandell <egomez@redhat.com>

* Run GCI on the project

Ran this command after adding the GCI linter:

	golangci-lint run ./... --fix

Signed-off-by: Edu Gómez Escandell <egomez@redhat.com>

---------

Signed-off-by: Edu Gómez Escandell <egomez@redhat.com>
2024-04-24 13:52:22 +02:00
Nahshon Unna Tsameret
475a70c8cd
Add new DV reason: ImagePullFailed (#3194)
When the image pull fails, the DataVolume Running condition, will have
the Reason field of `ImagePullFailed`, to allow better error handling in
code taht uses it.

Signed-off-by: Nahshon Unna-Tsameret <nunnatsa@redhat.com>
2024-04-18 19:35:59 +02:00
Felix Matouschek
3239d50b4e
cleanup: Return modified labels added from termination message (#3147)
Instead of changing the labels map that is passed in as parameter to the
setLabelsFromTerminationMessage function, it now returns a modified copy
of the passed in labels map and is renamed to
addLabelsFromTerminationMessage. If the passed in map is nil a new map
will be allocated and initialized.

Signed-off-by: Felix Matouschek <fmatouschek@redhat.com>
2024-03-27 07:33:28 +01:00
Felix Matouschek
ca8085a25c
feat(import): Set PVC labels derived from env vars on containerdisks (#3103)
* feat(cdi-containerimage-server): Add info endpoint

The info endpoint returns a ServerInfo object containing all
environment variables of the server serialized to json. This allows the
extraction of env vars from a containerdisk when using pullMethod node.

Signed-off-by: Felix Matouschek <fmatouschek@redhat.com>

* feat(importer): Add conversion of env vars to label

This adds the conversion of env vars containing KUBEVIRT_IO_ to a label
key/value pair.

Example: TEST_KUBEVIRT_IO_TEST=testvalue becomes test.kubevirt.io/test:
testvalue.

Signed-off-by: Felix Matouschek <fmatouschek@redhat.com>

* feat(importer): Extract labels from registry datasource

This allows the registry-datasource to return a termination message with
labels extracted from the env vars of a source containerdisk when using
pullMethod pod.

Signed-off-by: Felix Matouschek <fmatouschek@redhat.com>

* feat(importer): Extract labels from http datasource

This allows the http-datasource to return a termination message with
labels extracted from the env vars of a source containerdisk when using
pullMethod node.

Signed-off-by: Felix Matouschek <fmatouschek@redhat.com>

* feat(controller): Set PVC labels from importer termination message

With this change the import-controller is able set labels on destination
PVCs returned from the importer in its termination message.

Signed-off-by: Felix Matouschek <fmatouschek@redhat.com>

* tests: Add tests for conversion of containerdisk env vars to PVC labels

This adds tests for the conversion of containerdisk env vars to PVC
labels for both pullMethods pod and node.

Signed-off-by: Felix Matouschek <fmatouschek@redhat.com>

* fix: Fix race in import-populator

By running reconcileTargetPVC of populatorController on every reconcile
cycle, the import-populator controller is able to retry seting labels and
annotations on the target PVC when import-controller modified the target
PVC at the same time.

Signed-off-by: Felix Matouschek <fmatouschek@redhat.com>

---------

Signed-off-by: Felix Matouschek <fmatouschek@redhat.com>
2024-03-21 23:13:16 +01:00
Felix Matouschek
cd7ee9e9b3
feat: Make importer datasource communication explicit (#3101)
Make the communication of datasources in the importer explicit by adding
a GetTerminationMessage method to the DataSourceInterface.
Then use this method to communicate additional information to the import
controller once the importer pod has terminated, instead of writing
additional data to the termination message in the Close method of
datasources.

Signed-off-by: Felix Matouschek <fmatouschek@redhat.com>
2024-03-13 22:09:23 +01:00
alromeros
aff18f09e4
Address error condition when scratch space is needed to avoid VM failures (#2945)
When scratch space is needed during imports/uploads, the pod typically fails so it can be restarted with the required space. This is expected behavior that's automatically handled by CDI.

However, since we use an error exit code, this behavior leads to unwanted VM statuses during provisioning in Kubevirt.

This commit addresses this behavior by using a different DV condition, so kubevirt ignores it and the VM can be provisioned as expected.

Signed-off-by: Alvaro Romero <alromero@redhat.com>
2023-10-31 03:26:24 +01:00
Shelly Kagan
533a725d40
Allow ImmediateBinding annotation when using populators (#2765)
* Allow ImmediateBind annotation when using populators

In case of using PVC with populators if the PVC has this
annotation we prevent from waiting for it to be schedueled
and we proceed with the process.
When using datavolumes with populators in case the dv has the annotation
it will be passed to the PVC. we prevent from being in pendingPopulation
in case the created pvc has the annotaion.
Plus when having honorWaitForFirstConsumer feature gate disabled we will
put on the target PVC the immediateBind annotation.
Now we allow to use populators when having the annotation the the
feature gate disabled.

Signed-off-by: Shelly Kagan <skagan@redhat.com>

* Add functional tests to population using PVCs

Signed-off-by: Shelly Kagan <skagan@redhat.com>

* Support immediate binding with clone datavolume

Signed-off-by: Shelly Kagan <skagan@redhat.com>

* Pass allowed annotations from target pvc to pvc prime

This annotations are used for the import/upload/clone
pods to define netork configurations.

Signed-off-by: Shelly Kagan <skagan@redhat.com>

---------

Signed-off-by: Shelly Kagan <skagan@redhat.com>
2023-07-10 01:05:04 +02:00
Michael Henriksen
f88fab69dc
PVC Clone Populator (#2709)
* touch up zero restoresize snapshot

Signed-off-by: Michael Henriksen <mhenriks@redhat.com>

* clone populator

only supports PVC source now

snapshot coming soon

Signed-off-by: Michael Henriksen <mhenriks@redhat.com>

* more unit tests

Signed-off-by: Michael Henriksen <mhenriks@redhat.com>

* unit test for clone populator

Signed-off-by: Michael Henriksen <mhenriks@redhat.com>

* func tests for clone populator

Signed-off-by: Michael Henriksen <mhenriks@redhat.com>

* move clone populator cleanup function to planner

other review comments

verifier pod should bount readonly

Signed-off-by: Michael Henriksen <mhenriks@redhat.com>

* add readonly flag to test executor pods

synchronize get hash calls

Signed-off-by: Michael Henriksen <mhenriks@redhat.com>

* increase linter timeout

Signed-off-by: Michael Henriksen <mhenriks@redhat.com>

* better/explicit readonly support for test pods

Signed-off-by: Michael Henriksen <mhenriks@redhat.com>

* check pv for driver info before looking up storageclass as it may not exist

Signed-off-by: Michael Henriksen <mhenriks@redhat.com>

* addressed review comments

Signed-off-by: Michael Henriksen <mhenriks@redhat.com>

* chooseStrategy shoud generate more events

Signed-off-by: Michael Henriksen <mhenriks@redhat.com>

---------

Signed-off-by: Michael Henriksen <mhenriks@redhat.com>
2023-05-24 05:11:52 +02:00
alromeros
c5f767d910
Import populator (#2690)
* Create populators package to be used for all populators

This commit introduces the basic reconciler for
populators with common function that can be used
by the different populators.

Signed-off-by: Shelly Kagan <skagan@redhat.com>

* unite getcontenttype func across code

Signed-off-by: Shelly Kagan <skagan@redhat.com>

* Add VolumeImportSource CRD for import populator

This commit adds the VolumeImportSource CRD into CDI.

CRs created from this CRD will be referenced in the dataSourceRef field to populate PVCs with the import populator.

Signed-off-by: Alvaro Romero <alromero@redhat.com>

* Refactor common populator code to be shared among all populators

This commit introduces and modifies several functions so we can reuse common code between all populators.

Other than having a common reconcile function, a new populatorController interface has been introduced so we are able to call populator-specific methods from the populator-base reconciler.

Signed-off-by: Alvaro Romero <alromero@redhat.com>

* Create Import Populator

The import populator is a controller that handles the import of data in PVCs without the need of DataVolumes while still taking advantage of the import-controller flow.

This controller creates an additional PVC' with import annotations. After the import process succeeds, the controller rebinds the PV to the original target PVc and deletes the PVC prime.

Signed-off-by: Alvaro Romero <alromero@redhat.com>

* Add functional tests to cover the import populator flow

This commit updates the import tests to cover the new import populator flow.

Signed-off-by: Alvaro Romero <alromero@redhat.com>

* Add unit tests for import populator

Signed-off-by: Alvaro Romero <alromero@redhat.com>

* Minor fixes and enhancements in import/common populator code

* Modify indexes and other related code to support namespaced dataSourceRefs. Cross-namespace population is still not supported as it depends on alpha feature gates.
* Add functional test to cover static binding.
* Fix selected node annotation bug in scratch space PVCs
* Fix linter alerts

Signed-off-by: Alvaro Romero <alromero@redhat.com>

---------

Signed-off-by: Shelly Kagan <skagan@redhat.com>
Signed-off-by: Alvaro Romero <alromero@redhat.com>
Co-authored-by: Shelly Kagan <skagan@redhat.com>
2023-04-28 00:10:59 +02:00
Marcelo Feitoza Parisi
c7467cc5fd
Google Cloud Storage Import Support (#2615)
* Google Cloud Storage Importer

This is a Google Cloud Storage importer for CDI

Signed-off-by: Marcelo Parisi <marcelo@feitoza.com.br>

* Fix auto-generated swagger and openapi

Signed-off-by: Marcelo Parisi <marcelo@feitoza.com.br>

* GCS Importer General Fixes

Signed-off-by: Marcelo Parisi <marcelo@feitoza.com.br>

* Moving back gcs-secret.txt

Moving file back to imageDir to fix unit testing.

Signed-off-by: Marcelo Parisi <marcelo@feitoza.com.br>

---------

Signed-off-by: Marcelo Parisi <marcelo@feitoza.com.br>
Co-authored-by: Marcelo Parisi <marcelo@dev-box.corp.feitoza.com.br>
2023-03-22 16:49:29 +00:00
akalenyu
4c31a26603
Respect bind.immediate annotation by not attempting fancy clones (#2604)
* Fix hostpath CSI being skipped as "Not HPP"

Signed-off-by: Alex Kalenyuk <akalenyu@redhat.com>

* Fall back to host assisted if immediate bind requested

Signed-off-by: Alex Kalenyuk <akalenyu@redhat.com>

---------

Signed-off-by: Alex Kalenyuk <akalenyu@redhat.com>
2023-03-01 04:44:52 +01:00
Lee Yarwood
f229aeb5ff
dataimportcron: Pass KubeVirt instance type labels to DataVolume and DataSource (#2534)
* dataimportcron: Pass KubeVirt instance type labels to DataVolume and DataSource

Following on from 4fbcb2d509 a requirement
has arisen to expose the default instance type metadata previously
exposed as annotations also as labels to allow callers such as the UI to
have simple server side filtering of these resources.

The unreleased feature implementation in KubeVirt has now
switched to labels and so CDI should now do the same and pass through
the appropriate labels to the underlying resources.

Signed-off-by: Lee Yarwood <lyarwood@redhat.com>

* instancetype: Pass instance type labels from DataVolume to PVC

Unlike annotations not all labels are copied from a given DataVolume to
a PVC during an import. This change corrects this for instance type
labels ensuring they are passed down to the underlying PVC.

The associated constants are also moved into pkg/controller/common/util
to allow access from the DataImportCron and DataVolume controllers.

Signed-off-by: Lee Yarwood <lyarwood@redhat.com>

Signed-off-by: Lee Yarwood <lyarwood@redhat.com>
2023-01-10 17:54:53 +00:00
Lee Yarwood
4fbcb2d509
dataimportcron: Pass KubeVirt instance type annotations to DV and DS (#2490)
A recent design proposal within the KubeVirt community introduced the
idea of inferring the details of default instance type and preferences
from a given volume associated with a VirtualMachine [1]. The idea being
to further reduce the number of choices a user has to make to get a
bootable VirtualMachine to a single choice of a PVC.

This change aims to support this effort by allowing operators to
annotate the underlying DataVolumes, DataSources and PVCs at import time
through CDI by first annotating the initial DataImportCrons.

This is useful to users of CDI such as the KubeVirt SSP operator that
currently defines a number of DataImportCrons to pull in various boot
sources required by the KubeVirt common-templates project.

Both the DataVolume and DataSource associated with the DataImportCron
are annotated to allow KubeVirt to potentially avoid a deeper lookup of
the associated PVC when attempting to infer these defaults.

[1] https://github.com/kubevirt/community/blob/main/design-proposals/default-instancetypes-from-volumes.md

Signed-off-by: Lee Yarwood <lyarwood@redhat.com>

Signed-off-by: Lee Yarwood <lyarwood@redhat.com>
2023-01-04 15:00:47 +00:00
Arnon Gilboa
bfe30a8964
Split and refactor DV controller (#2483)
- Split the huge DV controller into smaller op-specific DV controllers -
  import, clone, upload
- Add common watch-adding function so each controller watches only its
  relevant DVs
- Refactor the common Reconcile() to use interface DataVolumeReconciler
  implemented by each controller
- Move all functions, structs, consts to the relevant controller
- Split the utests per controller

Signed-off-by: Arnon Gilboa <agilboa@redhat.com>

Signed-off-by: Arnon Gilboa <agilboa@redhat.com>
2022-12-22 01:03:15 +00:00
akalenyu
f4978d920b
Bump volumesnapshot client to v6 (#2513)
* make deps-update on clean repo

Signed-off-by: Alex Kalenyuk <akalenyu@redhat.com>

* Bump volumesnapshot client to v6

In case we want to utilize https://kubernetes.io/docs/concepts/storage/volume-snapshots/#convert-volume-mode
new API field sourceVolumeMode.

Signed-off-by: Alex Kalenyuk <akalenyu@redhat.com>

Signed-off-by: Alex Kalenyuk <akalenyu@redhat.com>
2022-12-20 20:07:16 +00:00
Michael Henriksen
46c6aa994a
Support restricted PSA for worker pods (#2410)
* remove root worker pods

Signed-off-by: Michael Henriksen <mhenriks@redhat.com>

* remove selinux requirement for worker pods

Signed-off-by: Michael Henriksen <mhenriks@redhat.com>

* run tests in restricted namespace and required changes

Signed-off-by: Michael Henriksen <mhenriks@redhat.com>

* handle empty tar

Signed-off-by: Michael Henriksen <mhenriks@redhat.com>

* add PSA label when running functional tests in OpenShift

Signed-off-by: Michael Henriksen <mhenriks@redhat.com>

* cannot use restricted PSA with istio (for now)

refactor scc management

Signed-off-by: Michael Henriksen <mhenriks@redhat.com>

* fix clean script

Signed-off-by: Michael Henriksen <mhenriks@redhat.com>

Signed-off-by: Michael Henriksen <mhenriks@redhat.com>
2022-09-14 21:16:23 +01:00
alromeros
db59dcec87
Fix race condition in upload-controller to keep PVC annotations after a clone error (#2363)
* Modify upload-controller to keep the annotations of a PVC if a pod fails in another controller

When a pod fails, some annotations (running condition, pod phase...) are updated in the affected PVC to let other controllers know.

However, due to a lack of synchronization between some controllers, a race condition could happen where, if a pod succeeds just after a pod fails in a different controller, the annotations set in the error handling would just be updated inapropiately.

This commit modifies the upload-controller to check for clone failures before updating annotations.

Signed-off-by: Alvaro Romero <alromero@redhat.com>

* Add unit tests to updateUploadAnnotations

Signed-off-by: Alvaro Romero <alromero@redhat.com>

* Update functional tests in cloner_test to check for conditions and annotations after a pod fails

Signed-off-by: Alvaro Romero <alromero@redhat.com>

* Improve error handling in source-clone pod to avoid overwritting the DV running condition

Signed-off-by: Alvaro Romero <alromero@redhat.com>
2022-08-03 14:50:27 +02:00
alromeros
efe5109ba5
Improve error handling when pod creation fails (#2335)
* Improve the error handling when pod creation fails

When pod creation fails, the error is usually logged without providing additional information to the user. This behavior is especially risky when the user lacks the permits to check the logs, making it unintuitive and almost impossible to find the source of the problem.

This commit improves the error handling of the pod-creation process, so pertinent info about the failure is included in the pod's PVC.

Signed-off-by: Alvaro Romero <alromero@redhat.com>

* Update functional tests to check for events when pod-creation fails

Since error handling in pod-creation has been improved in our controllers, this commit introduces several changes in the corresponding functional tests to properly cover the new behavior included when pod-creation fails.

Signed-off-by: Alvaro Romero <alromero@redhat.com>

* Update unit-tests after improving error-handling of pods for proper coverage

Signed-off-by: Alvaro Romero <alromero@redhat.com>

* Minor fixes and improvements on error handling for pods

Signed-off-by: Alvaro Romero <alromero@redhat.com>

* Modify datavolume-controller to change the running condition of datavolumes when a pod fails

Until this commit, the way of handling pod errors in the datavolume-controller has been to change the affected datavolume's phase to failed, which conflicts with the declarative approach of the controllers.

This commit modifies this behavior so that, when a pod fails, the affected datavolume's running condition is changed to false while the phase remains unchanged.

Signed-off-by: Alvaro Romero <alromero@redhat.com>
2022-07-15 10:28:53 +02:00
Arnon Gilboa
1bf34b578e
Add GC func tests; mutate DV GC annotation only on create (#2326)
Signed-off-by: Arnon Gilboa <agilboa@redhat.com>
2022-06-28 02:32:55 +02:00
Bartosz Rybacki
b58e3924d1
Clone fs to block fails on size validation (#2299)
* Test: Clone fs to block fails on size validation

When requesting size `X` with filesystem volume mode and storage api the size
is increased for the fs overhead. When trying to clone to block using
the same size `X` the clone fails because the target is smaller than source.

Signed-off-by: Bartosz Rybacki <brybacki@redhat.com>

* Improve size validation for clone

Skip size validation for filesystem in webhook and include filesystem
overhead when doing the validation in controller.

Signed-off-by: Bartosz Rybacki <brybacki@redhat.com>

* Correct size validation for smart clone

Signed-off-by: Bartosz Rybacki <brybacki@redhat.com>

* Correct unit test with fs overhead

Signed-off-by: Bartosz Rybacki <brybacki@redhat.com>

* Restore CDI Config after each clone test

Signed-off-by: Bartosz Rybacki <brybacki@redhat.com>

* Review cleanup

Removing redundant conversions and not useful comments

Signed-off-by: Bartosz Rybacki <brybacki@redhat.com>
2022-06-27 15:02:54 +02:00
alromeros
5516641864
Allow creating clones without source PVC (#2306)
* Modify datavolume admission webhook to enable creating clones without source PVC

This commit modifies the datavolume admission webhook to follow a more descriptive approach, enabling the creation of clones without a source PVC.

This clone will later be handled by the datavolume-controller until the source PVC is created.

Signed-off-by: Alvaro Romero <alromero@redhat.com>

* Modify the datavolume-controller to improve the handling of clones without source

Since we are allowing the creation of clones without source PVC in the admission webhook, we need to improve the handling of these clones once in the datavolume-controller.

This commit modifies said controller, so we do proper error handling and validation until the source PVC is created.

Signed-off-by: Alvaro Romero <alromero@redhat.com>

* Add unit tests to check the creation of clones without source PVC

Signed-off-by: Alvaro Romero <alromero@redhat.com>

* Include a mechanism to reconcile clones without source once the source PVC is created

This commit introduces a new datavolume-controller watch so, if a clone without source is created, we make sure to reconcile it once a proper PVC is created.

It also updates/includes unit tests for proper coverage.

Signed-off-by: Alvaro Romero <alromero@redhat.com>

* Include functional tests to cover the creation of clones without source PVC

Signed-off-by: Alvaro Romero <alromero@redhat.com>

* Minor refactoring of clone-related code in DataVolume reconciler to improve readability

After enabling the creation of clones without source PVC in the datavolume controller, the clone-related logic outside its reconciler has increased in size and become sparse.

This commit rearranges all this code and condenses it into the clone reconciler, without changing the loop behavior.

Signed-off-by: Alvaro Romero <alromero@redhat.com>

* Modify datavolume-mutate webhook to reject the creation of clones if the source PVC's namespace doesn't exist

In previous commits, a mechanism to allow the creation of clones without source PVC was added, without ever checking if the source PVC's namespace exists or not.

This behavior could lead to permission conflicts between the user and the source's namespace since the webhook skipped all the related validation.

This commit modifies the datavolume-mutate admission webhook to reject the clone if the source PVC's namespace doesn't exist.

Signed-off-by: Alvaro Romero <alromero@redhat.com>

* Update unit tests for proper coverage of clone-validation functions

This commit adds and updates several unit tests to improve the coverage of the clone-validation mechanism after several functions were moved to the controller.

It also introduces minor changes on related code in the datavolume-controller and functional tests following PR review.

Signed-off-by: Alvaro Romero <alromero@redhat.com>
2022-06-21 18:05:38 +02:00
alromeros
7eebbfaf1c
Make size optional when cloning using the Storage API (#2222)
* Allow empty DV size when cloning using storage API

When cloning a Data Volume, the size of the target can be potentially obtainable via the source PVC, which discards the need to explicitly specify it.

Considering that, this commit introduces a change in the correspondent validation webhook to allow omitting the resources.request.storage field when cloning a PVC using the storage API.

Signed-off-by: Alvaro Romero <alromero@redhat.com>

* Modify datavolume-controller to allow obtaining storage size from source PVC when cloning

When cloning a PVC, if the target's size is not specified, said value can be attainable from the source PVC.

This commit introduces a change in datavolume controller so, in case of detecting an empty storage size, said value can be obtained when performing CSI and Smart cloning.

Signed-off-by: Alvaro Romero <alromero@redhat.com>

* Update unit tests for datavolume-validation after enabling cloning with empty size

This commit updates the unit testing for the datavolume validation webhook, covering the possibility of cloning a PVC without setting any storage size.

Signed-off-by: Alvaro Romero <alromero@redhat.com>

* Update unit testing for controller-related functions after enabling cloning with empty size

This commit includes unit tests for the volumeSize() function after enabling creating clones with blank size.

Signed-off-by: Alvaro Romero <alromero@redhat.com>

* Update the datavolume controller to create a size-detection pod when performing host-assisted clone

When performing a host-assisted clone with empty clone size, simply copying the original PVC size could lead to potential overhead miscalculations if the source's VolumeMode is "filesystem".

When that's the case, an inspection pod will be created in the datavolume controller so it extracts the size of the virtual image using qemu-img.

Signed-off-by: Alvaro Romero <alromero@redhat.com>

* Include an image-size detection tool to allow cloning with empty DV size

This commit introduces a new tool in charge of collecting the virtual image size when cloning with an empty DV size. In some cases where said value is unattainable from the original PVC's spec, the datavolume controller will create a new pod containing this new tool.

The binary will then run the 'qemu-img' command and handle its results appropriately.

Signed-off-by: Alvaro Romero <alromero@redhat.com>

* Optimize the clone-size lookup process to avoid creating unnecessary size-detection pods

When performing host-assisted clone with an empty DV size, in some cases, a size-detection pod is used to obtain the required capacity.

This commit tries to optimize this process to keep the collected value as a PVC annotation, that is checked in subsequent clones to avoid creating redundant pods.

Signed-off-by: Alvaro Romero <alromero@redhat.com>

* Minor fixes and improvements on mechanism for cloning with empty storage size
* Add new optional flag on size-detection binary to enable using a different URI scheme
* Improve the pod-creation mechanism so the pod is not created until the source PVC has finished the import
* Modify size-finlation mechanism to account for possible round-downs when importing the source image
* Improve the size inflation mechanism so only PVCs with filesystem as volume mode are considered
* Minor style corrections

Signed-off-by: Alvaro Romero <alromero@redhat.com>

* Modify the clone-controller to allow skipping the clone size validation in some cases

Due to filesystem overhead differences, the target's size can sometimes be smaller than the source's one when obtaining said value with the size-detection pod.

This commit introduces minor changes in the clone-controller so we can skip the size validation in those cases.

Signed-off-by: Alvaro Romero <alromero@redhat.com>

* Minor changes and improvements in size-detection mechanism following PR review
* Added new UT that covers using empty storage API for non-cloning sources
* Added new watch on datavolume-controller that looks for changes in the size-detection pod
* Removed redundant and unnecessary specs on size-detection pod
* Added error handling when reading the pod's termination message
* Moved general-usage functions to 'util.go' file
* Updated 'datavolumes' documentation to reference the possibility of omitting the storage size when cloning
* Minor style corrections

Signed-off-by: Alvaro Romero <alromero@redhat.com>

* Add unit tests that cover the size-detection mechanism in the DataVolume controller

Signed-off-by: Alvaro Romero <alromero@redhat.com>

* Include functional tests for cloning without specifying storage size

Signed-off-by: Alvaro Romero <alromero@redhat.com>

* Improve error handling in the creation/deletion process of the size-detection pod

This commit introduces additional handling in case of error after and during the size-detection pod is created.

It also updates several related unit tests.

Signed-off-by: Alvaro Romero <alromero@redhat.com>

* Minor fixes to improve fsOverhead calculations when cloning with empty storage size
* Modified the size-detection mechanism so we account for fsOverhead when cloning to filesystem volume mode in all cases
* Clean up the code for reconciling when cloning a PVC that is not ready
* Minor fix in functional test so it works when cloning from block to filesystem volume mode

Signed-off-by: Alvaro Romero <alromero@redhat.com>
2022-05-31 17:03:45 +03:00
Arnon Gilboa
0b3900c60c
Garbage Collect Completed DVs (#2233)
* Garbage Collect Completed DVs

See design at:
https://github.com/kubevirt/community/blob/main/design-proposals/garbage-collect-completed-dvs.md

ToDos:
-DataImportCron and DataSource controllers adaptation and func tests
-Add doc for DataVolume, CDIConfig and DataImportCron changes
-Extend unit tests and functional tests
-KubeVirt adaptation

Signed-off-by: Arnon Gilboa <agilboa@redhat.com>

* Controller minor fixes

Signed-off-by: Arnon Gilboa <agilboa@redhat.com>

* Adapt tests to GC

Signed-off-by: Arnon Gilboa <agilboa@redhat.com>

* Add DV mutate unit test for GC

Signed-off-by: Arnon Gilboa <agilboa@redhat.com>

* Improve GC skip per annotation test

Signed-off-by: Arnon Gilboa <agilboa@redhat.com>

* Use DescribeTable for the GC tests

Signed-off-by: Arnon Gilboa <agilboa@redhat.com>
2022-05-19 00:09:31 +02:00
Maya Rashish
c05a750a9a
Detect storage capabilities for no-provisioner storage classes (#2226)
* Detect storage capabilities for no-provisioner storage classes

Assume there's a persistent volume that we can look up to infer the
correct values for volume mode and access modes.

Limit ourselves to detecting no-provisioner capabilities on LSO to
avoid greatly increasing the number of storage classes we provide
capabilities for. This is similar to our current flow where we
only provide capabilities for known storage classes.

Signed-off-by: Maya Rashish <mrashish@redhat.com>

* Regenerate bazel stuff for pkg/monitoring's existence

Signed-off-by: Maya Rashish <mrashish@redhat.com>

* Add a watcher for no-provisioner PVs

We maintain a map of storage class names and provisioners whenever
storage classes are changed.

If a PV has one of the storage classes with no-provisioner as a
provisioner, reconcile that storage class.

This is because we infer the storage profile based on PVs, and
new ones might have different storage capabilities.

Signed-off-by: Maya Rashish <mrashish@redhat.com>

* Use a client to do our storage class caching

Signed-off-by: Maya Rashish <mrashish@redhat.com>

* Pass a client as an argument, not global.

Suggested by awels, thanks!

Signed-off-by: Maya Rashish <mrashish@redhat.com>
2022-05-12 14:00:02 +02:00
Alexander Wels
b3d08268e2
Start smart clone controller from datavolume controller when needed (#2265)
* periodic sync CSI snapshot CRD check

It was possible for the CSI snapshot CRD check to fail silently and
prevent the smart clone controller from starting during the cdi deployment
pod start up. This would prevent smart clone from working properly.

This adds a periodic sync of 1 minute for checking the CRDs. We also
log failures that are not is not found so we can more easily detect this
situation as humans.

Signed-off-by: Alexander Wels <awels@redhat.com>

* Change location of the start controller call.

Signed-off-by: Alexander Wels <awels@redhat.com>
2022-05-12 04:28:01 +02:00
akalenyu
71522a1f2d
Switch VolumeSnapshot to v1 (#2235)
* Switch VolumeSnapshot to v1

VolumeSnapshot v1beta is being deprecated:
https://kubernetes.io/blog/2022/04/07/upcoming-changes-in-kubernetes-1-24/#api-removals-deprecations-and-other-changes-for-kubernetes-1-24

Signed-off-by: Alex Kalenyuk <akalenyu@redhat.com>

* Fix unit tests; change version we look for in IsCsiCrdsDeployed

Signed-off-by: Alex Kalenyuk <akalenyu@redhat.com>
2022-04-12 18:50:19 +02:00
Roman Mohr
b9c0684469
Separate sdk api (#2208)
* Introduce controller-runtime-sdk api package

Split controller-runtime-sdk into the base package and
controller-runtime-sdk/api.

Signed-off-by: Roman Mohr <rmohr@redhat.com>

* go mod vendor

Signed-off-by: Roman Mohr <rmohr@redhat.com>

* Update code references

Signed-off-by: Roman Mohr <rmohr@redhat.com>
2022-03-31 21:31:18 +02:00
Bartosz Rybacki
f89812c268
Do not factor fs overhead into available space during validation (#2195)
* Create a test for an overhead bug

This image size and filesystem overhead combination was experimentally determined
to reproduce bz#2064936 in CI when using ceph/rbd with a Filesystem mode PV since
the filesystem capacity will be constrained by the PVC request size.

Below is the problem it tries to recreate:
When validating whether an image will fit into a PV we compare the
image's virtual size to the filesystem's reported available space to
guage whether it will fit.  The current calculation reduces the apparent
available space by the configured filesystem overhead value but the
overhead is already (mostly) factored into the result of Statfs.  This
causes the check to fail for PVCs that are just large enough to
accommodate an image plus overhead (ie. when using the DataVolume
Storage API with filesystem PVs with capacity constrained by the PVC
storage request size).

This was not caught in testing because HPP does not have capacity
constrained PVs and we are typically testing block volumes in the ceph
lanes.  It can be triggered in our CI by allocating a Filesystem PV on
ceph-rbd storage because these volumes are capacity constrained and
subject to filesystem overhead.

Signed-off-by: Bartosz Rybacki <brybacki@redhat.com>

* Fix a target pvc validation bug

Corrects the validation logic for target volume.

Below description of the original problem:
When validating whether an image will fit into a PV we compare the
image's virtual size to the filesystem's reported available space to
guage whether it will fit.  The current calculation reduces the apparent
available space by the configured filesystem overhead value but the
overhead is already (mostly) factored into the result of Statfs.  This
causes the check to fail for PVCs that are just large enough to
accommodate an image plus overhead (ie. when using the DataVolume
Storage API with filesystem PVs with capacity constrained by the PVC
storage request size).

This was not caught in testing because HPP does not have capacity
constrained PVs and we are typically testing block volumes in the ceph
lanes.  It can be triggered in our CI by allocating a Filesystem PV on
ceph-rbd storage because these volumes are capacity constrained and
subject to filesystem overhead.

Signed-off-by: Bartosz Rybacki <brybacki@redhat.com>

* Improve the warning message

Removed redundant and misleading part about pvc size and update the simplification

Signed-off-by: Bartosz Rybacki <brybacki@redhat.com>

* Remove useless test

The test checks that the validation logic takes fs Overhead into account.
New validation logic does not check fs overhead. So test is no longer
relevant.

Signed-off-by: Bartosz Rybacki <brybacki@redhat.com>
2022-03-22 04:38:48 +01:00
Alexander Wels
013cb6b62b
Set http(s)_proxy to lower case env variable (#2132)
* Set htpp(s)_proxy to lower case env variable

CURL used by nbdkit doesn't read upper case http(s)_proxy environment
variables, and thus was not using the proxy. Changed the variable to
be lower case.

Added a significant number of tests to test many more variations of
using a proxy. Also added https + auth endpoint to the file-host
container, so we can test https + auth with the proxy.

Added https endpoint to proxy, so we can test an https proxy.

Cleaned up some of the error handling in the import controller for
the proxy, in particular if a trustedCAProxy is defined.

Fixed some of the cluster wide proxy configuration so it works properly
inside an openshift cluster.

Signed-off-by: Alexander Wels <awels@redhat.com>

* Add https proxy support to registry import. Added extra
functional tests to test all registry import combinations

Signed-off-by: Alexander Wels <awels@redhat.com>

* Fixed some tests to work better in Open Shift.

Signed-off-by: Alexander Wels <awels@redhat.com>
2022-02-03 18:09:41 +01:00
Bartosz Rybacki
e18fc68718
BugId: 2038679 - Clone with volume mode file system using Storage API fails (#2096)
* Update clone size validation logic

The case with DV using spec.storage API needs
more complex validation that will be added in the
clone controller. The API webhook validation
for that case is removed.

Signed-off-by: Bartosz Rybacki <brybacki@redhat.com>

* Improve DV phase failure message in tests

Signed-off-by: Bartosz Rybacki <brybacki@redhat.com>

* Add test and warning event for clone size

During clone check if actual requested size on source volume is bigger
than target requested size and emit an event to notify user about situation.

Actual size on filesystem is lower that requested, because of possible filesystem overhead. When using storage API the overhead will be applied on target.

Signed-off-by: Bartosz Rybacki <brybacki@redhat.com>

* Code Review cleanup - Removing debug logs

Removed some garbage left after troubleshooting.

Signed-off-by: Bartosz Rybacki <brybacki@redhat.com>

* Move fn GetUsableSpace to common utils

Signed-off-by: Bartosz Rybacki <brybacki@redhat.com>
2022-02-02 17:53:10 +01:00
Arnon Gilboa
81fa12ed38
Add DataImportCron ImageStream tag support (#2117)
* Add DataImportCron ImageStream tag support

Signed-off-by: Arnon Gilboa <agilboa@redhat.com>

* Fix storageClass possible nil deref

Signed-off-by: Arnon Gilboa <agilboa@redhat.com>

* Change DataSource indexer key separator

Signed-off-by: Arnon Gilboa <agilboa@redhat.com>

* Add DataImportCron ImageStream tag utest

Signed-off-by: Arnon Gilboa <agilboa@redhat.com>

* CR fixes

Signed-off-by: Arnon Gilboa <agilboa@redhat.com>
2022-01-25 13:05:05 +01:00
Matthew Arnold
7806e77bdf
Allow optional per-DataVolume VDDK image. (#2102)
* Add optional VDDK initImageURL field.

Signed-off-by: Matthew Arnold <marnold@redhat.com>

* Pass VDDK image URL through to PVC annotation.

Signed-off-by: Matthew Arnold <marnold@redhat.com>

* Unit tests for per-DV VDDK image URL.

Signed-off-by: Matthew Arnold <marnold@redhat.com>

* Functional test for VDDK initImageURL field.

Signed-off-by: Matthew Arnold <marnold@redhat.com>

* Update documentation for VDDK initImageURL.

Signed-off-by: Matthew Arnold <marnold@redhat.com>

* Fix lint error.

Signed-off-by: Matthew Arnold <marnold@redhat.com>

* Check for absence of AwaitingVDDK in unit test.

Signed-off-by: Matthew Arnold <marnold@redhat.com>
2022-01-19 22:49:48 +01:00
Shelly Kagan
41df5c240e
Emit event and update dv conditions when pvc fails to create due to quota (#2016)
* Update datavolume conditions when quota exceeded when creating pvc

When creating the pvc from the dv the pvc size
can exceed the allowed quota, in such case so far the only
indication was to look in the logs.
Now added indication in the data volume conditions
(when possible) and emitted event.

Signed-off-by: Shelly Kagan <skagan@redhat.com>

* Add functional tests to check the new conditons and event

Signed-off-by: Shelly Kagan <skagan@redhat.com>

* tests cosmetics

-use existing functions
-add missing checks on errors
-remove unused code
-etc..

Signed-off-by: Shelly Kagan <skagan@redhat.com>
2021-11-16 17:29:39 +01:00
Matthew Arnold
703e421a8a
Allow user-specified headers in HTTP data source. (#1994)
* Update HTTP data source API to allow custom headers.

Signed-off-by: Matthew Arnold <marnold@redhat.com>

* Implement custom HTTP headers API.

Signed-off-by: Matthew Arnold <marnold@redhat.com>

* Document custom headers in HTTP data source.

Signed-off-by: Matthew Arnold <marnold@redhat.com>

* Correct secretExtraHeader comment to reference Secret.

Signed-off-by: Matthew Arnold <marnold@redhat.com>

* Add volume mounts for secret headers.

Replaces environment variables for headers from secrets.

Signed-off-by: Matthew Arnold <marnold@redhat.com>

* Avoid failing when there are no extra headers.

Signed-off-by: Matthew Arnold <marnold@redhat.com>

* Redact contents of headers that come from secrets.

Also split up getExtraHeaders to reduce Sonar Cloud complexity.

Signed-off-by: Matthew Arnold <marnold@redhat.com>

* Ensure all HTTP client requests use extra headers.

Missed redirect check and content length retrieval, both of which might
need the extra headers.

Signed-off-by: Matthew Arnold <marnold@redhat.com>

* Add some unit tests for extra HTTP headers.

Signed-off-by: Matthew Arnold <marnold@redhat.com>

* Do not quote headers in nbdkit curl arguments.

Signed-off-by: Matthew Arnold <marnold@redhat.com>

* Add functional tests for extra HTTP headers.

Avoids new test server by specifiying basic authorization headers to the
existing file host port that requires it.

Signed-off-by: Matthew Arnold <marnold@redhat.com>

* Use filepath.Walk to read secrets.

Signed-off-by: Matthew Arnold <marnold@redhat.com>

* Minor documentation update for secrets.

Signed-off-by: Matthew Arnold <marnold@redhat.com>

* Re-run 'make generate' for verification failure.

Signed-off-by: Matthew Arnold <marnold@redhat.com>
2021-11-12 21:06:57 +01:00
Shelly Kagan
1eda6db87e
Datacontroller cosmetics (#2008)
* move common code to controller util

Signed-off-by: Shelly Kagan <skagan@redhat.com>

* remove unused functions and cosmetics

Signed-off-by: Shelly Kagan <skagan@redhat.com>
2021-11-04 18:05:55 +01:00
Michael Henriksen
aedaf513ec
Move apis to staging, push to containerized-data-importer-api (#1997)
* move apis to new staging area

Signed-off-by: Michael Henriksen <mhenriks@redhat.com>

* add script to push to staging

Signed-off-by: Michael Henriksen <mhenriks@redhat.com>

* fix lint check and api reference

Signed-off-by: Michael Henriksen <mhenriks@redhat.com>

* push staging to api repo

Signed-off-by: Michael Henriksen <mhenriks@redhat.com>
2021-10-28 13:40:24 +02:00
Michael Henriksen
87a13c2f29
Add long term token to pvcs when host assisted cloning cross namespaces (#1922)
* Add long term token (10 years) to pvcs when host assisted cloning between namespaces

Signed-off-by: Michael Henriksen <mhenriks@redhat.com>

* clone controller should retry if source in use

Signed-off-by: Michael Henriksen <mhenriks@redhat.com>

* minor refactor if/else -> switch

Signed-off-by: Michael Henriksen <mhenriks@redhat.com>
2021-09-17 01:24:00 +02:00
akalenyu
2254cf0c1f
Add relationship labels (#1864)
Users don't want 👽 resources in clusters,
and we should also be able to tell if were part of a broader installation.

Note:
- Operator created resources were handled in https://github.com/kubevirt/controller-lifecycle-operator-sdk/pull/18
as these labels will be common to all resources deployed by the HCO.
- Now that the controller is guaranteed to have the labels, we can set env vars
that reference the label values (fieldRef) to spare calling GET on the CR in the controllers.
(thanks mhenriks).

Signed-off-by: Alex Kalenyuk <akalenyu@redhat.com>
2021-07-28 20:05:24 +02:00
Maya Rashish
19d109837d
Add a datavolume condition for the image being too large (#1818)
* Strip newlines when writing a termination message.

Otherwise it isn't visible, at least when viewing in the -o yaml view.

Signed-off-by: Maya Rashish <mrashish@redhat.com>

* Write down the nbdkit output and add it to the error output

With the added output from nbdkit, we can see the reason for the
non-existence of the nbdkit socket.

Signed-off-by: Maya Rashish <mrashish@redhat.com>

* Don't set that we're waiting if it's CrashLoopBackOff

It's better to have the reason for the crash (terminate message)
than "backing off 5 minutes"

Signed-off-by: Maya Rashish <mrashish@redhat.com>

* Simplify all "image too large to fit" terminate reasons.

Signed-off-by: Maya Rashish <mrashish@redhat.com>

* Move verifyConditions to utils, no functional change

Signed-off-by: Maya Rashish <mrashish@redhat.com>

* Switch test for image too large to test condition and not log

Signed-off-by: Maya Rashish <mrashish@redhat.com>

* Remove unused branch

Signed-off-by: Maya Rashish <mrashish@redhat.com>

* Rename setConditionFromPodWithPrefix to setAnnotationsFromPodWithPrefix

No functional change. Intended to be followed by some refactoring.

Signed-off-by: Maya Rashish <mrashish@redhat.com>

* Fold restart count logic into the common setAnnotationsFromPodWithPrefix

Changing to >= rather than > to ensure a zero pod restart count is
always used -- the import controller unit tests request this.

Signed-off-by: Maya Rashish <mrashish@redhat.com>

* Reduce indentation by returning right away.

Signed-off-by: Maya Rashish <mrashish@redhat.com>

* Fold check for pod being nil into common code.

Signed-off-by: Maya Rashish <mrashish@redhat.com>

* move saveVddkAnnotations into util and make it unconditional

Call it setVddkAnnotations for consistency.
Check for not-terminated inside the function, not outside.

Removes check for source being VDDK (to avoid passing more arguments):
it won't match the regex anyway.

Signed-off-by: Maya Rashish <mrashish@redhat.com>

* Reduce indentation by bailing on failure.

Signed-off-by: Maya Rashish <mrashish@redhat.com>

* Reorder parameters to mirror the order in the function name

Signed-off-by: Maya Rashish <mrashish@redhat.com>

* Use a named variable for first container state

Yields shorter, more legible lines.

Signed-off-by: Maya Rashish <mrashish@redhat.com>

* Use a constant for the nbdkit log.

Signed-off-by: Maya Rashish <mrashish@redhat.com>

* Add more information to function description - also logs to file

Signed-off-by: Maya Rashish <mrashish@redhat.com>
2021-06-29 12:47:05 +02:00
Arnon Gilboa
c963ebb276
Add DataVolume annotation to retain the transfer pods after completion (#1841)
* Add annotation to retain the transfer pods after completion

Signed-off-by: Arnon Gilboa <agilboa@redhat.com>

* Add cloner test

Signed-off-by: Arnon Gilboa <agilboa@redhat.com>

* CR fixes

Signed-off-by: Arnon Gilboa <agilboa@redhat.com>
2021-06-28 17:39:31 +02:00
Maya Rashish
c1ccbbf4b7
Reduce the amount of noise from the filesystem overhead feature (#1831)
Signed-off-by: Maya Rashish <mrashish@redhat.com>
2021-06-09 23:17:40 +02:00
Matthew Arnold
2960a3f6d3
Copy VDDK version to DV annotation. (#1752)
* Add an interface to watch nbdkit logs.

Useful for fishing out various pieces of information. Save VDDK library
version and connected ESX host by appending to the importer pod's
termination message. Turns nbdkit logging up to verbose for VDDK data
sources, so only the last few lines are printed for debugging.

Signed-off-by: Matthew Arnold <marnold@redhat.com>

* Copy VDDK info from termination message to PVC/DV.

Signed-off-by: Matthew Arnold <marnold@redhat.com>

* Add unit tests for saved VDDK information.

Signed-off-by: Matthew Arnold <marnold@redhat.com>

* Add functional test for VDDK annotations.

Signed-off-by: Matthew Arnold <marnold@redhat.com>

* Fix unit test, forgot to check for nil pvc.

Signed-off-by: Matthew Arnold <marnold@redhat.com>

* Don't ignore errors updating PVC with VDDK info.

Signed-off-by: Matthew Arnold <marnold@redhat.com>

* Watch nbdkit with Scanner instead of ReadString.

Signed-off-by: Matthew Arnold <marnold@redhat.com>

* Move VDDK info test into existing functional test.

Signed-off-by: Matthew Arnold <marnold@redhat.com>

* Make nbdkit stop sequence slightly clearer.

Signed-off-by: Matthew Arnold <marnold@redhat.com>

* Save VDDK info in regular DV reconciler.

Signed-off-by: Matthew Arnold <marnold@redhat.com>

* Don't save VDDK info when PVC is being deleted.

Also, piggyback off existing PVC update instead of introducing a new
error handling path.

Signed-off-by: Matthew Arnold <marnold@redhat.com>

* Fix VDDK-info unit tests.

Signed-off-by: Matthew Arnold <marnold@redhat.com>

* Use scanner for all nbdkit logging.

Also fix up a minor merge mistake.

Signed-off-by: Matthew Arnold <marnold@redhat.com>

* Try to satisfy complaints from SonarCloud.

Signed-off-by: Matthew Arnold <marnold@redhat.com>
2021-05-08 21:06:18 +02:00
Michael Henriksen
74a2c86608
use namespace transfer for smart clone (#1763)
* use namespace transfer for smart clone

Signed-off-by: Michael Henriksen <mhenriks@redhat.com>

* updates from test failures

Signed-off-by: Michael Henriksen <mhenriks@redhat.com>

* add expansion func tests

Signed-off-by: Michael Henriksen <mhenriks@redhat.com>

* add dv phases for expansion and transfer

Signed-off-by: Michael Henriksen <mhenriks@redhat.com>

* rebase and integrate with storage profiles

Signed-off-by: Michael Henriksen <mhenriks@redhat.com>
2021-04-30 15:18:43 +02:00
Bartosz Rybacki
f81ab950fb
Use storage profiles when handling DataVolumes (#1753)
* Create new Storage type

A new Storage type similar to the PVC Spec is now available to use
in the DataVolume Spec. This is more permissive than PVC, and together
with StorageProfile this allows CDI to apply additional logic for
missing or optional fields.

Signed-off-by: Bartosz Rybacki <brybacki@redhat.com>

* Use the StorageProfile

Handle the StorageProfile recommended params when creating the PVC for
a DataVolume. When parameters like volumeMode or accessModes are
not provided, CDI checks the StorageProfile for a given StorageClass
to set the recommended defaults. This enables user to create DataVolume
without the need to provide all the parameters.

Signed-off-by: Bartosz Rybacki <brybacki@redhat.com>

* Allow multiple accessModes

CDI allows multiple access modes to be specified in the DataVolume.spec.storage and in the StorageProfile. This now works the same way as in PVC specification.

Signed-off-by: Bartosz Rybacki <brybacki@redhat.com>

* Handle the storage.size field

The storage.size specifies how much space a user wants to have.
When creating image on the fileSystem storage CDI takes into
account the file system overhead and requests PVC big enough to
fit an image and file system metadata.

Signed-off-by: Bartosz Rybacki <brybacki@redhat.com>

* Test storage profile with DV

Signed-off-by: Bartosz Rybacki <brybacki@redhat.com>

* Document Storage Profiles

Signed-off-by: Bartosz Rybacki <brybacki@redhat.com>

* Refactor: Render the effective PVC early

The helper 'render PVC' was moved earlier in the control flow, so
it can be used in more places. Removing the need for if/else logic.

Signed-off-by: Bartosz Rybacki <brybacki@redhat.com>

* Test handling size on import, upload and clone

Signed-off-by: Bartosz Rybacki <brybacki@redhat.com>

* Code Review: Refactor resolving of volumeMode

Signed-off-by: Bartosz Rybacki <brybacki@redhat.com>

* Fix: render target pvc spec correctly in smart clone controller

Signed-off-by: Bartosz Rybacki <brybacki@redhat.com>
2021-04-29 13:10:24 -05:00
Vishesh Tanksale
2014ddecfd
Adding priority class name for importer/upload pod to data volume object (#1740)
* Adding priority class name for importer/upload pod to data volume object

Signed-off-by: Vishesh Ajay Tanksale <vtanksale@apple.com>

* Addressing review comments

Signed-off-by: Vishesh Ajay Tanksale <vtanksale@apple.com>

* Adding controller logic to assign priority class on importer,cloner and uploader pod

Signed-off-by: Vishesh Ajay Tanksale <vtanksale@apple.com>

* Adding functional test

Signed-off-by: Vishesh Ajay Tanksale <vtanksale@apple.com>

* Addressing review comments

Signed-off-by: Vishesh Ajay Tanksale <vtanksale@apple.com>

* Updating Data Volume doc

Signed-off-by: Vishesh Ajay Tanksale <vtanksale@apple.com>

Co-authored-by: Vishesh Ajay Tanksale <vtanksale@apple.com>
2021-04-28 09:38:42 -05:00
Tomasz Barański
84f51f32f6
Preallocate cloning DV (#1719)
* Refactoring - move PreallocationApplied flag definition to common

Signed-off-by: Tomasz Baranski <tbaransk@redhat.com>

* Preallocate cloning DataVolumes

Signed-off-by: Tomasz Baranski <tbaransk@redhat.com>
2021-04-27 15:06:30 +02:00