Commit Graph

97 Commits

Author SHA1 Message Date
Michael Henriksen
6408daf1e4
cdi-uploadserver: healthcheck and application use same port (#3536)
healthcheck used to be on a dedicated port for "reasons" and
by that I mean I was too lazy to properly set up the tls configuration
and check authz in upload handlers

Signed-off-by: Michael Henriksen <mhenriks@redhat.com>
2024-11-21 19:41:15 +01:00
Michael Henriksen
5195176c16
update to k8s 1.30 libs and controller-runtime 0.18.4 (#3336)
* make deps-update

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

* ReourceRequirements -> VolumeResourceRequirements

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

* fix calls to controller.Watch()

controller-runtime changed the API!

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

* Fix errors with actual openshift/library-go lib

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

* make all works now and everything compiles

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

* fix "make update-codegen" because generate_groups.sh deprecated

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

* run "make generate"

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

* fix transfer unittest because of change to controller-runtime

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

---------

Signed-off-by: Michael Henriksen <mhenriks@redhat.com>
2024-07-14 20:12:50 +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
7fb78edade
Enable dupword linter (#3175)
* Enable dupword linter

Per the readme:
> A linter that checks for duplicate words in the source code (usually miswritten)

https://github.com/Abirdcfly/dupword
https://golangci-lint.run/usage/linters/#dupword

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

* Remove duplicate words in comments and strings

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

---------

Signed-off-by: Edu Gómez Escandell <egomez@redhat.com>
2024-04-25 01:00:23 +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
Ben Coxford
ebb9d31ac9
fix: propagating mesh annotations to transient pods (#3186)
* fix propagating mesh annotations to transient pods

Signed-off-by: bcoxford <ben.coxford@ncr.com>

* set pvc annotations on prep claim and size detection transient pods

Signed-off-by: bcoxford <ben.coxford@ncr.com>

* remove old annotations

Signed-off-by: bcoxford <ben.coxford@ncr.com>

* switch to target dv on pvc clone controller

Signed-off-by: bcoxford <ben.coxford@ncr.com>

* use metav1 object

Signed-off-by: bcoxford <ben.coxford@ncr.com>

---------

Signed-off-by: bcoxford <ben.coxford@ncr.com>
2024-04-16 22:32:47 +02:00
alromeros
6a9a39c014
Improve readability of upload pod's creation code (#3151)
Signed-off-by: Alvaro Romero <alromero@redhat.com>
2024-03-27 02:43:29 +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
Alex Kalenyuk
31d12e426e
update k8s & related libraries to 1.28 (#3078)
* Bump k8s/OpenShift/ctrl-runtime/lifecycle-sdk & make deps-update

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

* Operator: adapt for dependency bump

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

* Controller: adapt watch calls for dependency bump

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

* Controller: adapt to ctrl-runtime's cache API changes

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

* Operator: fix unit tests by deleting resources properly in fake client

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

* Controller: fix unit tests by deleting resources properly in fake client

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

* Controller: adapt to fake client honoring status subresource

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

* Fix codegen script & make generate

There are some issues in the new script, so we
will still use the deprecated one.
More context in f4d1a5431b

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

* Functests: Adapt to NamespacedName now implementing MarshalLog

ns/name -> {"name":"name","namespace":"ns"}

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

* Functests & API server: address deprecation of wait.PollImmediate

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

---------

Signed-off-by: Alex Kalenyuk <akalenyu@redhat.com>
2024-01-23 17:52:05 +01:00
Michael Henriksen
cc8dbc3bae
increase controller cuncurrency and cpu requests (#2862)
This commit ups the cpu request for for all our installed compopents
(cdi-deployment, cdi-apiserver, cdi-uploadproxy, cdi-operator)
for 10m (1% of a core) to 100m (10% of a core).
The main driver of this is BZ: 2216038.
Without this change, it is pretty easy to create a large number of
concurrent clone operations and get token timeout errors.
Upping resource requests and concurrency addresses the issue
in a very direct way.

Signed-off-by: Michael Henriksen <mhenriks@redhat.com>
2023-08-24 02:48:34 +02: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
4ce9272c2c
DataVolume Controller uses VolumeCloneSource Populator (#2750)
* remove CSI clone

bye bye

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

* no more smart clone

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

* PVC clone same namespace

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

* cross namespace pvc clone

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

* various fixes to get some functional tests to work

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

* delete smart clone controller again

somehow reappeared after rebase

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

* mostly pvc clone functional test fixes

make sure size detect pod only runs on kubevirt content type

clone populator was skipping last round op applying pvc' annotations

various func test fixes

review comments

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

* more various test fixes

host clone phase should (implicitly) wait for clone source pod to exit

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

* remove "smart" clone from snapshot

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

* DataVolume clone from snapshot uses populator

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

* improve clone populator/datavolume coordination on "running" condition

For host clone, not much changes, values still comming from annotations on host clone PVC

For smart/csi clone the DataVolume will be "running" if not in pending or error phase

Will have the same values for terminal "completed" state regardless of clone type

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

* unit tests for pvc/snapshot clone controllers

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

* remove skipped test added in https://github.com/kubevirt/containerized-data-importer/pull/2759

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

* attempt address AfterSuite and generate-verify failures

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

* handle snapshot clone with no target size specified

also add more validation to some snapshot clone tests

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

* remove Patch calls

Using the controller runtime Patch API with controller runtime cached client seems to be a pretty bad fit

At least given the way the CR API is designed where an old object is compared to new.

I like patch in theory though and will revisit

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

* Clone populator should plan and execute even if PVC is bound

It was possible to miss "preallocation applied" annotation otherwise

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

* add long term token to datavolume

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

* Rename ProgressReporter to StatusReporter

Should have been done back when annotations were addded to "progress"

Also, if pvc is bound do not call phase Reconcile functions only Status

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

---------

Signed-off-by: Michael Henriksen <mhenriks@redhat.com>
2023-06-30 00:14:54 +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
Shelly Kagan
e6c835c7c1
Upload populator (#2678)
* Create CRD for volumeuploadsource populator

This CRD will be used in the DataSourceRef on PVCs
to trigger population that upload to the volume.
This will be performed by the upload populator
that will be added in future commits.

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

* Create upload populator controller

The upload populator controller can be used
standalone without the need of datavolume.
It reconciles pvc with upload dataSourceRef
and uses populators API to populated the pvc
with an upload command.
The controller creates pvc' with upload
annotation. After the upload completes it
rebinds the pv to the original target pvc and
deletes pvc prime.
Eventually we get a bound PVC which is already
populated.

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

* Adjust upload-proxy to handle upload population

In case of pvc with datasourceref to upload population
we should create the url to the upload server with the
pvc' name.

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

* Add tests for upload population

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

* Add unit tests for upload populator

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

* Add preallocation to volumeuploadsource crd

Also some other small fixes

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

---------

Signed-off-by: Shelly Kagan <skagan@redhat.com>
2023-05-04 08:24:42 +02:00
Nahshon Unna Tsameret
e6d2286dfb
golangci-lint: Enable errcheck (#2696)
* golangci-lint: enable errcheck and fix findings

Signed-off-by: Nahshon Unna-Tsameret <nunnatsa@redhat.com>

* golangci=lint: exit if find something

Signed-off-by: Nahshon Unna-Tsameret <nunnatsa@redhat.com>

---------

Signed-off-by: Nahshon Unna-Tsameret <nunnatsa@redhat.com>
2023-04-25 20:40:16 +02:00
Nahshon Unna Tsameret
34a98256a2
Start integrate golangci lint into CI (#2675)
* Start adding the golangci-lint to CI

golangci-lint is a collection of many linters. This PR adds
golangci-lint to the CI. For strat, it enables the govet linter, and fix
its single finding.

The PR adds this linter to the `test-lint` Makefile target.

The new .golangci.yml file is the configuration for the linter.

golangci-lint version was set to the latest one - v1.52.2.
It is defined in hack/build/run-linters.sh

Signed-off-by: Nahshon Unna-Tsameret <nunnatsa@redhat.com>

* golangci-lint: enable gosimple and fix findings

Signed-off-by: Nahshon Unna-Tsameret <nunnatsa@redhat.com>

* golangci-lint: enable unused and fix findings

Signed-off-by: Nahshon Unna-Tsameret <nunnatsa@redhat.com>

---------

Signed-off-by: Nahshon Unna-Tsameret <nunnatsa@redhat.com>
2023-04-11 13:59:33 +01:00
garonsky
4e3ee4c44d
Add support for imagePullSecrets (#2589)
* Add support for imagePullSecrets in the CDI CR, to support pulling
images from repositories that require secrets.

The imagePullSecrets is propagated to the following components: cdi-apiserver,
cdi-deployment, and cdi-uploadproxy. The definition of imagePullSecrets in
cdi-operator must be done manually.

Signed-off-by: Gleb Aronsky <gleb.aronsky@windriver.com>

* Modifying code to incorporate review comments.

Signed-off-by: Gleb Aronsky <gleb.aronsky@windriver.com>

---------

Signed-off-by: Gleb Aronsky <gleb.aronsky@windriver.com>
Co-authored-by: Gleb Aronsky <gleb.aronsky@windriver.com>
2023-03-18 01:41:35 +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
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
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
akalenyu
dfdc218a48
Allow configuring TLS profiles for our externally facing components (#2332)
* Add TLS Security Profile API

TLSSecurityProfile is used by operators to apply cluster-wide TLS security settings to operands.

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

* Update apiserver & uploadproxy server TLS config on CDIConfig TLS knob change

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

* Propagate TLS config to uploadserver as well

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

* Add functests for apiserver and upload that ensure value is respected

Signed-off-by: Alex Kalenyuk <akalenyu@redhat.com>
2022-07-10 19:13:50 +02:00
Alexander Wels
5554567cbb
Comply with restricted security context (#2331)
* Comply with restricted security context in kubernetes

Ensure CDI pods comply with the restricted security context as much as
possible (have to be root for nbdkit and block devices). Also cannot set
SeccompProfile since SCC won't allow us to set it.

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

* Changed path /var/local/all_certs to stay in /var

Signed-off-by: Alexander Wels <awels@redhat.com>
2022-07-08 18:47:50 +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
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
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
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
Michael Henriksen
d56e0cca05
23 libs (#2077)
Signed-off-by: Michael Henriksen <mhenriks@redhat.com>
2022-01-07 16:56:25 +01:00
Michael Henriksen
48934c912d
uploadserver key/cert in secret (#2028)
* uploadserver key/cert in secret

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

* fix func test to accept "secret get"

Signed-off-by: Michael Henriksen <mhenriks@redhat.com>
2021-11-23 20:22:49 +01:00
akalenyu
fd332a3165
Degraded/unusual restartcount alerts (#2009)
* Add degraded alert

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

* Add unusual restart count metric

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

* Add actual firing alerts (degraded/restartcount)

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

* Test newly added metrics

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

* Review: Rename metric to match conventions, func to check if test is eligible to run metric tests

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

* Get rid of similar funcs, reconcile more generally

Signed-off-by: Alex Kalenyuk <akalenyu@redhat.com>
2021-11-18 01:05:01 +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
Shelly Kagan
e7dd62eb26
Upload archive (#1969)
* Add support for archive upload

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

* fix golang errors

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

* Change storage profile property set to support more then one set

So far CDI supported only 1 claim propery set. We want to be able
to support more then one so in case the user provides to the
DV storage volumeMode without accessMode or vice versa cdi
will be able to fit to it the most appropriate match.
Added to rook ceph block a second default of filesystem
volume mode with RWO access mode, it will support archive
upload which has default of filesystem mode.

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

* CR fix - change to one endpoint for the user

upload proxy will identify if the upload is archive
or not by looking at the content type annotation on
the pvc. If the content type is archive it will route
the uplaod to upload server to a new archive upload uri.

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

* Add storage profile and data volume controllers unit tests

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

* CR fixes

* add default volume mode to archive content type
* upload server use data processor for archive upload
* tests for volume mode with archive content type
* tests for archive upload of compressed tar

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

* Adjust imports acording to new apis dir

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

* CR small fixes

Signed-off-by: Shelly Kagan <skagan@redhat.com>
2021-11-03 20:11:47 +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
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
Michael Henriksen
d92c2f459d
update deps and bazel (#1815)
* update deps and bazel

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

* fix apidocs and unit tests

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

* fix generate-verify

Signed-off-by: Michael Henriksen <mhenriks@redhat.com>
2021-06-08 01:31:59 +02: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
Michael Henriksen
3447bb84c7
Cluster scoped DataVolume/PVC namespace transfer API (#1673)
* Cluster-scoped namespace transfer api and controller

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

* unit tests

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

* ObjectTransfer webhook

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

* new functests

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

* experiment with termination grace period

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

* quota test

Signed-off-by: Michael Henriksen <mhenriks@redhat.com>
2021-02-24 20:45:24 +01:00
Tomasz Barański
a29c3d4165
Preallocate even if the size is too small (#1637)
This PR removes "skipped" condition for preallocation. Importer/uploader
will preallocate to the available size. Filesystem overhead needs to be
taken into account.

Signed-off-by: Tomasz Baranski <tbaransk@redhat.com>
2021-02-10 21:18:56 +01:00
threestoneliu
e461c759a5
rename importController to uploadController in the upload-controller.go file (#1632)
Signed-off-by: threestoneliu <liuzhilei93@outlook.com>
2021-02-04 21:40:53 +01:00
Maya Rashish
9d1b94f47e
Simplify shouldReconcile function arguments. (#1602)
* Simplify shouldReconcile function arguments.

By having the function itself grab things it needs and are easily
obtained.

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

* Adapt unit tests to simpler shouldReconcilePVC

Don't set any feature gates for WFFC being disabled.
When the second argument is true, pass the immediate binding annotation
to the PVC itself.

Signed-off-by: Maya Rashish <mrashish@redhat.com>
2021-02-04 14:38:26 +01:00
Arnon Gilboa
f7703a6bd7
Support cloning from Filesystem to Block and vice-versa (#1597)
* validate source and target pvcs has the same content type - for all clones
* if source and target volume modes are different, validate content type is kubevirt, and fallback to host-assisted cloning
* unit & func tests

Signed-off-by: Arnon Gilboa <agilboa@redhat.com>
2021-02-03 01:06:52 +01:00
Bartosz Rybacki
2abf7330c1
Add a DV/PVC annotation "storage.bind.immediate.requested" (#1560)
* Add a DV/PVC annotation "storage.bind.immediate.requested"

When the annotation is applied the CDI will force bind the PVC (by scheduling worker pods), ignoring the logic to handle WaitForFirstConsumer binding mode.

This is useful when uploading "template" images to the cluster on local storage with WaitForFirstConsumer binding. In this case the image has to be available somewhere on the cluster, the actual placement of image on specific node is not important, so the CDI worker node can be used as a first consumer.

For storage with immediate binging it is effectively a NOOP.

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

* Test import/upload/clone with annotation "storage.bind.immediate.requested"

Signed-off-by: Bartosz Rybacki <brybacki@redhat.com>
2021-01-15 08:15:10 +01:00
Tomasz Barański
9a6ce7eee0
Preallocation check all paths (#1535)
* [WIP] doc: User-facing doc for preallocation support

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

* apis: CDI accepts `preallocation` option.

With this commit CDI accepts (but does handle) `preallocation` settings
for DataVolumes and in CDIConfig.

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

* core: Implementing preallocation

This commit implements preallocation support for import and upload.

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

* test: Functional tests for preallocation support

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

* core: Remove "preallocation for StorageClasses" config

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

* test: Removed unused function

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

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

* core: Uss PVC annotation to pass preallocation parameters

DataVolume controller now uses a PVC annotation to pass preallocation
configuration to import and update controllers.

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

* core: Implementing preallocation

This commit implements preallocation support for import and upload.

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

* core: Make sure all import/upload paths do preallocation

Signed-off-by: Tomasz Baranski <tbaransk@redhat.com>
2021-01-08 04:48:59 +01:00
Tomasz Barański
91a15c57d1
Preallocation support (#1498)
* [WIP] doc: User-facing doc for preallocation support

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

* apis: CDI accepts `preallocation` option.

With this commit CDI accepts (but does handle) `preallocation` settings
for DataVolumes and in CDIConfig.

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

* core: Implementing preallocation

This commit implements preallocation support for import and upload.

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

* test: Functional tests for preallocation support

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

* core: Remove "preallocation for StorageClasses" config

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

* test: Removed unused function

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

* test: Fix rook-ceph test failures

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

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

* core: Uss PVC annotation to pass preallocation parameters

DataVolume controller now uses a PVC annotation to pass preallocation
configuration to import and update controllers.

Signed-off-by: Tomasz Baranski <tbaransk@redhat.com>
2020-12-18 16:46:16 -05:00
Arnon Gilboa
ff42ea0597
Pass specific PVC annotations to the transfer pods (#1480)
* Pass specific PVC annotations to the transfer pods

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

* Add annotations importer/uploader/cloner functional tests

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

* CR fixes

Signed-off-by: Arnon Gilboa <agilboa@redhat.com>
2020-11-30 19:20:38 +01:00
Michael Henriksen
7dbc07ab0f
Attempt to schedula clone sourc/target pods on same node (#1426)
Signed-off-by: Michael Henriksen <mhenriks@redhat.com>
2020-10-13 00:45:38 +02:00