mirror of
https://github.com/kubevirt/containerized-data-importer.git
synced 2025-06-03 06:30:22 +00:00
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>
This commit is contained in:
parent
3648cc2567
commit
e6c835c7c1
@ -276,6 +276,10 @@ func start() {
|
||||
klog.Errorf("Unable to setup import populator: %v", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
if _, err := populators.NewUploadPopulator(ctx, mgr, log, installerLabels); err != nil {
|
||||
klog.Errorf("Unable to setup upload populator: %v", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
klog.V(1).Infoln("created cdi controllers")
|
||||
|
||||
|
@ -584,6 +584,10 @@ func GetOpenAPIDefinitions(ref common.ReferenceCallback) map[string]common.OpenA
|
||||
"kubevirt.io/containerized-data-importer-api/pkg/apis/core/v1beta1.VolumeImportSourceList": schema_pkg_apis_core_v1beta1_VolumeImportSourceList(ref),
|
||||
"kubevirt.io/containerized-data-importer-api/pkg/apis/core/v1beta1.VolumeImportSourceSpec": schema_pkg_apis_core_v1beta1_VolumeImportSourceSpec(ref),
|
||||
"kubevirt.io/containerized-data-importer-api/pkg/apis/core/v1beta1.VolumeImportSourceStatus": schema_pkg_apis_core_v1beta1_VolumeImportSourceStatus(ref),
|
||||
"kubevirt.io/containerized-data-importer-api/pkg/apis/core/v1beta1.VolumeUploadSource": schema_pkg_apis_core_v1beta1_VolumeUploadSource(ref),
|
||||
"kubevirt.io/containerized-data-importer-api/pkg/apis/core/v1beta1.VolumeUploadSourceList": schema_pkg_apis_core_v1beta1_VolumeUploadSourceList(ref),
|
||||
"kubevirt.io/containerized-data-importer-api/pkg/apis/core/v1beta1.VolumeUploadSourceSpec": schema_pkg_apis_core_v1beta1_VolumeUploadSourceSpec(ref),
|
||||
"kubevirt.io/containerized-data-importer-api/pkg/apis/core/v1beta1.VolumeUploadSourceStatus": schema_pkg_apis_core_v1beta1_VolumeUploadSourceStatus(ref),
|
||||
"kubevirt.io/controller-lifecycle-operator-sdk/api.NodePlacement": schema_kubevirtio_controller_lifecycle_operator_sdk_api_NodePlacement(ref),
|
||||
}
|
||||
}
|
||||
@ -27560,6 +27564,142 @@ func schema_pkg_apis_core_v1beta1_VolumeImportSourceStatus(ref common.ReferenceC
|
||||
}
|
||||
}
|
||||
|
||||
func schema_pkg_apis_core_v1beta1_VolumeUploadSource(ref common.ReferenceCallback) common.OpenAPIDefinition {
|
||||
return common.OpenAPIDefinition{
|
||||
Schema: spec.Schema{
|
||||
SchemaProps: spec.SchemaProps{
|
||||
Description: "VolumeUploadSource is a specification to populate PersistentVolumeClaims with upload data",
|
||||
Type: []string{"object"},
|
||||
Properties: map[string]spec.Schema{
|
||||
"kind": {
|
||||
SchemaProps: spec.SchemaProps{
|
||||
Description: "Kind is a string value representing the REST resource this object represents. Servers may infer this from the endpoint the client submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds",
|
||||
Type: []string{"string"},
|
||||
Format: "",
|
||||
},
|
||||
},
|
||||
"apiVersion": {
|
||||
SchemaProps: spec.SchemaProps{
|
||||
Description: "APIVersion defines the versioned schema of this representation of an object. Servers should convert recognized schemas to the latest internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources",
|
||||
Type: []string{"string"},
|
||||
Format: "",
|
||||
},
|
||||
},
|
||||
"metadata": {
|
||||
SchemaProps: spec.SchemaProps{
|
||||
Default: map[string]interface{}{},
|
||||
Ref: ref("k8s.io/apimachinery/pkg/apis/meta/v1.ObjectMeta"),
|
||||
},
|
||||
},
|
||||
"spec": {
|
||||
SchemaProps: spec.SchemaProps{
|
||||
Default: map[string]interface{}{},
|
||||
Ref: ref("kubevirt.io/containerized-data-importer-api/pkg/apis/core/v1beta1.VolumeUploadSourceSpec"),
|
||||
},
|
||||
},
|
||||
"status": {
|
||||
SchemaProps: spec.SchemaProps{
|
||||
Default: map[string]interface{}{},
|
||||
Ref: ref("kubevirt.io/containerized-data-importer-api/pkg/apis/core/v1beta1.VolumeUploadSourceStatus"),
|
||||
},
|
||||
},
|
||||
},
|
||||
Required: []string{"spec"},
|
||||
},
|
||||
},
|
||||
Dependencies: []string{
|
||||
"k8s.io/apimachinery/pkg/apis/meta/v1.ObjectMeta", "kubevirt.io/containerized-data-importer-api/pkg/apis/core/v1beta1.VolumeUploadSourceSpec", "kubevirt.io/containerized-data-importer-api/pkg/apis/core/v1beta1.VolumeUploadSourceStatus"},
|
||||
}
|
||||
}
|
||||
|
||||
func schema_pkg_apis_core_v1beta1_VolumeUploadSourceList(ref common.ReferenceCallback) common.OpenAPIDefinition {
|
||||
return common.OpenAPIDefinition{
|
||||
Schema: spec.Schema{
|
||||
SchemaProps: spec.SchemaProps{
|
||||
Description: "VolumeUploadSourceList provides the needed parameters to do request a list of Upload Sources from the system",
|
||||
Type: []string{"object"},
|
||||
Properties: map[string]spec.Schema{
|
||||
"kind": {
|
||||
SchemaProps: spec.SchemaProps{
|
||||
Description: "Kind is a string value representing the REST resource this object represents. Servers may infer this from the endpoint the client submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds",
|
||||
Type: []string{"string"},
|
||||
Format: "",
|
||||
},
|
||||
},
|
||||
"apiVersion": {
|
||||
SchemaProps: spec.SchemaProps{
|
||||
Description: "APIVersion defines the versioned schema of this representation of an object. Servers should convert recognized schemas to the latest internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources",
|
||||
Type: []string{"string"},
|
||||
Format: "",
|
||||
},
|
||||
},
|
||||
"metadata": {
|
||||
SchemaProps: spec.SchemaProps{
|
||||
Default: map[string]interface{}{},
|
||||
Ref: ref("k8s.io/apimachinery/pkg/apis/meta/v1.ListMeta"),
|
||||
},
|
||||
},
|
||||
"items": {
|
||||
SchemaProps: spec.SchemaProps{
|
||||
Description: "Items provides a list of DataSources",
|
||||
Type: []string{"array"},
|
||||
Items: &spec.SchemaOrArray{
|
||||
Schema: &spec.Schema{
|
||||
SchemaProps: spec.SchemaProps{
|
||||
Default: map[string]interface{}{},
|
||||
Ref: ref("kubevirt.io/containerized-data-importer-api/pkg/apis/core/v1beta1.VolumeImportSource"),
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
Required: []string{"metadata", "items"},
|
||||
},
|
||||
},
|
||||
Dependencies: []string{
|
||||
"k8s.io/apimachinery/pkg/apis/meta/v1.ListMeta", "kubevirt.io/containerized-data-importer-api/pkg/apis/core/v1beta1.VolumeImportSource"},
|
||||
}
|
||||
}
|
||||
|
||||
func schema_pkg_apis_core_v1beta1_VolumeUploadSourceSpec(ref common.ReferenceCallback) common.OpenAPIDefinition {
|
||||
return common.OpenAPIDefinition{
|
||||
Schema: spec.Schema{
|
||||
SchemaProps: spec.SchemaProps{
|
||||
Description: "VolumeUploadSourceSpec defines specification for VolumeUploadSource",
|
||||
Type: []string{"object"},
|
||||
Properties: map[string]spec.Schema{
|
||||
"contentType": {
|
||||
SchemaProps: spec.SchemaProps{
|
||||
Description: "ContentType represents the type of the upload data (Kubevirt or archive)",
|
||||
Type: []string{"string"},
|
||||
Format: "",
|
||||
},
|
||||
},
|
||||
"preallocation": {
|
||||
SchemaProps: spec.SchemaProps{
|
||||
Description: "Preallocation controls whether storage for the target PVC should be allocated in advance.",
|
||||
Type: []string{"boolean"},
|
||||
Format: "",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func schema_pkg_apis_core_v1beta1_VolumeUploadSourceStatus(ref common.ReferenceCallback) common.OpenAPIDefinition {
|
||||
return common.OpenAPIDefinition{
|
||||
Schema: spec.Schema{
|
||||
SchemaProps: spec.SchemaProps{
|
||||
Description: "VolumeUploadSourceStatus provides the most recently observed status of the VolumeUploadSource",
|
||||
Type: []string{"object"},
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func schema_kubevirtio_controller_lifecycle_operator_sdk_api_NodePlacement(ref common.ReferenceCallback) common.OpenAPIDefinition {
|
||||
return common.OpenAPIDefinition{
|
||||
Schema: spec.Schema{
|
||||
|
@ -14,6 +14,7 @@ go_library(
|
||||
"objecttransfer.go",
|
||||
"storageprofile.go",
|
||||
"volumeimportsource.go",
|
||||
"volumeuploadsource.go",
|
||||
],
|
||||
importpath = "kubevirt.io/containerized-data-importer/pkg/client/clientset/versioned/typed/core/v1beta1",
|
||||
visibility = ["//visibility:public"],
|
||||
|
@ -36,6 +36,7 @@ type CdiV1beta1Interface interface {
|
||||
ObjectTransfersGetter
|
||||
StorageProfilesGetter
|
||||
VolumeImportSourcesGetter
|
||||
VolumeUploadSourcesGetter
|
||||
}
|
||||
|
||||
// CdiV1beta1Client is used to interact with features provided by the cdi.kubevirt.io group.
|
||||
@ -75,6 +76,10 @@ func (c *CdiV1beta1Client) VolumeImportSources(namespace string) VolumeImportSou
|
||||
return newVolumeImportSources(c, namespace)
|
||||
}
|
||||
|
||||
func (c *CdiV1beta1Client) VolumeUploadSources(namespace string) VolumeUploadSourceInterface {
|
||||
return newVolumeUploadSources(c, namespace)
|
||||
}
|
||||
|
||||
// NewForConfig creates a new CdiV1beta1Client for the given config.
|
||||
// NewForConfig is equivalent to NewForConfigAndClient(c, httpClient),
|
||||
// where httpClient was generated with rest.HTTPClientFor(c).
|
||||
|
@ -13,6 +13,7 @@ go_library(
|
||||
"fake_objecttransfer.go",
|
||||
"fake_storageprofile.go",
|
||||
"fake_volumeimportsource.go",
|
||||
"fake_volumeuploadsource.go",
|
||||
],
|
||||
importpath = "kubevirt.io/containerized-data-importer/pkg/client/clientset/versioned/typed/core/v1beta1/fake",
|
||||
visibility = ["//visibility:public"],
|
||||
|
@ -60,6 +60,10 @@ func (c *FakeCdiV1beta1) VolumeImportSources(namespace string) v1beta1.VolumeImp
|
||||
return &FakeVolumeImportSources{c, namespace}
|
||||
}
|
||||
|
||||
func (c *FakeCdiV1beta1) VolumeUploadSources(namespace string) v1beta1.VolumeUploadSourceInterface {
|
||||
return &FakeVolumeUploadSources{c, namespace}
|
||||
}
|
||||
|
||||
// RESTClient returns a RESTClient that is used to communicate
|
||||
// with API server by this client implementation.
|
||||
func (c *FakeCdiV1beta1) RESTClient() rest.Interface {
|
||||
|
@ -0,0 +1,142 @@
|
||||
/*
|
||||
Copyright 2018 The CDI Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
// Code generated by client-gen. DO NOT EDIT.
|
||||
|
||||
package fake
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
labels "k8s.io/apimachinery/pkg/labels"
|
||||
schema "k8s.io/apimachinery/pkg/runtime/schema"
|
||||
types "k8s.io/apimachinery/pkg/types"
|
||||
watch "k8s.io/apimachinery/pkg/watch"
|
||||
testing "k8s.io/client-go/testing"
|
||||
v1beta1 "kubevirt.io/containerized-data-importer-api/pkg/apis/core/v1beta1"
|
||||
)
|
||||
|
||||
// FakeVolumeUploadSources implements VolumeUploadSourceInterface
|
||||
type FakeVolumeUploadSources struct {
|
||||
Fake *FakeCdiV1beta1
|
||||
ns string
|
||||
}
|
||||
|
||||
var volumeuploadsourcesResource = schema.GroupVersionResource{Group: "cdi.kubevirt.io", Version: "v1beta1", Resource: "volumeuploadsources"}
|
||||
|
||||
var volumeuploadsourcesKind = schema.GroupVersionKind{Group: "cdi.kubevirt.io", Version: "v1beta1", Kind: "VolumeUploadSource"}
|
||||
|
||||
// Get takes name of the volumeUploadSource, and returns the corresponding volumeUploadSource object, and an error if there is any.
|
||||
func (c *FakeVolumeUploadSources) Get(ctx context.Context, name string, options v1.GetOptions) (result *v1beta1.VolumeUploadSource, err error) {
|
||||
obj, err := c.Fake.
|
||||
Invokes(testing.NewGetAction(volumeuploadsourcesResource, c.ns, name), &v1beta1.VolumeUploadSource{})
|
||||
|
||||
if obj == nil {
|
||||
return nil, err
|
||||
}
|
||||
return obj.(*v1beta1.VolumeUploadSource), err
|
||||
}
|
||||
|
||||
// List takes label and field selectors, and returns the list of VolumeUploadSources that match those selectors.
|
||||
func (c *FakeVolumeUploadSources) List(ctx context.Context, opts v1.ListOptions) (result *v1beta1.VolumeUploadSourceList, err error) {
|
||||
obj, err := c.Fake.
|
||||
Invokes(testing.NewListAction(volumeuploadsourcesResource, volumeuploadsourcesKind, c.ns, opts), &v1beta1.VolumeUploadSourceList{})
|
||||
|
||||
if obj == nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
label, _, _ := testing.ExtractFromListOptions(opts)
|
||||
if label == nil {
|
||||
label = labels.Everything()
|
||||
}
|
||||
list := &v1beta1.VolumeUploadSourceList{ListMeta: obj.(*v1beta1.VolumeUploadSourceList).ListMeta}
|
||||
for _, item := range obj.(*v1beta1.VolumeUploadSourceList).Items {
|
||||
if label.Matches(labels.Set(item.Labels)) {
|
||||
list.Items = append(list.Items, item)
|
||||
}
|
||||
}
|
||||
return list, err
|
||||
}
|
||||
|
||||
// Watch returns a watch.Interface that watches the requested volumeUploadSources.
|
||||
func (c *FakeVolumeUploadSources) Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) {
|
||||
return c.Fake.
|
||||
InvokesWatch(testing.NewWatchAction(volumeuploadsourcesResource, c.ns, opts))
|
||||
|
||||
}
|
||||
|
||||
// Create takes the representation of a volumeUploadSource and creates it. Returns the server's representation of the volumeUploadSource, and an error, if there is any.
|
||||
func (c *FakeVolumeUploadSources) Create(ctx context.Context, volumeUploadSource *v1beta1.VolumeUploadSource, opts v1.CreateOptions) (result *v1beta1.VolumeUploadSource, err error) {
|
||||
obj, err := c.Fake.
|
||||
Invokes(testing.NewCreateAction(volumeuploadsourcesResource, c.ns, volumeUploadSource), &v1beta1.VolumeUploadSource{})
|
||||
|
||||
if obj == nil {
|
||||
return nil, err
|
||||
}
|
||||
return obj.(*v1beta1.VolumeUploadSource), err
|
||||
}
|
||||
|
||||
// Update takes the representation of a volumeUploadSource and updates it. Returns the server's representation of the volumeUploadSource, and an error, if there is any.
|
||||
func (c *FakeVolumeUploadSources) Update(ctx context.Context, volumeUploadSource *v1beta1.VolumeUploadSource, opts v1.UpdateOptions) (result *v1beta1.VolumeUploadSource, err error) {
|
||||
obj, err := c.Fake.
|
||||
Invokes(testing.NewUpdateAction(volumeuploadsourcesResource, c.ns, volumeUploadSource), &v1beta1.VolumeUploadSource{})
|
||||
|
||||
if obj == nil {
|
||||
return nil, err
|
||||
}
|
||||
return obj.(*v1beta1.VolumeUploadSource), err
|
||||
}
|
||||
|
||||
// UpdateStatus was generated because the type contains a Status member.
|
||||
// Add a +genclient:noStatus comment above the type to avoid generating UpdateStatus().
|
||||
func (c *FakeVolumeUploadSources) UpdateStatus(ctx context.Context, volumeUploadSource *v1beta1.VolumeUploadSource, opts v1.UpdateOptions) (*v1beta1.VolumeUploadSource, error) {
|
||||
obj, err := c.Fake.
|
||||
Invokes(testing.NewUpdateSubresourceAction(volumeuploadsourcesResource, "status", c.ns, volumeUploadSource), &v1beta1.VolumeUploadSource{})
|
||||
|
||||
if obj == nil {
|
||||
return nil, err
|
||||
}
|
||||
return obj.(*v1beta1.VolumeUploadSource), err
|
||||
}
|
||||
|
||||
// Delete takes name of the volumeUploadSource and deletes it. Returns an error if one occurs.
|
||||
func (c *FakeVolumeUploadSources) Delete(ctx context.Context, name string, opts v1.DeleteOptions) error {
|
||||
_, err := c.Fake.
|
||||
Invokes(testing.NewDeleteActionWithOptions(volumeuploadsourcesResource, c.ns, name, opts), &v1beta1.VolumeUploadSource{})
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
// DeleteCollection deletes a collection of objects.
|
||||
func (c *FakeVolumeUploadSources) DeleteCollection(ctx context.Context, opts v1.DeleteOptions, listOpts v1.ListOptions) error {
|
||||
action := testing.NewDeleteCollectionAction(volumeuploadsourcesResource, c.ns, listOpts)
|
||||
|
||||
_, err := c.Fake.Invokes(action, &v1beta1.VolumeUploadSourceList{})
|
||||
return err
|
||||
}
|
||||
|
||||
// Patch applies the patch and returns the patched volumeUploadSource.
|
||||
func (c *FakeVolumeUploadSources) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *v1beta1.VolumeUploadSource, err error) {
|
||||
obj, err := c.Fake.
|
||||
Invokes(testing.NewPatchSubresourceAction(volumeuploadsourcesResource, c.ns, name, pt, data, subresources...), &v1beta1.VolumeUploadSource{})
|
||||
|
||||
if obj == nil {
|
||||
return nil, err
|
||||
}
|
||||
return obj.(*v1beta1.VolumeUploadSource), err
|
||||
}
|
@ -33,3 +33,5 @@ type ObjectTransferExpansion interface{}
|
||||
type StorageProfileExpansion interface{}
|
||||
|
||||
type VolumeImportSourceExpansion interface{}
|
||||
|
||||
type VolumeUploadSourceExpansion interface{}
|
||||
|
@ -0,0 +1,195 @@
|
||||
/*
|
||||
Copyright 2018 The CDI Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
// Code generated by client-gen. DO NOT EDIT.
|
||||
|
||||
package v1beta1
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
types "k8s.io/apimachinery/pkg/types"
|
||||
watch "k8s.io/apimachinery/pkg/watch"
|
||||
rest "k8s.io/client-go/rest"
|
||||
v1beta1 "kubevirt.io/containerized-data-importer-api/pkg/apis/core/v1beta1"
|
||||
scheme "kubevirt.io/containerized-data-importer/pkg/client/clientset/versioned/scheme"
|
||||
)
|
||||
|
||||
// VolumeUploadSourcesGetter has a method to return a VolumeUploadSourceInterface.
|
||||
// A group's client should implement this interface.
|
||||
type VolumeUploadSourcesGetter interface {
|
||||
VolumeUploadSources(namespace string) VolumeUploadSourceInterface
|
||||
}
|
||||
|
||||
// VolumeUploadSourceInterface has methods to work with VolumeUploadSource resources.
|
||||
type VolumeUploadSourceInterface interface {
|
||||
Create(ctx context.Context, volumeUploadSource *v1beta1.VolumeUploadSource, opts v1.CreateOptions) (*v1beta1.VolumeUploadSource, error)
|
||||
Update(ctx context.Context, volumeUploadSource *v1beta1.VolumeUploadSource, opts v1.UpdateOptions) (*v1beta1.VolumeUploadSource, error)
|
||||
UpdateStatus(ctx context.Context, volumeUploadSource *v1beta1.VolumeUploadSource, opts v1.UpdateOptions) (*v1beta1.VolumeUploadSource, error)
|
||||
Delete(ctx context.Context, name string, opts v1.DeleteOptions) error
|
||||
DeleteCollection(ctx context.Context, opts v1.DeleteOptions, listOpts v1.ListOptions) error
|
||||
Get(ctx context.Context, name string, opts v1.GetOptions) (*v1beta1.VolumeUploadSource, error)
|
||||
List(ctx context.Context, opts v1.ListOptions) (*v1beta1.VolumeUploadSourceList, error)
|
||||
Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error)
|
||||
Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *v1beta1.VolumeUploadSource, err error)
|
||||
VolumeUploadSourceExpansion
|
||||
}
|
||||
|
||||
// volumeUploadSources implements VolumeUploadSourceInterface
|
||||
type volumeUploadSources struct {
|
||||
client rest.Interface
|
||||
ns string
|
||||
}
|
||||
|
||||
// newVolumeUploadSources returns a VolumeUploadSources
|
||||
func newVolumeUploadSources(c *CdiV1beta1Client, namespace string) *volumeUploadSources {
|
||||
return &volumeUploadSources{
|
||||
client: c.RESTClient(),
|
||||
ns: namespace,
|
||||
}
|
||||
}
|
||||
|
||||
// Get takes name of the volumeUploadSource, and returns the corresponding volumeUploadSource object, and an error if there is any.
|
||||
func (c *volumeUploadSources) Get(ctx context.Context, name string, options v1.GetOptions) (result *v1beta1.VolumeUploadSource, err error) {
|
||||
result = &v1beta1.VolumeUploadSource{}
|
||||
err = c.client.Get().
|
||||
Namespace(c.ns).
|
||||
Resource("volumeuploadsources").
|
||||
Name(name).
|
||||
VersionedParams(&options, scheme.ParameterCodec).
|
||||
Do(ctx).
|
||||
Into(result)
|
||||
return
|
||||
}
|
||||
|
||||
// List takes label and field selectors, and returns the list of VolumeUploadSources that match those selectors.
|
||||
func (c *volumeUploadSources) List(ctx context.Context, opts v1.ListOptions) (result *v1beta1.VolumeUploadSourceList, err error) {
|
||||
var timeout time.Duration
|
||||
if opts.TimeoutSeconds != nil {
|
||||
timeout = time.Duration(*opts.TimeoutSeconds) * time.Second
|
||||
}
|
||||
result = &v1beta1.VolumeUploadSourceList{}
|
||||
err = c.client.Get().
|
||||
Namespace(c.ns).
|
||||
Resource("volumeuploadsources").
|
||||
VersionedParams(&opts, scheme.ParameterCodec).
|
||||
Timeout(timeout).
|
||||
Do(ctx).
|
||||
Into(result)
|
||||
return
|
||||
}
|
||||
|
||||
// Watch returns a watch.Interface that watches the requested volumeUploadSources.
|
||||
func (c *volumeUploadSources) Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) {
|
||||
var timeout time.Duration
|
||||
if opts.TimeoutSeconds != nil {
|
||||
timeout = time.Duration(*opts.TimeoutSeconds) * time.Second
|
||||
}
|
||||
opts.Watch = true
|
||||
return c.client.Get().
|
||||
Namespace(c.ns).
|
||||
Resource("volumeuploadsources").
|
||||
VersionedParams(&opts, scheme.ParameterCodec).
|
||||
Timeout(timeout).
|
||||
Watch(ctx)
|
||||
}
|
||||
|
||||
// Create takes the representation of a volumeUploadSource and creates it. Returns the server's representation of the volumeUploadSource, and an error, if there is any.
|
||||
func (c *volumeUploadSources) Create(ctx context.Context, volumeUploadSource *v1beta1.VolumeUploadSource, opts v1.CreateOptions) (result *v1beta1.VolumeUploadSource, err error) {
|
||||
result = &v1beta1.VolumeUploadSource{}
|
||||
err = c.client.Post().
|
||||
Namespace(c.ns).
|
||||
Resource("volumeuploadsources").
|
||||
VersionedParams(&opts, scheme.ParameterCodec).
|
||||
Body(volumeUploadSource).
|
||||
Do(ctx).
|
||||
Into(result)
|
||||
return
|
||||
}
|
||||
|
||||
// Update takes the representation of a volumeUploadSource and updates it. Returns the server's representation of the volumeUploadSource, and an error, if there is any.
|
||||
func (c *volumeUploadSources) Update(ctx context.Context, volumeUploadSource *v1beta1.VolumeUploadSource, opts v1.UpdateOptions) (result *v1beta1.VolumeUploadSource, err error) {
|
||||
result = &v1beta1.VolumeUploadSource{}
|
||||
err = c.client.Put().
|
||||
Namespace(c.ns).
|
||||
Resource("volumeuploadsources").
|
||||
Name(volumeUploadSource.Name).
|
||||
VersionedParams(&opts, scheme.ParameterCodec).
|
||||
Body(volumeUploadSource).
|
||||
Do(ctx).
|
||||
Into(result)
|
||||
return
|
||||
}
|
||||
|
||||
// UpdateStatus was generated because the type contains a Status member.
|
||||
// Add a +genclient:noStatus comment above the type to avoid generating UpdateStatus().
|
||||
func (c *volumeUploadSources) UpdateStatus(ctx context.Context, volumeUploadSource *v1beta1.VolumeUploadSource, opts v1.UpdateOptions) (result *v1beta1.VolumeUploadSource, err error) {
|
||||
result = &v1beta1.VolumeUploadSource{}
|
||||
err = c.client.Put().
|
||||
Namespace(c.ns).
|
||||
Resource("volumeuploadsources").
|
||||
Name(volumeUploadSource.Name).
|
||||
SubResource("status").
|
||||
VersionedParams(&opts, scheme.ParameterCodec).
|
||||
Body(volumeUploadSource).
|
||||
Do(ctx).
|
||||
Into(result)
|
||||
return
|
||||
}
|
||||
|
||||
// Delete takes name of the volumeUploadSource and deletes it. Returns an error if one occurs.
|
||||
func (c *volumeUploadSources) Delete(ctx context.Context, name string, opts v1.DeleteOptions) error {
|
||||
return c.client.Delete().
|
||||
Namespace(c.ns).
|
||||
Resource("volumeuploadsources").
|
||||
Name(name).
|
||||
Body(&opts).
|
||||
Do(ctx).
|
||||
Error()
|
||||
}
|
||||
|
||||
// DeleteCollection deletes a collection of objects.
|
||||
func (c *volumeUploadSources) DeleteCollection(ctx context.Context, opts v1.DeleteOptions, listOpts v1.ListOptions) error {
|
||||
var timeout time.Duration
|
||||
if listOpts.TimeoutSeconds != nil {
|
||||
timeout = time.Duration(*listOpts.TimeoutSeconds) * time.Second
|
||||
}
|
||||
return c.client.Delete().
|
||||
Namespace(c.ns).
|
||||
Resource("volumeuploadsources").
|
||||
VersionedParams(&listOpts, scheme.ParameterCodec).
|
||||
Timeout(timeout).
|
||||
Body(&opts).
|
||||
Do(ctx).
|
||||
Error()
|
||||
}
|
||||
|
||||
// Patch applies the patch and returns the patched volumeUploadSource.
|
||||
func (c *volumeUploadSources) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *v1beta1.VolumeUploadSource, err error) {
|
||||
result = &v1beta1.VolumeUploadSource{}
|
||||
err = c.client.Patch(pt).
|
||||
Namespace(c.ns).
|
||||
Resource("volumeuploadsources").
|
||||
Name(name).
|
||||
SubResource(subresources...).
|
||||
VersionedParams(&opts, scheme.ParameterCodec).
|
||||
Body(data).
|
||||
Do(ctx).
|
||||
Into(result)
|
||||
return
|
||||
}
|
@ -12,6 +12,7 @@ go_library(
|
||||
"objecttransfer.go",
|
||||
"storageprofile.go",
|
||||
"volumeimportsource.go",
|
||||
"volumeuploadsource.go",
|
||||
],
|
||||
importpath = "kubevirt.io/containerized-data-importer/pkg/client/informers/externalversions/core/v1beta1",
|
||||
visibility = ["//visibility:public"],
|
||||
|
@ -40,6 +40,8 @@ type Interface interface {
|
||||
StorageProfiles() StorageProfileInformer
|
||||
// VolumeImportSources returns a VolumeImportSourceInformer.
|
||||
VolumeImportSources() VolumeImportSourceInformer
|
||||
// VolumeUploadSources returns a VolumeUploadSourceInformer.
|
||||
VolumeUploadSources() VolumeUploadSourceInformer
|
||||
}
|
||||
|
||||
type version struct {
|
||||
@ -92,3 +94,8 @@ func (v *version) StorageProfiles() StorageProfileInformer {
|
||||
func (v *version) VolumeImportSources() VolumeImportSourceInformer {
|
||||
return &volumeImportSourceInformer{factory: v.factory, namespace: v.namespace, tweakListOptions: v.tweakListOptions}
|
||||
}
|
||||
|
||||
// VolumeUploadSources returns a VolumeUploadSourceInformer.
|
||||
func (v *version) VolumeUploadSources() VolumeUploadSourceInformer {
|
||||
return &volumeUploadSourceInformer{factory: v.factory, namespace: v.namespace, tweakListOptions: v.tweakListOptions}
|
||||
}
|
||||
|
@ -0,0 +1,90 @@
|
||||
/*
|
||||
Copyright 2018 The CDI Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
// Code generated by informer-gen. DO NOT EDIT.
|
||||
|
||||
package v1beta1
|
||||
|
||||
import (
|
||||
"context"
|
||||
time "time"
|
||||
|
||||
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
runtime "k8s.io/apimachinery/pkg/runtime"
|
||||
watch "k8s.io/apimachinery/pkg/watch"
|
||||
cache "k8s.io/client-go/tools/cache"
|
||||
corev1beta1 "kubevirt.io/containerized-data-importer-api/pkg/apis/core/v1beta1"
|
||||
versioned "kubevirt.io/containerized-data-importer/pkg/client/clientset/versioned"
|
||||
internalinterfaces "kubevirt.io/containerized-data-importer/pkg/client/informers/externalversions/internalinterfaces"
|
||||
v1beta1 "kubevirt.io/containerized-data-importer/pkg/client/listers/core/v1beta1"
|
||||
)
|
||||
|
||||
// VolumeUploadSourceInformer provides access to a shared informer and lister for
|
||||
// VolumeUploadSources.
|
||||
type VolumeUploadSourceInformer interface {
|
||||
Informer() cache.SharedIndexInformer
|
||||
Lister() v1beta1.VolumeUploadSourceLister
|
||||
}
|
||||
|
||||
type volumeUploadSourceInformer struct {
|
||||
factory internalinterfaces.SharedInformerFactory
|
||||
tweakListOptions internalinterfaces.TweakListOptionsFunc
|
||||
namespace string
|
||||
}
|
||||
|
||||
// NewVolumeUploadSourceInformer constructs a new informer for VolumeUploadSource type.
|
||||
// Always prefer using an informer factory to get a shared informer instead of getting an independent
|
||||
// one. This reduces memory footprint and number of connections to the server.
|
||||
func NewVolumeUploadSourceInformer(client versioned.Interface, namespace string, resyncPeriod time.Duration, indexers cache.Indexers) cache.SharedIndexInformer {
|
||||
return NewFilteredVolumeUploadSourceInformer(client, namespace, resyncPeriod, indexers, nil)
|
||||
}
|
||||
|
||||
// NewFilteredVolumeUploadSourceInformer constructs a new informer for VolumeUploadSource type.
|
||||
// Always prefer using an informer factory to get a shared informer instead of getting an independent
|
||||
// one. This reduces memory footprint and number of connections to the server.
|
||||
func NewFilteredVolumeUploadSourceInformer(client versioned.Interface, namespace string, resyncPeriod time.Duration, indexers cache.Indexers, tweakListOptions internalinterfaces.TweakListOptionsFunc) cache.SharedIndexInformer {
|
||||
return cache.NewSharedIndexInformer(
|
||||
&cache.ListWatch{
|
||||
ListFunc: func(options v1.ListOptions) (runtime.Object, error) {
|
||||
if tweakListOptions != nil {
|
||||
tweakListOptions(&options)
|
||||
}
|
||||
return client.CdiV1beta1().VolumeUploadSources(namespace).List(context.TODO(), options)
|
||||
},
|
||||
WatchFunc: func(options v1.ListOptions) (watch.Interface, error) {
|
||||
if tweakListOptions != nil {
|
||||
tweakListOptions(&options)
|
||||
}
|
||||
return client.CdiV1beta1().VolumeUploadSources(namespace).Watch(context.TODO(), options)
|
||||
},
|
||||
},
|
||||
&corev1beta1.VolumeUploadSource{},
|
||||
resyncPeriod,
|
||||
indexers,
|
||||
)
|
||||
}
|
||||
|
||||
func (f *volumeUploadSourceInformer) defaultInformer(client versioned.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer {
|
||||
return NewFilteredVolumeUploadSourceInformer(client, f.namespace, resyncPeriod, cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc}, f.tweakListOptions)
|
||||
}
|
||||
|
||||
func (f *volumeUploadSourceInformer) Informer() cache.SharedIndexInformer {
|
||||
return f.factory.InformerFor(&corev1beta1.VolumeUploadSource{}, f.defaultInformer)
|
||||
}
|
||||
|
||||
func (f *volumeUploadSourceInformer) Lister() v1beta1.VolumeUploadSourceLister {
|
||||
return v1beta1.NewVolumeUploadSourceLister(f.Informer().GetIndexer())
|
||||
}
|
@ -75,6 +75,8 @@ func (f *sharedInformerFactory) ForResource(resource schema.GroupVersionResource
|
||||
return &genericInformer{resource: resource.GroupResource(), informer: f.Cdi().V1beta1().StorageProfiles().Informer()}, nil
|
||||
case v1beta1.SchemeGroupVersion.WithResource("volumeimportsources"):
|
||||
return &genericInformer{resource: resource.GroupResource(), informer: f.Cdi().V1beta1().VolumeImportSources().Informer()}, nil
|
||||
case v1beta1.SchemeGroupVersion.WithResource("volumeuploadsources"):
|
||||
return &genericInformer{resource: resource.GroupResource(), informer: f.Cdi().V1beta1().VolumeUploadSources().Informer()}, nil
|
||||
|
||||
// Group=upload.cdi.kubevirt.io, Version=v1beta1
|
||||
case uploadv1beta1.SchemeGroupVersion.WithResource("uploadtokenrequests"):
|
||||
|
@ -12,6 +12,7 @@ go_library(
|
||||
"objecttransfer.go",
|
||||
"storageprofile.go",
|
||||
"volumeimportsource.go",
|
||||
"volumeuploadsource.go",
|
||||
],
|
||||
importpath = "kubevirt.io/containerized-data-importer/pkg/client/listers/core/v1beta1",
|
||||
visibility = ["//visibility:public"],
|
||||
|
@ -65,3 +65,11 @@ type VolumeImportSourceListerExpansion interface{}
|
||||
// VolumeImportSourceNamespaceListerExpansion allows custom methods to be added to
|
||||
// VolumeImportSourceNamespaceLister.
|
||||
type VolumeImportSourceNamespaceListerExpansion interface{}
|
||||
|
||||
// VolumeUploadSourceListerExpansion allows custom methods to be added to
|
||||
// VolumeUploadSourceLister.
|
||||
type VolumeUploadSourceListerExpansion interface{}
|
||||
|
||||
// VolumeUploadSourceNamespaceListerExpansion allows custom methods to be added to
|
||||
// VolumeUploadSourceNamespaceLister.
|
||||
type VolumeUploadSourceNamespaceListerExpansion interface{}
|
||||
|
99
pkg/client/listers/core/v1beta1/volumeuploadsource.go
Normal file
99
pkg/client/listers/core/v1beta1/volumeuploadsource.go
Normal file
@ -0,0 +1,99 @@
|
||||
/*
|
||||
Copyright 2018 The CDI Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
// Code generated by lister-gen. DO NOT EDIT.
|
||||
|
||||
package v1beta1
|
||||
|
||||
import (
|
||||
"k8s.io/apimachinery/pkg/api/errors"
|
||||
"k8s.io/apimachinery/pkg/labels"
|
||||
"k8s.io/client-go/tools/cache"
|
||||
v1beta1 "kubevirt.io/containerized-data-importer-api/pkg/apis/core/v1beta1"
|
||||
)
|
||||
|
||||
// VolumeUploadSourceLister helps list VolumeUploadSources.
|
||||
// All objects returned here must be treated as read-only.
|
||||
type VolumeUploadSourceLister interface {
|
||||
// List lists all VolumeUploadSources in the indexer.
|
||||
// Objects returned here must be treated as read-only.
|
||||
List(selector labels.Selector) (ret []*v1beta1.VolumeUploadSource, err error)
|
||||
// VolumeUploadSources returns an object that can list and get VolumeUploadSources.
|
||||
VolumeUploadSources(namespace string) VolumeUploadSourceNamespaceLister
|
||||
VolumeUploadSourceListerExpansion
|
||||
}
|
||||
|
||||
// volumeUploadSourceLister implements the VolumeUploadSourceLister interface.
|
||||
type volumeUploadSourceLister struct {
|
||||
indexer cache.Indexer
|
||||
}
|
||||
|
||||
// NewVolumeUploadSourceLister returns a new VolumeUploadSourceLister.
|
||||
func NewVolumeUploadSourceLister(indexer cache.Indexer) VolumeUploadSourceLister {
|
||||
return &volumeUploadSourceLister{indexer: indexer}
|
||||
}
|
||||
|
||||
// List lists all VolumeUploadSources in the indexer.
|
||||
func (s *volumeUploadSourceLister) List(selector labels.Selector) (ret []*v1beta1.VolumeUploadSource, err error) {
|
||||
err = cache.ListAll(s.indexer, selector, func(m interface{}) {
|
||||
ret = append(ret, m.(*v1beta1.VolumeUploadSource))
|
||||
})
|
||||
return ret, err
|
||||
}
|
||||
|
||||
// VolumeUploadSources returns an object that can list and get VolumeUploadSources.
|
||||
func (s *volumeUploadSourceLister) VolumeUploadSources(namespace string) VolumeUploadSourceNamespaceLister {
|
||||
return volumeUploadSourceNamespaceLister{indexer: s.indexer, namespace: namespace}
|
||||
}
|
||||
|
||||
// VolumeUploadSourceNamespaceLister helps list and get VolumeUploadSources.
|
||||
// All objects returned here must be treated as read-only.
|
||||
type VolumeUploadSourceNamespaceLister interface {
|
||||
// List lists all VolumeUploadSources in the indexer for a given namespace.
|
||||
// Objects returned here must be treated as read-only.
|
||||
List(selector labels.Selector) (ret []*v1beta1.VolumeUploadSource, err error)
|
||||
// Get retrieves the VolumeUploadSource from the indexer for a given namespace and name.
|
||||
// Objects returned here must be treated as read-only.
|
||||
Get(name string) (*v1beta1.VolumeUploadSource, error)
|
||||
VolumeUploadSourceNamespaceListerExpansion
|
||||
}
|
||||
|
||||
// volumeUploadSourceNamespaceLister implements the VolumeUploadSourceNamespaceLister
|
||||
// interface.
|
||||
type volumeUploadSourceNamespaceLister struct {
|
||||
indexer cache.Indexer
|
||||
namespace string
|
||||
}
|
||||
|
||||
// List lists all VolumeUploadSources in the indexer for a given namespace.
|
||||
func (s volumeUploadSourceNamespaceLister) List(selector labels.Selector) (ret []*v1beta1.VolumeUploadSource, err error) {
|
||||
err = cache.ListAllByNamespace(s.indexer, s.namespace, selector, func(m interface{}) {
|
||||
ret = append(ret, m.(*v1beta1.VolumeUploadSource))
|
||||
})
|
||||
return ret, err
|
||||
}
|
||||
|
||||
// Get retrieves the VolumeUploadSource from the indexer for a given namespace and name.
|
||||
func (s volumeUploadSourceNamespaceLister) Get(name string) (*v1beta1.VolumeUploadSource, error) {
|
||||
obj, exists, err := s.indexer.GetByKey(s.namespace + "/" + name)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if !exists {
|
||||
return nil, errors.NewNotFound(v1beta1.Resource("volumeuploadsource"), name)
|
||||
}
|
||||
return obj.(*v1beta1.VolumeUploadSource), nil
|
||||
}
|
@ -5,6 +5,7 @@ go_library(
|
||||
srcs = [
|
||||
"import-populator.go",
|
||||
"populator-base.go",
|
||||
"upload-populator.go",
|
||||
"util.go",
|
||||
],
|
||||
importpath = "kubevirt.io/containerized-data-importer/pkg/controller/populators",
|
||||
@ -40,6 +41,7 @@ go_test(
|
||||
srcs = [
|
||||
"import-populator_test.go",
|
||||
"populators_suite_test.go",
|
||||
"upload-populator_test.go",
|
||||
],
|
||||
embed = [":go_default_library"],
|
||||
deps = [
|
||||
@ -50,9 +52,13 @@ go_test(
|
||||
"//tests/reporters:go_default_library",
|
||||
"//vendor/github.com/kubernetes-csi/external-snapshotter/client/v6/apis/volumesnapshot/v1:go_default_library",
|
||||
"//vendor/github.com/onsi/ginkgo:go_default_library",
|
||||
"//vendor/github.com/onsi/ginkgo/extensions/table:go_default_library",
|
||||
"//vendor/github.com/onsi/gomega:go_default_library",
|
||||
"//vendor/k8s.io/api/core/v1:go_default_library",
|
||||
"//vendor/k8s.io/api/storage/v1:go_default_library",
|
||||
"//vendor/k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1:go_default_library",
|
||||
"//vendor/k8s.io/apimachinery/pkg/api/errors:go_default_library",
|
||||
"//vendor/k8s.io/apimachinery/pkg/api/resource:go_default_library",
|
||||
"//vendor/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
|
||||
"//vendor/k8s.io/apimachinery/pkg/runtime:go_default_library",
|
||||
"//vendor/k8s.io/apimachinery/pkg/runtime/schema:go_default_library",
|
||||
@ -61,6 +67,7 @@ go_test(
|
||||
"//vendor/k8s.io/client-go/tools/record:go_default_library",
|
||||
"//vendor/sigs.k8s.io/controller-runtime/pkg/client/fake:go_default_library",
|
||||
"//vendor/sigs.k8s.io/controller-runtime/pkg/log:go_default_library",
|
||||
"//vendor/sigs.k8s.io/controller-runtime/pkg/log/zap:go_default_library",
|
||||
"//vendor/sigs.k8s.io/controller-runtime/pkg/reconcile:go_default_library",
|
||||
],
|
||||
)
|
||||
|
@ -262,7 +262,7 @@ func (r *ReconcilerBase) createPVCPrime(pvc *corev1.PersistentVolumeClaim, sourc
|
||||
}
|
||||
util.SetRecommendedLabels(pvcPrime, r.installerLabels, "cdi-controller")
|
||||
|
||||
// disk or image size, inflate it with overhead if necessary
|
||||
// disk or image size, inflate it with overhead
|
||||
requestedSize := pvc.Spec.Resources.Requests[corev1.ResourceStorage]
|
||||
requestedSize, err := cc.InflateSizeWithOverhead(r.client, requestedSize.Value(), &pvc.Spec)
|
||||
if err != nil {
|
||||
|
@ -6,6 +6,9 @@ import (
|
||||
|
||||
"testing"
|
||||
|
||||
logf "sigs.k8s.io/controller-runtime/pkg/log"
|
||||
"sigs.k8s.io/controller-runtime/pkg/log/zap"
|
||||
|
||||
"kubevirt.io/containerized-data-importer/tests/reporters"
|
||||
)
|
||||
|
||||
@ -13,3 +16,7 @@ func TestPopulators(t *testing.T) {
|
||||
RegisterFailHandler(Fail)
|
||||
RunSpecsWithDefaultAndCustomReporters(t, "Populators Suite", reporters.NewReporters())
|
||||
}
|
||||
|
||||
var _ = BeforeSuite(func() {
|
||||
logf.SetLogger(zap.New(zap.WriteTo(GinkgoWriter), zap.UseDevMode(true)))
|
||||
})
|
||||
|
171
pkg/controller/populators/upload-populator.go
Normal file
171
pkg/controller/populators/upload-populator.go
Normal file
@ -0,0 +1,171 @@
|
||||
/*
|
||||
Copyright 2023 The CDI Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package populators
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"strconv"
|
||||
|
||||
"github.com/go-logr/logr"
|
||||
corev1 "k8s.io/api/core/v1"
|
||||
k8serrors "k8s.io/apimachinery/pkg/api/errors"
|
||||
"k8s.io/apimachinery/pkg/types"
|
||||
cdiv1 "kubevirt.io/containerized-data-importer-api/pkg/apis/core/v1beta1"
|
||||
cc "kubevirt.io/containerized-data-importer/pkg/controller/common"
|
||||
featuregates "kubevirt.io/containerized-data-importer/pkg/feature-gates"
|
||||
"sigs.k8s.io/controller-runtime/pkg/client"
|
||||
"sigs.k8s.io/controller-runtime/pkg/controller"
|
||||
"sigs.k8s.io/controller-runtime/pkg/manager"
|
||||
"sigs.k8s.io/controller-runtime/pkg/reconcile"
|
||||
)
|
||||
|
||||
const (
|
||||
uploadPopulatorName = "upload-populator"
|
||||
|
||||
// errUploadFailed provides a const to indicate upload has failed
|
||||
errUploadFailed = "UploadFailed"
|
||||
// uploadSucceeded provides a const to indicate upload has succeeded
|
||||
uploadSucceeded = "UploadSucceeded"
|
||||
|
||||
// messageUploadFailed provides a const to form upload has failed message
|
||||
messageUploadFailed = "Upload into %s failed"
|
||||
// messageUploadSucceeded provides a const to form upload has succeeded message
|
||||
messageUploadSucceeded = "Successfully uploaded into %s"
|
||||
)
|
||||
|
||||
// UploadPopulatorReconciler members
|
||||
type UploadPopulatorReconciler struct {
|
||||
ReconcilerBase
|
||||
}
|
||||
|
||||
// NewUploadPopulator creates a new instance of the upload populator
|
||||
func NewUploadPopulator(
|
||||
ctx context.Context,
|
||||
mgr manager.Manager,
|
||||
log logr.Logger,
|
||||
installerLabels map[string]string,
|
||||
) (controller.Controller, error) {
|
||||
client := mgr.GetClient()
|
||||
reconciler := &UploadPopulatorReconciler{
|
||||
ReconcilerBase: ReconcilerBase{
|
||||
client: client,
|
||||
scheme: mgr.GetScheme(),
|
||||
log: log.WithName(uploadPopulatorName),
|
||||
recorder: mgr.GetEventRecorderFor(uploadPopulatorName),
|
||||
featureGates: featuregates.NewFeatureGates(client),
|
||||
installerLabels: installerLabels,
|
||||
sourceKind: cdiv1.VolumeUploadSourceRef,
|
||||
},
|
||||
}
|
||||
|
||||
uploadPopulator, err := controller.New(uploadPopulatorName, mgr, controller.Options{
|
||||
Reconciler: reconciler,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if err := addCommonPopulatorsWatches(mgr, uploadPopulator, log, cdiv1.VolumeUploadSourceRef, &cdiv1.VolumeUploadSource{}); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return uploadPopulator, nil
|
||||
}
|
||||
|
||||
// Reconcile the reconcile loop for the PVC with DataSourceRef of VolumeUploadSource kind
|
||||
func (r *UploadPopulatorReconciler) Reconcile(_ context.Context, req reconcile.Request) (reconcile.Result, error) {
|
||||
log := r.log.WithValues("PVC", req.NamespacedName)
|
||||
log.V(1).Info("reconciling Upload Source PVCs")
|
||||
return r.reconcile(req, r, log)
|
||||
}
|
||||
|
||||
// upload-specific implementation of getPopulationSource
|
||||
func (r *UploadPopulatorReconciler) getPopulationSource(namespace, name string) (client.Object, error) {
|
||||
uploadSource := &cdiv1.VolumeUploadSource{}
|
||||
uploadSourceKey := types.NamespacedName{Namespace: namespace, Name: name}
|
||||
if err := r.client.Get(context.TODO(), uploadSourceKey, uploadSource); err != nil {
|
||||
// reconcile will be triggered once created
|
||||
if k8serrors.IsNotFound(err) {
|
||||
return nil, nil
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
return uploadSource, nil
|
||||
}
|
||||
|
||||
// Upload-specific implementation of updatePVCForPopulation
|
||||
func (r *UploadPopulatorReconciler) updatePVCForPopulation(pvc *corev1.PersistentVolumeClaim, source client.Object) {
|
||||
pvc.Annotations[cc.AnnUploadRequest] = ""
|
||||
uploadSource := source.(*cdiv1.VolumeUploadSource)
|
||||
pvc.Annotations[cc.AnnContentType] = cc.GetContentType(string(uploadSource.Spec.ContentType))
|
||||
pvc.Annotations[cc.AnnPopulatorKind] = cdiv1.VolumeUploadSourceRef
|
||||
pvc.Annotations[cc.AnnPreallocationRequested] = strconv.FormatBool(cc.GetPreallocation(r.client, uploadSource.Spec.Preallocation))
|
||||
}
|
||||
|
||||
func (r *UploadPopulatorReconciler) updatePVCPrimeNameAnnotation(pvc *corev1.PersistentVolumeClaim, pvcPrimeName string) (bool, error) {
|
||||
if _, ok := pvc.Annotations[AnnPVCPrimeName]; ok {
|
||||
return false, nil
|
||||
}
|
||||
|
||||
if pvc.Annotations == nil {
|
||||
pvc.Annotations = make(map[string]string)
|
||||
}
|
||||
pvc.Annotations[AnnPVCPrimeName] = pvcPrimeName
|
||||
if err := r.client.Update(context.TODO(), pvc); err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return true, nil
|
||||
}
|
||||
|
||||
func (r *UploadPopulatorReconciler) removePVCPrimeNameAnnotation(pvc *corev1.PersistentVolumeClaim) error {
|
||||
if _, ok := pvc.Annotations[AnnPVCPrimeName]; !ok {
|
||||
return nil
|
||||
}
|
||||
|
||||
delete(pvc.Annotations, AnnPVCPrimeName)
|
||||
return r.client.Update(context.TODO(), pvc)
|
||||
}
|
||||
|
||||
func (r *UploadPopulatorReconciler) reconcileTargetPVC(pvc, pvcPrime *corev1.PersistentVolumeClaim) (reconcile.Result, error) {
|
||||
updated, err := r.updatePVCPrimeNameAnnotation(pvc, pvcPrime.Name)
|
||||
if updated || err != nil {
|
||||
// wait for the annotation to be updated
|
||||
return reconcile.Result{}, err
|
||||
}
|
||||
|
||||
// Wait upload completes
|
||||
phase := pvcPrime.Annotations[cc.AnnPodPhase]
|
||||
switch phase {
|
||||
case string(corev1.PodFailed):
|
||||
// We'll get called later once it succeeds
|
||||
r.recorder.Eventf(pvcPrime, corev1.EventTypeWarning, errUploadFailed, fmt.Sprintf(messageUploadFailed, pvc.Name))
|
||||
case string(corev1.PodSucceeded):
|
||||
err := r.removePVCPrimeNameAnnotation(pvc)
|
||||
if err != nil {
|
||||
return reconcile.Result{}, err
|
||||
}
|
||||
// Once the upload is succeeded, we rebind the PV from PVC' to target PVC
|
||||
if err := r.rebindPV(pvc, pvcPrime); err != nil {
|
||||
return reconcile.Result{}, err
|
||||
}
|
||||
r.recorder.Eventf(pvc, corev1.EventTypeNormal, uploadSucceeded, fmt.Sprintf(messageUploadSucceeded, pvc))
|
||||
}
|
||||
|
||||
return reconcile.Result{}, nil
|
||||
}
|
338
pkg/controller/populators/upload-populator_test.go
Normal file
338
pkg/controller/populators/upload-populator_test.go
Normal file
@ -0,0 +1,338 @@
|
||||
/*
|
||||
Copyright 2023 The CDI Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package populators
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
. "github.com/onsi/ginkgo"
|
||||
. "github.com/onsi/ginkgo/extensions/table"
|
||||
. "github.com/onsi/gomega"
|
||||
|
||||
snapshotv1 "github.com/kubernetes-csi/external-snapshotter/client/v6/apis/volumesnapshot/v1"
|
||||
corev1 "k8s.io/api/core/v1"
|
||||
storagev1 "k8s.io/api/storage/v1"
|
||||
extv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
|
||||
"k8s.io/apimachinery/pkg/api/errors"
|
||||
"k8s.io/apimachinery/pkg/api/resource"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/runtime"
|
||||
"k8s.io/apimachinery/pkg/types"
|
||||
"k8s.io/client-go/kubernetes/scheme"
|
||||
"k8s.io/client-go/tools/record"
|
||||
"sigs.k8s.io/controller-runtime/pkg/client/fake"
|
||||
logf "sigs.k8s.io/controller-runtime/pkg/log"
|
||||
"sigs.k8s.io/controller-runtime/pkg/reconcile"
|
||||
|
||||
cdiv1 "kubevirt.io/containerized-data-importer-api/pkg/apis/core/v1beta1"
|
||||
"kubevirt.io/containerized-data-importer/pkg/common"
|
||||
cc "kubevirt.io/containerized-data-importer/pkg/controller/common"
|
||||
featuregates "kubevirt.io/containerized-data-importer/pkg/feature-gates"
|
||||
)
|
||||
|
||||
const (
|
||||
testPopulatorName = "upload-populator-test"
|
||||
testStorageClass = "test-sc"
|
||||
pvcPrimeUID = "pvcPrimeUID"
|
||||
)
|
||||
|
||||
var (
|
||||
uploadPopLog = logf.Log.WithName("upload-populator-controller-test")
|
||||
)
|
||||
|
||||
var _ = Describe("Datavolume controller reconcile loop", func() {
|
||||
DescribeTable("should create PVC prime", func(contentType string, preallocation bool) {
|
||||
pvc := newUploadPopulatorPVC("test-pvc")
|
||||
volumeUploadSourceCR := newUploadPopulatorCR(contentType, preallocation)
|
||||
scName := "test-sc"
|
||||
sc := cc.CreateStorageClassWithProvisioner(scName, map[string]string{cc.AnnDefaultStorageClass: "true"}, map[string]string{}, "csi-plugin")
|
||||
r := createUploadPopulatorReconciler(pvc, volumeUploadSourceCR, sc)
|
||||
_, err := r.Reconcile(context.TODO(), reconcile.Request{NamespacedName: types.NamespacedName{Name: "test-pvc", Namespace: metav1.NamespaceDefault}})
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
||||
expectEvent(r, createdPVCPrimeSuccessfully)
|
||||
|
||||
pvcPrime, err := r.getPVCPrime(pvc)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(pvcPrime).ToNot(BeNil())
|
||||
Expect(pvcPrime.GetAnnotations()).ToNot(BeNil())
|
||||
Expect(pvcPrime.GetAnnotations()[cc.AnnImmediateBinding]).To(Equal(""))
|
||||
Expect(pvcPrime.GetAnnotations()[cc.AnnUploadRequest]).To(Equal(""))
|
||||
Expect(pvcPrime.GetAnnotations()[cc.AnnContentType]).To(Equal(contentType))
|
||||
Expect(pvcPrime.GetAnnotations()[cc.AnnPreallocationRequested]).To(Equal(strconv.FormatBool(preallocation)))
|
||||
Expect(pvcPrime.GetAnnotations()[cc.AnnPopulatorKind]).To(Equal(cdiv1.VolumeUploadSourceRef))
|
||||
|
||||
_, err = r.Reconcile(context.TODO(), reconcile.Request{NamespacedName: types.NamespacedName{Name: "test-pvc", Namespace: metav1.NamespaceDefault}})
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
updatedPVC := &corev1.PersistentVolumeClaim{}
|
||||
err = r.client.Get(context.TODO(), types.NamespacedName{Name: "test-pvc", Namespace: metav1.NamespaceDefault}, updatedPVC)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(updatedPVC.GetAnnotations()).ToNot(BeNil())
|
||||
Expect(updatedPVC.GetAnnotations()[AnnPVCPrimeName]).To(Equal(pvcPrime.Name))
|
||||
},
|
||||
Entry("kubevirt content type", "kubevirt", false),
|
||||
Entry("kubevirt content type with preallocation", "kubevirt", true),
|
||||
Entry("archive content type", "archive", false),
|
||||
)
|
||||
|
||||
It("should set event if upload pod failed", func() {
|
||||
pvc := newUploadPopulatorPVC("test-pvc")
|
||||
pvc.Annotations = make(map[string]string)
|
||||
pvc.Annotations[AnnPVCPrimeName] = PVCPrimeName(pvc)
|
||||
uploadPV := uploadPV(pvc)
|
||||
|
||||
volumeUploadSourceCR := newUploadPopulatorCR("", false)
|
||||
scName := "test-sc"
|
||||
sc := cc.CreateStorageClassWithProvisioner(scName, map[string]string{cc.AnnDefaultStorageClass: "true"}, map[string]string{}, "csi-plugin")
|
||||
r := createUploadPopulatorReconciler(pvc, volumeUploadSourceCR, sc, uploadPV)
|
||||
|
||||
_, err := r.Reconcile(context.TODO(), reconcile.Request{NamespacedName: types.NamespacedName{Name: "test-pvc", Namespace: metav1.NamespaceDefault}})
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
pvcPrime, err := r.getPVCPrime(pvc)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
pvcPrime.Annotations[cc.AnnPodPhase] = string(corev1.PodFailed)
|
||||
pvcPrime.Spec.VolumeName = "test-pv"
|
||||
pvcPrime.UID = pvcPrimeUID
|
||||
err = r.client.Update(context.TODO(), pvcPrime)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
||||
_, err = r.Reconcile(context.TODO(), reconcile.Request{NamespacedName: types.NamespacedName{Name: "test-pvc", Namespace: metav1.NamespaceDefault}})
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
||||
updatedPV, err := r.getPV(pvcPrime.Spec.VolumeName)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
||||
//expect bind to remain to pvc'
|
||||
Expect(updatedPV.Spec.ClaimRef.Name).To(Equal(pvcPrime.Name))
|
||||
|
||||
expectEvent(r, errUploadFailed)
|
||||
})
|
||||
|
||||
It("should rebind PV to target PVC", func() {
|
||||
pvc := newUploadPopulatorPVC("test-pvc")
|
||||
pvc.Annotations = make(map[string]string)
|
||||
pvc.Annotations[AnnPVCPrimeName] = PVCPrimeName(pvc)
|
||||
uploadPV := uploadPV(pvc)
|
||||
|
||||
volumeUploadSourceCR := newUploadPopulatorCR("", false)
|
||||
scName := "test-sc"
|
||||
sc := cc.CreateStorageClassWithProvisioner(scName, map[string]string{cc.AnnDefaultStorageClass: "true"}, map[string]string{}, "csi-plugin")
|
||||
r := createUploadPopulatorReconciler(pvc, volumeUploadSourceCR, sc, uploadPV)
|
||||
|
||||
_, err := r.Reconcile(context.TODO(), reconcile.Request{NamespacedName: types.NamespacedName{Name: "test-pvc", Namespace: metav1.NamespaceDefault}})
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
pvcPrime, err := r.getPVCPrime(pvc)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
pvcPrime.Annotations[cc.AnnPodPhase] = string(corev1.PodSucceeded)
|
||||
pvcPrime.Spec.VolumeName = "test-pv"
|
||||
pvcPrime.UID = pvcPrimeUID
|
||||
err = r.client.Update(context.TODO(), pvcPrime)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
||||
_, err = r.Reconcile(context.TODO(), reconcile.Request{NamespacedName: types.NamespacedName{Name: "test-pvc", Namespace: metav1.NamespaceDefault}})
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
||||
updatedPV, err := r.getPV(pvcPrime.Spec.VolumeName)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
||||
Expect(updatedPV.Spec.ClaimRef.Name).To(Equal("test-pvc"))
|
||||
|
||||
//should remove the pvc prime annotation when upload completes
|
||||
updatedPVC := &corev1.PersistentVolumeClaim{}
|
||||
err = r.client.Get(context.TODO(), types.NamespacedName{Name: "test-pvc", Namespace: metav1.NamespaceDefault}, updatedPVC)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(updatedPVC.GetAnnotations()).To(BeNil())
|
||||
|
||||
expectEvent(r, uploadSucceeded)
|
||||
})
|
||||
|
||||
It("should clean PVCPrime when targetPVC bound", func() {
|
||||
pvc := newUploadPopulatorPVC("test-pvc")
|
||||
pvc.Spec.VolumeName = "test-pv"
|
||||
pvcPrime := newUploadPopulatorPVC(PVCPrimeName(pvc))
|
||||
|
||||
volumeUploadSourceCR := newUploadPopulatorCR("", false)
|
||||
scName := "test-sc"
|
||||
sc := cc.CreateStorageClassWithProvisioner(scName, map[string]string{cc.AnnDefaultStorageClass: "true"}, map[string]string{}, "csi-plugin")
|
||||
r := createUploadPopulatorReconciler(pvc, volumeUploadSourceCR, sc, pvcPrime)
|
||||
|
||||
pvcPrime = &corev1.PersistentVolumeClaim{}
|
||||
pvcPrimeKey := types.NamespacedName{Namespace: pvc.Namespace, Name: PVCPrimeName(pvc)}
|
||||
err := r.client.Get(context.TODO(), pvcPrimeKey, pvcPrime)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
||||
_, err = r.Reconcile(context.TODO(), reconcile.Request{NamespacedName: types.NamespacedName{Name: "test-pvc", Namespace: metav1.NamespaceDefault}})
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
pvcPrime = &corev1.PersistentVolumeClaim{}
|
||||
pvcPrimeKey = types.NamespacedName{Namespace: pvc.Namespace, Name: PVCPrimeName(pvc)}
|
||||
err = r.client.Get(context.TODO(), pvcPrimeKey, pvcPrime)
|
||||
Expect(err).To(HaveOccurred())
|
||||
Expect(errors.IsNotFound(err)).To(BeTrue())
|
||||
})
|
||||
|
||||
It("should wait for selected node annotation in case of wffc", func() {
|
||||
pvc := newUploadPopulatorPVC("test-pvc")
|
||||
volumeUploadSourceCR := newUploadPopulatorCR("", false)
|
||||
scName := "test-sc"
|
||||
pvc.Spec.StorageClassName = &scName
|
||||
sc := cc.CreateStorageClassWithProvisioner(scName, map[string]string{cc.AnnDefaultStorageClass: "true"}, map[string]string{}, "csi-plugin")
|
||||
bindingMode := storagev1.VolumeBindingWaitForFirstConsumer
|
||||
sc.VolumeBindingMode = &bindingMode
|
||||
|
||||
r := createUploadPopulatorReconciler(pvc, volumeUploadSourceCR, sc)
|
||||
|
||||
_, err := r.Reconcile(context.TODO(), reconcile.Request{NamespacedName: types.NamespacedName{Name: "test-pvc", Namespace: metav1.NamespaceDefault}})
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
// until added selected node annotation upload
|
||||
// process shouldn't start
|
||||
pvcPrime := &corev1.PersistentVolumeClaim{}
|
||||
pvcPrimeKey := types.NamespacedName{Namespace: pvc.Namespace, Name: PVCPrimeName(pvc)}
|
||||
err = r.client.Get(context.TODO(), pvcPrimeKey, pvcPrime)
|
||||
Expect(err).To(HaveOccurred())
|
||||
Expect(errors.IsNotFound(err)).To(BeTrue())
|
||||
|
||||
pvc.Annotations = make(map[string]string)
|
||||
pvc.Annotations[cc.AnnSelectedNode] = "node01"
|
||||
err = r.client.Update(context.TODO(), pvc)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
||||
_, err = r.Reconcile(context.TODO(), reconcile.Request{NamespacedName: types.NamespacedName{Name: "test-pvc", Namespace: metav1.NamespaceDefault}})
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
||||
expectEvent(r, createdPVCPrimeSuccessfully)
|
||||
|
||||
pvcPrime, err = r.getPVCPrime(pvc)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(pvcPrime).ToNot(BeNil())
|
||||
Expect(pvcPrime.Annotations[cc.AnnSelectedNode]).To(Equal("node01"))
|
||||
})
|
||||
})
|
||||
|
||||
func newUploadPopulatorPVC(name string) *corev1.PersistentVolumeClaim {
|
||||
apiGroup := cc.AnnAPIGroup
|
||||
return &corev1.PersistentVolumeClaim{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: name,
|
||||
Namespace: metav1.NamespaceDefault,
|
||||
},
|
||||
Spec: corev1.PersistentVolumeClaimSpec{
|
||||
AccessModes: []corev1.PersistentVolumeAccessMode{corev1.ReadWriteOnce},
|
||||
Resources: corev1.ResourceRequirements{
|
||||
Requests: corev1.ResourceList{
|
||||
corev1.ResourceName(corev1.ResourceStorage): resource.MustParse("1Gi"),
|
||||
},
|
||||
},
|
||||
DataSourceRef: &corev1.TypedObjectReference{
|
||||
APIGroup: &apiGroup,
|
||||
Kind: cdiv1.VolumeUploadSourceRef,
|
||||
Name: testPopulatorName,
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func newUploadPopulatorCR(contentType string, preallocation bool) *cdiv1.VolumeUploadSource {
|
||||
return &cdiv1.VolumeUploadSource{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: testPopulatorName,
|
||||
Namespace: metav1.NamespaceDefault,
|
||||
},
|
||||
Spec: cdiv1.VolumeUploadSourceSpec{
|
||||
ContentType: cdiv1.DataVolumeContentType(contentType),
|
||||
Preallocation: &preallocation,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func uploadPV(pvc *corev1.PersistentVolumeClaim) *corev1.PersistentVolume {
|
||||
return &corev1.PersistentVolume{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: "test-pv",
|
||||
},
|
||||
Spec: corev1.PersistentVolumeSpec{
|
||||
ClaimRef: &corev1.ObjectReference{
|
||||
Namespace: metav1.NamespaceDefault,
|
||||
Name: PVCPrimeName(pvc),
|
||||
UID: pvcPrimeUID,
|
||||
},
|
||||
PersistentVolumeReclaimPolicy: corev1.PersistentVolumeReclaimDelete,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func expectEvent(r *UploadPopulatorReconciler, expectedEvent string) {
|
||||
close(r.recorder.(*record.FakeRecorder).Events)
|
||||
found := false
|
||||
for event := range r.recorder.(*record.FakeRecorder).Events {
|
||||
By(event)
|
||||
if strings.Contains(event, expectedEvent) {
|
||||
found = true
|
||||
}
|
||||
}
|
||||
Expect(found).To(BeTrue())
|
||||
}
|
||||
|
||||
func createUploadPopulatorReconciler(objects ...runtime.Object) *UploadPopulatorReconciler {
|
||||
cdiConfig := cc.MakeEmptyCDIConfigSpec(common.ConfigName)
|
||||
cdiConfig.Status = cdiv1.CDIConfigStatus{
|
||||
ScratchSpaceStorageClass: testStorageClass,
|
||||
}
|
||||
cdiConfig.Spec.FeatureGates = []string{featuregates.HonorWaitForFirstConsumer}
|
||||
|
||||
objs := []runtime.Object{}
|
||||
objs = append(objs, objects...)
|
||||
objs = append(objs, cdiConfig)
|
||||
|
||||
// Register operator types with the runtime scheme.
|
||||
s := scheme.Scheme
|
||||
_ = cdiv1.AddToScheme(s)
|
||||
_ = snapshotv1.AddToScheme(s)
|
||||
_ = extv1.AddToScheme(s)
|
||||
|
||||
objs = append(objs, cc.MakeEmptyCDICR())
|
||||
|
||||
builder := fake.NewClientBuilder().
|
||||
WithScheme(s).
|
||||
WithRuntimeObjects(objs...)
|
||||
|
||||
for _, ia := range getIndexArgs() {
|
||||
builder = builder.WithIndex(ia.obj, ia.field, ia.extractValue)
|
||||
}
|
||||
|
||||
cl := builder.Build()
|
||||
|
||||
rec := record.NewFakeRecorder(10)
|
||||
|
||||
// Create a ReconcileMemcached object with the scheme and fake client.
|
||||
r := &UploadPopulatorReconciler{
|
||||
ReconcilerBase: ReconcilerBase{
|
||||
client: cl,
|
||||
scheme: s,
|
||||
log: uploadPopLog,
|
||||
recorder: rec,
|
||||
featureGates: featuregates.NewFeatureGates(cl),
|
||||
installerLabels: map[string]string{
|
||||
common.AppKubernetesPartOfLabel: "testing",
|
||||
common.AppKubernetesVersionLabel: "v0.0.0-tests",
|
||||
},
|
||||
sourceKind: cdiv1.VolumeUploadSourceRef,
|
||||
},
|
||||
}
|
||||
return r
|
||||
}
|
@ -38,6 +38,10 @@ const (
|
||||
// messageCreatedPVCPrimeSuccessfully provides a const to indicate we created PVC prime for population (message)
|
||||
messageCreatedPVCPrimeSuccessfully = "PVC Prime created successfully"
|
||||
|
||||
// AnnPVCPrimeName annotation is the name of the PVC' that is added to the target PVC
|
||||
// used by the upload-proxy in order to get the service name
|
||||
AnnPVCPrimeName = cc.AnnAPIGroup + "/storage.populator.pvcPrime"
|
||||
|
||||
// annMigratedTo annotation is added to a PVC and PV that is supposed to be
|
||||
// dynamically provisioned/deleted by by its corresponding CSI driver
|
||||
// through the CSIMigration feature flags. When this annotation is set the
|
||||
|
@ -889,6 +889,7 @@ func (r *UploadReconciler) makeUploadPodSpec(args UploadPodArgs, resourceRequire
|
||||
})
|
||||
}
|
||||
setPodPvcAnnotations(pod, args.PVC)
|
||||
cc.SetNodeNameIfPopulator(args.PVC, &pod.Spec)
|
||||
cc.SetRestrictedSecurityContext(&pod.Spec)
|
||||
return pod
|
||||
}
|
||||
|
@ -1760,6 +1760,7 @@ func createNotReadyEventValidationMap() map[string]bool {
|
||||
match[normalCreateSuccess+" *v1.CustomResourceDefinition dataimportcrons.cdi.kubevirt.io"] = false
|
||||
match[normalCreateSuccess+" *v1.CustomResourceDefinition objecttransfers.cdi.kubevirt.io"] = false
|
||||
match[normalCreateSuccess+" *v1.CustomResourceDefinition volumeimportsources.cdi.kubevirt.io"] = false
|
||||
match[normalCreateSuccess+" *v1.CustomResourceDefinition volumeuploadsources.cdi.kubevirt.io"] = false
|
||||
match[normalCreateSuccess+" *v1.ClusterRole cdi-uploadproxy"] = false
|
||||
match[normalCreateSuccess+" *v1.ClusterRoleBinding cdi-uploadproxy"] = false
|
||||
match[normalCreateSuccess+" *v1.ClusterRole cdi-cronjob"] = false
|
||||
|
@ -60,6 +60,7 @@ func createCRDResources(args *FactoryArgs) []client.Object {
|
||||
createDataImportCronCRD(),
|
||||
createObjectTransferCRD(),
|
||||
createVolumeImportSourceCRD(),
|
||||
createVolumeUploadSourceCRD(),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -35,3 +35,15 @@ func createVolumeImportSourceCRD() *extv1.CustomResourceDefinition {
|
||||
_ = k8syaml.NewYAMLToJSONDecoder(strings.NewReader(resources.CDICRDs["volumeimportsource"])).Decode(&crd)
|
||||
return &crd
|
||||
}
|
||||
|
||||
// NewVolumeUploadSourceCrd - provides VolumeUploadSource CRD
|
||||
func NewVolumeUploadSourceCrd() *extv1.CustomResourceDefinition {
|
||||
return createVolumeUploadSourceCRD()
|
||||
}
|
||||
|
||||
// createVolumeUploadSourceCRD creates the VolumeUploadSource schema
|
||||
func createVolumeUploadSourceCRD() *extv1.CustomResourceDefinition {
|
||||
crd := extv1.CustomResourceDefinition{}
|
||||
_ = k8syaml.NewYAMLToJSONDecoder(strings.NewReader(resources.CDICRDs["volumeuploadsource"])).Decode(&crd)
|
||||
return &crd
|
||||
}
|
||||
|
@ -7138,5 +7138,67 @@ status:
|
||||
plural: ""
|
||||
conditions: null
|
||||
storedVersions: null
|
||||
`,
|
||||
"volumeuploadsource": `apiVersion: apiextensions.k8s.io/v1
|
||||
kind: CustomResourceDefinition
|
||||
metadata:
|
||||
annotations:
|
||||
controller-gen.kubebuilder.io/version: v0.11.3
|
||||
creationTimestamp: null
|
||||
name: volumeuploadsources.cdi.kubevirt.io
|
||||
spec:
|
||||
group: cdi.kubevirt.io
|
||||
names:
|
||||
kind: VolumeUploadSource
|
||||
listKind: VolumeUploadSourceList
|
||||
plural: volumeuploadsources
|
||||
singular: volumeuploadsource
|
||||
scope: Namespaced
|
||||
versions:
|
||||
- name: v1beta1
|
||||
schema:
|
||||
openAPIV3Schema:
|
||||
description: VolumeUploadSource is a specification to populate PersistentVolumeClaims
|
||||
with upload data
|
||||
properties:
|
||||
apiVersion:
|
||||
description: 'APIVersion defines the versioned schema of this representation
|
||||
of an object. Servers should convert recognized schemas to the latest
|
||||
internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources'
|
||||
type: string
|
||||
kind:
|
||||
description: 'Kind is a string value representing the REST resource this
|
||||
object represents. Servers may infer this from the endpoint the client
|
||||
submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds'
|
||||
type: string
|
||||
metadata:
|
||||
type: object
|
||||
spec:
|
||||
description: VolumeUploadSourceSpec defines specification for VolumeUploadSource
|
||||
properties:
|
||||
contentType:
|
||||
description: ContentType represents the type of the upload data (Kubevirt
|
||||
or archive)
|
||||
type: string
|
||||
preallocation:
|
||||
description: Preallocation controls whether storage for the target
|
||||
PVC should be allocated in advance.
|
||||
type: boolean
|
||||
type: object
|
||||
status:
|
||||
description: VolumeUploadSourceStatus provides the most recently observed
|
||||
status of the VolumeUploadSource
|
||||
type: object
|
||||
required:
|
||||
- spec
|
||||
type: object
|
||||
served: true
|
||||
storage: true
|
||||
status:
|
||||
acceptedNames:
|
||||
kind: ""
|
||||
plural: ""
|
||||
conditions: null
|
||||
storedVersions: null
|
||||
`,
|
||||
}
|
||||
|
@ -9,6 +9,7 @@ go_library(
|
||||
"//pkg/common:go_default_library",
|
||||
"//pkg/controller:go_default_library",
|
||||
"//pkg/controller/common:go_default_library",
|
||||
"//pkg/controller/populators:go_default_library",
|
||||
"//pkg/token:go_default_library",
|
||||
"//pkg/util/cert/fetcher:go_default_library",
|
||||
"//pkg/util/tls-crypto-watch:go_default_library",
|
||||
|
@ -27,6 +27,7 @@ import (
|
||||
"kubevirt.io/containerized-data-importer/pkg/common"
|
||||
"kubevirt.io/containerized-data-importer/pkg/controller"
|
||||
cc "kubevirt.io/containerized-data-importer/pkg/controller/common"
|
||||
"kubevirt.io/containerized-data-importer/pkg/controller/populators"
|
||||
"kubevirt.io/containerized-data-importer/pkg/token"
|
||||
"kubevirt.io/containerized-data-importer/pkg/util/cert/fetcher"
|
||||
cryptowatch "kubevirt.io/containerized-data-importer/pkg/util/tls-crypto-watch"
|
||||
@ -206,7 +207,7 @@ func (app *uploadProxyApp) handleUploadRequest(w http.ResponseWriter, r *http.Re
|
||||
|
||||
klog.V(1).Infof("Received valid token: pvc: %s, namespace: %s", tokenData.Name, tokenData.Namespace)
|
||||
|
||||
err = app.uploadReady(tokenData.Name, tokenData.Namespace)
|
||||
pvc, err := app.uploadReady(tokenData.Name, tokenData.Namespace)
|
||||
if err != nil {
|
||||
klog.Error(err)
|
||||
w.WriteHeader(http.StatusServiceUnavailable)
|
||||
@ -218,7 +219,7 @@ func (app *uploadProxyApp) handleUploadRequest(w http.ResponseWriter, r *http.Re
|
||||
return
|
||||
}
|
||||
|
||||
uploadPath, err := app.resolveUploadPath(tokenData.Name, tokenData.Namespace, r.URL.Path)
|
||||
uploadPath, err := app.resolveUploadPath(pvc, tokenData.Name, r.URL.Path)
|
||||
if err != nil {
|
||||
klog.Error(err)
|
||||
w.WriteHeader(http.StatusServiceUnavailable)
|
||||
@ -230,40 +231,33 @@ func (app *uploadProxyApp) handleUploadRequest(w http.ResponseWriter, r *http.Re
|
||||
return
|
||||
}
|
||||
|
||||
app.proxyUploadRequest(tokenData.Namespace, tokenData.Name, uploadPath, w, r)
|
||||
app.proxyUploadRequest(uploadPath, w, r)
|
||||
}
|
||||
|
||||
func (app *uploadProxyApp) resolveUploadPath(pvcName, pvcNamespace, defaultPath string) (string, error) {
|
||||
pvc, err := app.client.CoreV1().PersistentVolumeClaims(pvcNamespace).Get(context.TODO(), pvcName, metav1.GetOptions{})
|
||||
if err != nil {
|
||||
if k8serrors.IsNotFound(err) {
|
||||
return "", fmt.Errorf("rejecting Upload Request for PVC %s that doesn't exist", pvcName)
|
||||
}
|
||||
|
||||
return "", err
|
||||
}
|
||||
|
||||
contentType, found := pvc.Annotations[cc.AnnContentType]
|
||||
if !found {
|
||||
return defaultPath, nil
|
||||
}
|
||||
|
||||
func (app *uploadProxyApp) resolveUploadPath(pvc *v1.PersistentVolumeClaim, pvcName, defaultPath string) (string, error) {
|
||||
var path string
|
||||
contentType := pvc.Annotations[cc.AnnContentType]
|
||||
switch contentType {
|
||||
case string(cdiv1.DataVolumeKubeVirt), "":
|
||||
return defaultPath, nil
|
||||
path = defaultPath
|
||||
case string(cdiv1.DataVolumeArchive):
|
||||
if strings.Contains(defaultPath, "alpha") {
|
||||
return common.UploadArchiveAlphaPath, nil
|
||||
path = common.UploadArchiveAlphaPath
|
||||
} else {
|
||||
path = common.UploadArchivePath
|
||||
}
|
||||
return common.UploadArchivePath, nil
|
||||
default:
|
||||
return "", fmt.Errorf("rejecting upload request for PVC %s - upload content-type %s is invalid", pvcName, contentType)
|
||||
}
|
||||
|
||||
return app.urlResolver(pvc.Namespace, pvc.Name, path), nil
|
||||
}
|
||||
|
||||
func (app *uploadProxyApp) uploadReady(pvcName, pvcNamespace string) error {
|
||||
return wait.PollImmediate(waitReadyImterval, waitReadyTime, func() (bool, error) {
|
||||
pvc, err := app.client.CoreV1().PersistentVolumeClaims(pvcNamespace).Get(context.TODO(), pvcName, metav1.GetOptions{})
|
||||
func (app *uploadProxyApp) uploadReady(pvcName, pvcNamespace string) (*v1.PersistentVolumeClaim, error) {
|
||||
var pvc *v1.PersistentVolumeClaim
|
||||
err := wait.PollImmediate(waitReadyImterval, waitReadyTime, func() (bool, error) {
|
||||
var err error
|
||||
pvc, err = app.client.CoreV1().PersistentVolumeClaims(pvcNamespace).Get(context.TODO(), pvcName, metav1.GetOptions{})
|
||||
if err != nil {
|
||||
if k8serrors.IsNotFound(err) {
|
||||
return false, fmt.Errorf("rejecting Upload Request for PVC %s that doesn't exist", pvcName)
|
||||
@ -271,6 +265,13 @@ func (app *uploadProxyApp) uploadReady(pvcName, pvcNamespace string) error {
|
||||
|
||||
return false, err
|
||||
}
|
||||
// If using upload populator then need to check upload possibility to the PVC'
|
||||
if populators.IsPVCDataSourceRefKind(pvc, cdiv1.VolumeUploadSourceRef) {
|
||||
pvc, err = app.getPopulationPVC(pvc, pvcNamespace)
|
||||
if pvc == nil || err != nil {
|
||||
return false, err
|
||||
}
|
||||
}
|
||||
|
||||
err = app.uploadPossible(pvc)
|
||||
if err != nil {
|
||||
@ -284,9 +285,11 @@ func (app *uploadProxyApp) uploadReady(pvcName, pvcNamespace string) error {
|
||||
ready, _ := strconv.ParseBool(pvc.Annotations[cc.AnnPodReady])
|
||||
return ready, nil
|
||||
})
|
||||
|
||||
return pvc, err
|
||||
}
|
||||
|
||||
func (app *uploadProxyApp) proxyUploadRequest(namespace, pvcName, uploadPath string, w http.ResponseWriter, r *http.Request) {
|
||||
func (app *uploadProxyApp) proxyUploadRequest(uploadPath string, w http.ResponseWriter, r *http.Request) {
|
||||
client, err := app.clientCreator.CreateClient()
|
||||
if err != nil {
|
||||
klog.Error("Error creating http client")
|
||||
@ -296,7 +299,7 @@ func (app *uploadProxyApp) proxyUploadRequest(namespace, pvcName, uploadPath str
|
||||
|
||||
p := &httputil.ReverseProxy{
|
||||
Director: func(req *http.Request) {
|
||||
req.URL, _ = url.Parse(app.urlResolver(namespace, pvcName, uploadPath))
|
||||
req.URL, _ = url.Parse(uploadPath)
|
||||
if _, ok := req.Header["User-Agent"]; !ok {
|
||||
// explicitly disable User-Agent so it's not set to default value
|
||||
req.Header.Set("User-Agent", "")
|
||||
@ -370,3 +373,21 @@ func (app *uploadProxyApp) startTLS() error {
|
||||
// wait for server to exit
|
||||
return <-errChan
|
||||
}
|
||||
|
||||
func (app *uploadProxyApp) getPopulationPVC(pvc *v1.PersistentVolumeClaim, pvcNamespace string) (*v1.PersistentVolumeClaim, error) {
|
||||
pvcPrimeName, ok := pvc.Annotations[populators.AnnPVCPrimeName]
|
||||
if !ok {
|
||||
// wait for pvcPrimeName annotation on the pvc
|
||||
return nil, nil
|
||||
}
|
||||
pvcPrime, err := app.client.CoreV1().PersistentVolumeClaims(pvcNamespace).Get(context.TODO(), pvcPrimeName, metav1.GetOptions{})
|
||||
if err != nil {
|
||||
if k8serrors.IsNotFound(err) {
|
||||
return nil, fmt.Errorf("rejecting Upload Request for PVC %s, PVC' wasn't created yet", pvc.Name)
|
||||
}
|
||||
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return pvcPrime, nil
|
||||
}
|
||||
|
@ -50,6 +50,8 @@ func addKnownTypes(scheme *runtime.Scheme) error {
|
||||
&ObjectTransferList{},
|
||||
&VolumeImportSource{},
|
||||
&VolumeImportSourceList{},
|
||||
&VolumeUploadSource{},
|
||||
&VolumeUploadSourceList{},
|
||||
)
|
||||
metav1.AddToGroupVersion(scheme, SchemeGroupVersion)
|
||||
return nil
|
||||
|
@ -668,9 +668,47 @@ type VolumeImportSourceList struct {
|
||||
Items []VolumeImportSource `json:"items"`
|
||||
}
|
||||
|
||||
// VolumeUploadSource is a specification to populate PersistentVolumeClaims with upload data
|
||||
// +genclient
|
||||
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
|
||||
// +kubebuilder:object:root=true
|
||||
// +kubebuilder:storageversion
|
||||
type VolumeUploadSource struct {
|
||||
metav1.TypeMeta `json:",inline"`
|
||||
metav1.ObjectMeta `json:"metadata,omitempty"`
|
||||
|
||||
Spec VolumeUploadSourceSpec `json:"spec"`
|
||||
// +optional
|
||||
Status VolumeUploadSourceStatus `json:"status,omitempty"`
|
||||
}
|
||||
|
||||
// VolumeUploadSourceSpec defines specification for VolumeUploadSource
|
||||
type VolumeUploadSourceSpec struct {
|
||||
// ContentType represents the type of the upload data (Kubevirt or archive)
|
||||
ContentType DataVolumeContentType `json:"contentType,omitempty"`
|
||||
// Preallocation controls whether storage for the target PVC should be allocated in advance.
|
||||
Preallocation *bool `json:"preallocation,omitempty"`
|
||||
}
|
||||
|
||||
// VolumeUploadSourceStatus provides the most recently observed status of the VolumeUploadSource
|
||||
type VolumeUploadSourceStatus struct {
|
||||
}
|
||||
|
||||
// VolumeUploadSourceList provides the needed parameters to do request a list of Upload Sources from the system
|
||||
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
|
||||
type VolumeUploadSourceList struct {
|
||||
metav1.TypeMeta `json:",inline"`
|
||||
metav1.ListMeta `json:"metadata"`
|
||||
|
||||
// Items provides a list of DataSources
|
||||
Items []VolumeImportSource `json:"items"`
|
||||
}
|
||||
|
||||
const (
|
||||
// VolumeImportSourceRef is import source for DataSourceRef for PVC
|
||||
VolumeImportSourceRef = "VolumeImportSource"
|
||||
// VolumeUploadSourceRef is upload source for DataSourceRef for PVC
|
||||
VolumeUploadSourceRef = "VolumeUploadSource"
|
||||
)
|
||||
|
||||
// this has to be here otherwise informer-gen doesn't recognize it
|
||||
|
@ -342,6 +342,34 @@ func (VolumeImportSourceList) SwaggerDoc() map[string]string {
|
||||
}
|
||||
}
|
||||
|
||||
func (VolumeUploadSource) SwaggerDoc() map[string]string {
|
||||
return map[string]string{
|
||||
"": "VolumeUploadSource is a specification to populate PersistentVolumeClaims with upload data\n+genclient\n+k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object\n+kubebuilder:object:root=true\n+kubebuilder:storageversion",
|
||||
"status": "+optional",
|
||||
}
|
||||
}
|
||||
|
||||
func (VolumeUploadSourceSpec) SwaggerDoc() map[string]string {
|
||||
return map[string]string{
|
||||
"": "VolumeUploadSourceSpec defines specification for VolumeUploadSource",
|
||||
"contentType": "ContentType represents the type of the upload data (Kubevirt or archive)",
|
||||
"preallocation": "Preallocation controls whether storage for the target PVC should be allocated in advance.",
|
||||
}
|
||||
}
|
||||
|
||||
func (VolumeUploadSourceStatus) SwaggerDoc() map[string]string {
|
||||
return map[string]string{
|
||||
"": "VolumeUploadSourceStatus provides the most recently observed status of the VolumeUploadSource",
|
||||
}
|
||||
}
|
||||
|
||||
func (VolumeUploadSourceList) SwaggerDoc() map[string]string {
|
||||
return map[string]string{
|
||||
"": "VolumeUploadSourceList provides the needed parameters to do request a list of Upload Sources from the system\n+k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object",
|
||||
"items": "Items provides a list of DataSources",
|
||||
}
|
||||
}
|
||||
|
||||
func (CDI) SwaggerDoc() map[string]string {
|
||||
return map[string]string{
|
||||
"": "CDI is the CDI Operator CRD\n+genclient\n+k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object\n+kubebuilder:object:root=true\n+kubebuilder:storageversion\n+kubebuilder:resource:shortName=cdi;cdis,scope=Cluster\n+kubebuilder:printcolumn:name=\"Age\",type=\"date\",JSONPath=\".metadata.creationTimestamp\"\n+kubebuilder:printcolumn:name=\"Phase\",type=\"string\",JSONPath=\".status.phase\"",
|
||||
|
@ -1743,3 +1743,101 @@ func (in *VolumeImportSourceStatus) DeepCopy() *VolumeImportSourceStatus {
|
||||
in.DeepCopyInto(out)
|
||||
return out
|
||||
}
|
||||
|
||||
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
|
||||
func (in *VolumeUploadSource) DeepCopyInto(out *VolumeUploadSource) {
|
||||
*out = *in
|
||||
out.TypeMeta = in.TypeMeta
|
||||
in.ObjectMeta.DeepCopyInto(&out.ObjectMeta)
|
||||
in.Spec.DeepCopyInto(&out.Spec)
|
||||
out.Status = in.Status
|
||||
return
|
||||
}
|
||||
|
||||
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new VolumeUploadSource.
|
||||
func (in *VolumeUploadSource) DeepCopy() *VolumeUploadSource {
|
||||
if in == nil {
|
||||
return nil
|
||||
}
|
||||
out := new(VolumeUploadSource)
|
||||
in.DeepCopyInto(out)
|
||||
return out
|
||||
}
|
||||
|
||||
// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object.
|
||||
func (in *VolumeUploadSource) DeepCopyObject() runtime.Object {
|
||||
if c := in.DeepCopy(); c != nil {
|
||||
return c
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
|
||||
func (in *VolumeUploadSourceList) DeepCopyInto(out *VolumeUploadSourceList) {
|
||||
*out = *in
|
||||
out.TypeMeta = in.TypeMeta
|
||||
in.ListMeta.DeepCopyInto(&out.ListMeta)
|
||||
if in.Items != nil {
|
||||
in, out := &in.Items, &out.Items
|
||||
*out = make([]VolumeImportSource, len(*in))
|
||||
for i := range *in {
|
||||
(*in)[i].DeepCopyInto(&(*out)[i])
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new VolumeUploadSourceList.
|
||||
func (in *VolumeUploadSourceList) DeepCopy() *VolumeUploadSourceList {
|
||||
if in == nil {
|
||||
return nil
|
||||
}
|
||||
out := new(VolumeUploadSourceList)
|
||||
in.DeepCopyInto(out)
|
||||
return out
|
||||
}
|
||||
|
||||
// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object.
|
||||
func (in *VolumeUploadSourceList) DeepCopyObject() runtime.Object {
|
||||
if c := in.DeepCopy(); c != nil {
|
||||
return c
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
|
||||
func (in *VolumeUploadSourceSpec) DeepCopyInto(out *VolumeUploadSourceSpec) {
|
||||
*out = *in
|
||||
if in.Preallocation != nil {
|
||||
in, out := &in.Preallocation, &out.Preallocation
|
||||
*out = new(bool)
|
||||
**out = **in
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new VolumeUploadSourceSpec.
|
||||
func (in *VolumeUploadSourceSpec) DeepCopy() *VolumeUploadSourceSpec {
|
||||
if in == nil {
|
||||
return nil
|
||||
}
|
||||
out := new(VolumeUploadSourceSpec)
|
||||
in.DeepCopyInto(out)
|
||||
return out
|
||||
}
|
||||
|
||||
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
|
||||
func (in *VolumeUploadSourceStatus) DeepCopyInto(out *VolumeUploadSourceStatus) {
|
||||
*out = *in
|
||||
return
|
||||
}
|
||||
|
||||
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new VolumeUploadSourceStatus.
|
||||
func (in *VolumeUploadSourceStatus) DeepCopy() *VolumeUploadSourceStatus {
|
||||
if in == nil {
|
||||
return nil
|
||||
}
|
||||
out := new(VolumeUploadSourceStatus)
|
||||
in.DeepCopyInto(out)
|
||||
return out
|
||||
}
|
||||
|
@ -25,10 +25,12 @@ import (
|
||||
apiequality "k8s.io/apimachinery/pkg/api/equality"
|
||||
k8serrors "k8s.io/apimachinery/pkg/api/errors"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/runtime/schema"
|
||||
|
||||
cdiv1 "kubevirt.io/containerized-data-importer-api/pkg/apis/core/v1beta1"
|
||||
"kubevirt.io/containerized-data-importer/pkg/common"
|
||||
controller "kubevirt.io/containerized-data-importer/pkg/controller/common"
|
||||
"kubevirt.io/containerized-data-importer/pkg/controller/populators"
|
||||
"kubevirt.io/containerized-data-importer/pkg/image"
|
||||
"kubevirt.io/containerized-data-importer/pkg/util"
|
||||
"kubevirt.io/containerized-data-importer/tests"
|
||||
@ -55,9 +57,7 @@ type uploadFileNameRequestCreator func(string, string) (*http.Request, error)
|
||||
var _ = Describe("[rfe_id:138][crit:high][vendor:cnv-qe@redhat.com][level:component]Upload tests", func() {
|
||||
|
||||
var (
|
||||
pvc *v1.PersistentVolumeClaim
|
||||
archivePVC *v1.PersistentVolumeClaim
|
||||
err error
|
||||
err error
|
||||
|
||||
uploadProxyURL string
|
||||
portForwardCmd *exec.Cmd
|
||||
@ -65,7 +65,22 @@ var _ = Describe("[rfe_id:138][crit:high][vendor:cnv-qe@redhat.com][level:compon
|
||||
|
||||
f := framework.NewFramework("upload-func-test")
|
||||
|
||||
BeforeEach(func() {
|
||||
cleanup := func(pvc *v1.PersistentVolumeClaim) {
|
||||
By("Deleting verifier pod")
|
||||
err = utils.DeleteVerifierPod(f.K8sClient, f.Namespace.Name)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
||||
By("Delete upload PVC")
|
||||
err = f.DeletePVC(pvc)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
||||
By("Wait for upload pod to be deleted")
|
||||
deleted, err := utils.WaitPodDeleted(f.K8sClient, utils.UploadPodName(pvc), f.Namespace.Name, time.Second*20)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(deleted).To(BeTrue())
|
||||
}
|
||||
|
||||
verifyCleanup := func(pvc *v1.PersistentVolumeClaim) {
|
||||
if pvc != nil {
|
||||
Eventually(func() bool {
|
||||
// Make sure the pvc doesn't still exist. The after each should have called delete.
|
||||
@ -73,9 +88,9 @@ var _ = Describe("[rfe_id:138][crit:high][vendor:cnv-qe@redhat.com][level:compon
|
||||
return err != nil
|
||||
}, timeout, pollingInterval).Should(BeTrue())
|
||||
}
|
||||
By("Creating PVC with upload target annotation")
|
||||
pvc = f.CreateBoundPVCFromDefinition(utils.UploadPVCDefinition())
|
||||
}
|
||||
|
||||
BeforeEach(func() {
|
||||
uploadProxyURL = findProxyURLCdiConfig(f)
|
||||
if uploadProxyURL == "" {
|
||||
By("Set up port forwarding")
|
||||
@ -91,29 +106,9 @@ var _ = Describe("[rfe_id:138][crit:high][vendor:cnv-qe@redhat.com][level:compon
|
||||
Expect(portForwardCmd.Wait()).To(Succeed())
|
||||
portForwardCmd = nil
|
||||
}
|
||||
|
||||
By("Delete upload PVC")
|
||||
err = f.DeletePVC(pvc)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
||||
By("Wait for upload pod to be deleted")
|
||||
deleted, err := utils.WaitPodDeleted(f.K8sClient, utils.UploadPodName(pvc), f.Namespace.Name, time.Second*20)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(deleted).To(BeTrue())
|
||||
|
||||
if archivePVC != nil {
|
||||
By("Delete upload archive PVC")
|
||||
err = f.DeletePVC(pvc)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
||||
By("Wait for upload archive pod to be deleted")
|
||||
deleted, err := utils.WaitPodDeleted(f.K8sClient, utils.UploadPodName(pvc), f.Namespace.Name, time.Second*20)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(deleted).To(BeTrue())
|
||||
}
|
||||
})
|
||||
|
||||
checkFailureNoValidToken := func() {
|
||||
checkFailureNoValidToken := func(pvc *v1.PersistentVolumeClaim) {
|
||||
uploadPod, err := utils.FindPodByPrefix(f.K8sClient, f.Namespace.Name, utils.UploadPodName(pvc), common.CDILabelSelector)
|
||||
Expect(err).NotTo(HaveOccurred(), fmt.Sprintf("Unable to get uploader pod %q", f.Namespace.Name+"/"+utils.UploadPodName(pvc)))
|
||||
|
||||
@ -137,7 +132,7 @@ var _ = Describe("[rfe_id:138][crit:high][vendor:cnv-qe@redhat.com][level:compon
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
}
|
||||
|
||||
checkUploadCertSecrets := func() {
|
||||
checkUploadCertSecrets := func(pvc *v1.PersistentVolumeClaim) {
|
||||
pod, err := f.K8sClient.CoreV1().Pods(pvc.Namespace).Get(context.TODO(), utils.UploadPodName(pvc), metav1.GetOptions{})
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
||||
@ -148,228 +143,464 @@ var _ = Describe("[rfe_id:138][crit:high][vendor:cnv-qe@redhat.com][level:compon
|
||||
Expect(HasEnvironmentVariableFromSecret(pod, "TLS_CERT", secret)).To(BeTrue(), "Should have TLS_CERT")
|
||||
}
|
||||
|
||||
DescribeTable("should", func(uploader uploadFunc, validToken bool, expectedStatus int) {
|
||||
By("Verify PVC annotation says ready")
|
||||
found, err := utils.WaitPVCPodStatusReady(f.K8sClient, pvc)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(found).To(BeTrue())
|
||||
Context("Standard upload", func() {
|
||||
var (
|
||||
pvc *v1.PersistentVolumeClaim
|
||||
)
|
||||
|
||||
checkUploadCertSecrets()
|
||||
BeforeEach(func() {
|
||||
verifyCleanup(pvc)
|
||||
By("Creating PVC with upload target annotation")
|
||||
pvc = f.CreateBoundPVCFromDefinition(utils.UploadPVCDefinition())
|
||||
})
|
||||
|
||||
var token string
|
||||
if validToken {
|
||||
AfterEach(func() {
|
||||
cleanup(pvc)
|
||||
})
|
||||
|
||||
DescribeTable("should", func(uploader uploadFunc, validToken bool, expectedStatus int) {
|
||||
By("Verify PVC annotation says ready")
|
||||
found, err := utils.WaitPVCPodStatusReady(f.K8sClient, pvc)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(found).To(BeTrue())
|
||||
|
||||
checkUploadCertSecrets(pvc)
|
||||
|
||||
var token string
|
||||
if validToken {
|
||||
By("Get an upload token")
|
||||
token, err = utils.RequestUploadToken(f.CdiClient, pvc)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(token).ToNot(BeEmpty())
|
||||
} else {
|
||||
token = "abc"
|
||||
}
|
||||
|
||||
By("Do upload")
|
||||
Eventually(func() bool {
|
||||
err = uploader(uploadProxyURL, token, expectedStatus)
|
||||
if err != nil {
|
||||
fmt.Fprintf(GinkgoWriter, "ERROR: %s\n", err.Error())
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}, timeout, 5*time.Second).Should(BeTrue(), "Upload should eventually succeed, even if initially pod is not ready")
|
||||
|
||||
if validToken {
|
||||
By("Verify PVC status annotation says succeeded")
|
||||
found, err := utils.WaitPVCPodStatusSucceeded(f.K8sClient, pvc)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(found).To(BeTrue())
|
||||
|
||||
By("Verify content")
|
||||
same, err := f.VerifyTargetPVCContentMD5(f.Namespace, pvc, utils.DefaultImagePath, utils.UploadFileMD5100kbytes, 100000)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(same).To(BeTrue())
|
||||
By("Verifying the image is sparse")
|
||||
Expect(f.VerifySparse(f.Namespace, pvc, utils.DefaultImagePath)).To(BeTrue())
|
||||
if utils.DefaultStorageCSIRespectsFsGroup {
|
||||
// CSI storage class, it should respect fsGroup
|
||||
By("Checking that disk image group is qemu")
|
||||
Expect(f.GetDiskGroup(f.Namespace, pvc, false)).To(Equal("107"))
|
||||
}
|
||||
By("Verifying permissions are 660")
|
||||
Expect(f.VerifyPermissions(f.Namespace, pvc)).To(BeTrue(), "Permissions on disk image are not 660")
|
||||
} else {
|
||||
checkFailureNoValidToken(pvc)
|
||||
}
|
||||
},
|
||||
Entry("[test_id:1368]succeed given a valid token", uploadImage, true, http.StatusOK),
|
||||
Entry("[test_id:5078]succeed given a valid token (async)", uploadImageAsync, true, http.StatusOK),
|
||||
Entry("[test_id:5079]succeed given a valid token (alpha)", uploadImageAlpha, true, http.StatusOK),
|
||||
Entry("[test_id:5080]succeed given a valid token (async alpha)", uploadImageAsyncAlpha, true, http.StatusOK),
|
||||
Entry("[test_id:5081]succeed given a valid token (form)", uploadForm, true, http.StatusOK),
|
||||
Entry("[test_id:5082]succeed given a valid token (form async)", uploadFormAsync, true, http.StatusOK),
|
||||
Entry("[posneg:negative][test_id:1369]fail given an invalid token", uploadImage, false, http.StatusUnauthorized),
|
||||
)
|
||||
|
||||
It("[test_id:4988]Verify upload to the same pvc fails", func() {
|
||||
By("Verify PVC annotation says ready")
|
||||
found, err := utils.WaitPVCPodStatusReady(f.K8sClient, pvc)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(found).To(BeTrue())
|
||||
|
||||
var token string
|
||||
By("Get an upload token")
|
||||
token, err = utils.RequestUploadToken(f.CdiClient, pvc)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(token).ToNot(BeEmpty())
|
||||
} else {
|
||||
token = "abc"
|
||||
}
|
||||
|
||||
By("Do upload")
|
||||
Eventually(func() bool {
|
||||
err = uploader(uploadProxyURL, token, expectedStatus)
|
||||
if err != nil {
|
||||
fmt.Fprintf(GinkgoWriter, "ERROR: %s\n", err.Error())
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}, timeout, 5*time.Second).Should(BeTrue(), "Upload should eventually succeed, even if initially pod is not ready")
|
||||
By("Do upload")
|
||||
Eventually(func() error {
|
||||
return uploadImage(uploadProxyURL, token, http.StatusOK)
|
||||
}, timeout, pollingInterval).Should(BeNil(), "Upload should eventually succeed, even if initially pod is not ready")
|
||||
|
||||
if validToken {
|
||||
By("Verify PVC status annotation says succeeded")
|
||||
found, err := utils.WaitPVCPodStatusSucceeded(f.K8sClient, pvc)
|
||||
found, err = utils.WaitPVCPodStatusSucceeded(f.K8sClient, pvc)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(found).To(BeTrue())
|
||||
|
||||
By("Verify content")
|
||||
same, err := f.VerifyTargetPVCContentMD5(f.Namespace, pvc, utils.DefaultImagePath, utils.UploadFileMD5100kbytes, 100000)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(same).To(BeTrue())
|
||||
By("Verifying the image is sparse")
|
||||
Expect(f.VerifySparse(f.Namespace, pvc, utils.DefaultImagePath)).To(BeTrue())
|
||||
if utils.DefaultStorageCSIRespectsFsGroup {
|
||||
// CSI storage class, it should respect fsGroup
|
||||
By("Checking that disk image group is qemu")
|
||||
Expect(f.GetDiskGroup(f.Namespace, pvc, false)).To(Equal("107"))
|
||||
}
|
||||
By("Verifying permissions are 660")
|
||||
Expect(f.VerifyPermissions(f.Namespace, pvc)).To(BeTrue(), "Permissions on disk image are not 660")
|
||||
} else {
|
||||
checkFailureNoValidToken()
|
||||
}
|
||||
},
|
||||
Entry("[test_id:1368]succeed given a valid token", uploadImage, true, http.StatusOK),
|
||||
Entry("[test_id:5078]succeed given a valid token (async)", uploadImageAsync, true, http.StatusOK),
|
||||
Entry("[test_id:5079]succeed given a valid token (alpha)", uploadImageAlpha, true, http.StatusOK),
|
||||
Entry("[test_id:5080]succeed given a valid token (async alpha)", uploadImageAsyncAlpha, true, http.StatusOK),
|
||||
Entry("[test_id:5081]succeed given a valid token (form)", uploadForm, true, http.StatusOK),
|
||||
Entry("[test_id:5082]succeed given a valid token (form async)", uploadFormAsync, true, http.StatusOK),
|
||||
Entry("[posneg:negative][test_id:1369]fail given an invalid token", uploadImage, false, http.StatusUnauthorized),
|
||||
)
|
||||
|
||||
DescribeTable("Archive upload should", func(uploader uploadArchiveFunc, validToken bool, format string) {
|
||||
By("Create archive file to upload")
|
||||
cirrosFileMd5, err := util.Md5sum(utils.UploadCirrosFile)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
tinyCoreFileMd5, err := util.Md5sum(utils.UploadFile)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
filesToUpload := map[string]string{utils.TinyCoreFile: tinyCoreFileMd5, utils.CirrosQCow2File: cirrosFileMd5}
|
||||
archiveFilePath, err := utils.ArchiveFiles("archive", os.TempDir(), utils.UploadFile, utils.UploadCirrosFile)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
if format != "" {
|
||||
archiveFilePath, err = utils.FormatTestData(archiveFilePath, os.TempDir(), format)
|
||||
By("Try upload again")
|
||||
err = uploadImage(uploadProxyURL, token, http.StatusServiceUnavailable)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
}
|
||||
|
||||
By("Creating PVC with upload target annotation and archive content-type")
|
||||
archivePVC = f.CreateBoundPVCFromDefinition(utils.UploadArchivePVCDefinition())
|
||||
})
|
||||
|
||||
By("Verify PVC annotation says ready")
|
||||
found, err := utils.WaitPVCPodStatusReady(f.K8sClient, archivePVC)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(found).To(BeTrue())
|
||||
|
||||
var token string
|
||||
var expectedStatus = http.StatusOK
|
||||
if validToken {
|
||||
By("Get an upload token")
|
||||
token, err = utils.RequestUploadToken(f.CdiClient, archivePVC)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(token).ToNot(BeEmpty())
|
||||
} else {
|
||||
token = "abc"
|
||||
expectedStatus = http.StatusUnauthorized
|
||||
}
|
||||
|
||||
By("Do upload")
|
||||
Eventually(func() error {
|
||||
return uploader(archiveFilePath, uploadProxyURL, token, expectedStatus)
|
||||
}, timeout, pollingInterval).Should(BeNil(), "Upload should eventually succeed, even if initially pod is not ready")
|
||||
|
||||
if validToken {
|
||||
By("Verify PVC status annotation says succeeded")
|
||||
found, err := utils.WaitPVCPodStatusSucceeded(f.K8sClient, archivePVC)
|
||||
DescribeTable("Verify validation error message on async upload if virtual size > pvc size", func(filename string) {
|
||||
By("Verify PVC annotation says ready")
|
||||
found, err := utils.WaitPVCPodStatusReady(f.K8sClient, pvc)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(found).To(BeTrue())
|
||||
|
||||
By("Verify content")
|
||||
for file, expectedMd5 := range filesToUpload {
|
||||
pathInPvc := filepath.Join(utils.DefaultPvcMountPath, file)
|
||||
same, err := f.VerifyTargetPVCContentMD5(f.Namespace, archivePVC, pathInPvc, expectedMd5)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(same).To(BeTrue())
|
||||
By("Verifying the image is sparse")
|
||||
Expect(f.VerifySparse(f.Namespace, archivePVC, pathInPvc)).To(BeTrue())
|
||||
}
|
||||
} else {
|
||||
checkFailureNoValidToken()
|
||||
}
|
||||
},
|
||||
Entry("succeed given a valid token", uploadArchive, true, ""),
|
||||
Entry("succeed given a valid token (alpha)", uploadArchiveAlpha, true, ""),
|
||||
Entry("fail given an invalid token", uploadArchive, false, ""),
|
||||
Entry("succeed upload of tar.gz", uploadArchive, true, image.ExtGz),
|
||||
Entry("succeed upload of tar.xz", uploadArchive, true, image.ExtXz),
|
||||
)
|
||||
var token string
|
||||
By("Get an upload token")
|
||||
token, err = utils.RequestUploadToken(f.CdiClient, pvc)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(token).ToNot(BeEmpty())
|
||||
|
||||
It("[test_id:4988]Verify upload to the same pvc fails", func() {
|
||||
By("Verify PVC annotation says ready")
|
||||
found, err := utils.WaitPVCPodStatusReady(f.K8sClient, pvc)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(found).To(BeTrue())
|
||||
By("Do upload")
|
||||
Eventually(func() error {
|
||||
return uploadFileNameToPath(binaryRequestFunc, filename, uploadProxyURL, asyncUploadPath, token, http.StatusBadRequest)
|
||||
}, timeout, pollingInterval).Should(BeNil(), "Upload should eventually succeed, even if initially pod is not ready")
|
||||
},
|
||||
Entry("[test_id:4989]fail given a large virtual size QCOW2 file", utils.UploadFileLargeVirtualDiskQcow),
|
||||
Entry("fail given a large physical size QCOW2 file", utils.UploadFileLargePhysicalDiskQcow),
|
||||
)
|
||||
|
||||
var token string
|
||||
By("Get an upload token")
|
||||
token, err = utils.RequestUploadToken(f.CdiClient, pvc)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(token).ToNot(BeEmpty())
|
||||
DescribeTable("[posneg:negative][test_id:2330]Verify failure on sync upload if virtual size > pvc size", func(filename string) {
|
||||
By("Verify PVC annotation says ready")
|
||||
found, err := utils.WaitPVCPodStatusReady(f.K8sClient, pvc)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(found).To(BeTrue())
|
||||
|
||||
By("Do upload")
|
||||
Eventually(func() error {
|
||||
return uploadImage(uploadProxyURL, token, http.StatusOK)
|
||||
}, timeout, pollingInterval).Should(BeNil(), "Upload should eventually succeed, even if initially pod is not ready")
|
||||
var token string
|
||||
By("Get an upload token")
|
||||
token, err = utils.RequestUploadToken(f.CdiClient, pvc)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(token).ToNot(BeEmpty())
|
||||
|
||||
By("Verify PVC status annotation says succeeded")
|
||||
found, err = utils.WaitPVCPodStatusSucceeded(f.K8sClient, pvc)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(found).To(BeTrue())
|
||||
By("Verifying permissions are 660")
|
||||
Expect(f.VerifyPermissions(f.Namespace, pvc)).To(BeTrue(), "Permissions on disk image are not 660")
|
||||
By("Do upload")
|
||||
Eventually(func() bool {
|
||||
err = uploadFileNameToPath(binaryRequestFunc, filename, uploadProxyURL, syncUploadPath, token, http.StatusOK)
|
||||
return err != nil && strings.Contains(err.Error(), "Unexpected return value 500")
|
||||
}, timeout, pollingInterval).Should(BeTrue())
|
||||
|
||||
By("Try upload again")
|
||||
err = uploadImage(uploadProxyURL, token, http.StatusServiceUnavailable)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
uploadPod, err := utils.FindPodByPrefix(f.K8sClient, f.Namespace.Name, utils.UploadPodName(pvc), common.CDILabelSelector)
|
||||
Expect(err).NotTo(HaveOccurred(), fmt.Sprintf("Unable to get uploader pod %q", f.Namespace.Name+"/"+utils.UploadPodName(pvc)))
|
||||
|
||||
By("Verify size error in logs")
|
||||
Eventually(func() bool {
|
||||
log, _ := f.RunKubectlCommand("logs", uploadPod.Name, "-n", uploadPod.Namespace)
|
||||
if strings.Contains(log, "is larger than the reported available") {
|
||||
return true
|
||||
}
|
||||
if strings.Contains(log, "no space left on device") {
|
||||
return true
|
||||
}
|
||||
if strings.Contains(log, "qemu-img execution failed") {
|
||||
return true
|
||||
}
|
||||
if strings.Contains(log, "calculated new size is < than current size, not resizing") {
|
||||
return true
|
||||
}
|
||||
By("Failed to find error messages about a too large image in log:")
|
||||
By(log)
|
||||
return false
|
||||
}, controllerSkipPVCCompleteTimeout, assertionPollInterval).Should(BeTrue())
|
||||
},
|
||||
Entry("fail given a large virtual size RAW XZ file", utils.UploadFileLargeVirtualDiskXz),
|
||||
Entry("fail given a large virtual size QCOW2 file", utils.UploadFileLargeVirtualDiskQcow),
|
||||
Entry("fail given a large physical size RAW XZ file", utils.UploadFileLargePhysicalDiskXz),
|
||||
Entry("fail given a large physical size QCOW2 file", utils.UploadFileLargePhysicalDiskQcow),
|
||||
)
|
||||
})
|
||||
|
||||
DescribeTable("Verify validation error message on async upload if virtual size > pvc size", func(filename string) {
|
||||
By("Verify PVC annotation says ready")
|
||||
found, err := utils.WaitPVCPodStatusReady(f.K8sClient, pvc)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(found).To(BeTrue())
|
||||
Context("Archive upload", func() {
|
||||
var (
|
||||
archivePVC *v1.PersistentVolumeClaim
|
||||
)
|
||||
|
||||
var token string
|
||||
By("Get an upload token")
|
||||
token, err = utils.RequestUploadToken(f.CdiClient, pvc)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(token).ToNot(BeEmpty())
|
||||
BeforeEach(func() {
|
||||
verifyCleanup(archivePVC)
|
||||
By("Creating PVC with upload target annotation and archive content-type")
|
||||
archivePVC = f.CreateBoundPVCFromDefinition(utils.UploadArchivePVCDefinition())
|
||||
})
|
||||
|
||||
By("Do upload")
|
||||
Eventually(func() error {
|
||||
return uploadFileNameToPath(binaryRequestFunc, filename, uploadProxyURL, asyncUploadPath, token, http.StatusBadRequest)
|
||||
}, timeout, pollingInterval).Should(BeNil(), "Upload should eventually succeed, even if initially pod is not ready")
|
||||
},
|
||||
Entry("[test_id:4989]fail given a large virtual size QCOW2 file", utils.UploadFileLargeVirtualDiskQcow),
|
||||
Entry("fail given a large physical size QCOW2 file", utils.UploadFileLargePhysicalDiskQcow),
|
||||
)
|
||||
AfterEach(func() {
|
||||
cleanup(archivePVC)
|
||||
})
|
||||
|
||||
DescribeTable("[posneg:negative][test_id:2330]Verify failure on sync upload if virtual size > pvc size", func(filename string) {
|
||||
By("Verify PVC annotation says ready")
|
||||
found, err := utils.WaitPVCPodStatusReady(f.K8sClient, pvc)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(found).To(BeTrue())
|
||||
|
||||
var token string
|
||||
By("Get an upload token")
|
||||
token, err = utils.RequestUploadToken(f.CdiClient, pvc)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(token).ToNot(BeEmpty())
|
||||
|
||||
By("Do upload")
|
||||
Eventually(func() bool {
|
||||
err = uploadFileNameToPath(binaryRequestFunc, filename, uploadProxyURL, syncUploadPath, token, http.StatusOK)
|
||||
return err != nil && strings.Contains(err.Error(), "Unexpected return value 500")
|
||||
}, timeout, pollingInterval).Should(BeTrue())
|
||||
|
||||
uploadPod, err := utils.FindPodByPrefix(f.K8sClient, f.Namespace.Name, utils.UploadPodName(pvc), common.CDILabelSelector)
|
||||
Expect(err).NotTo(HaveOccurred(), fmt.Sprintf("Unable to get uploader pod %q", f.Namespace.Name+"/"+utils.UploadPodName(pvc)))
|
||||
|
||||
By("Verify size error in logs")
|
||||
Eventually(func() bool {
|
||||
log, _ := f.RunKubectlCommand("logs", uploadPod.Name, "-n", uploadPod.Namespace)
|
||||
if strings.Contains(log, "is larger than the reported available") {
|
||||
return true
|
||||
DescribeTable("should", func(uploader uploadArchiveFunc, validToken bool, format string) {
|
||||
By("Create archive file to upload")
|
||||
cirrosFileMd5, err := util.Md5sum(utils.UploadCirrosFile)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
tinyCoreFileMd5, err := util.Md5sum(utils.UploadFile)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
filesToUpload := map[string]string{utils.TinyCoreFile: tinyCoreFileMd5, utils.CirrosQCow2File: cirrosFileMd5}
|
||||
archiveFilePath, err := utils.ArchiveFiles("archive", os.TempDir(), utils.UploadFile, utils.UploadCirrosFile)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
if format != "" {
|
||||
archiveFilePath, err = utils.FormatTestData(archiveFilePath, os.TempDir(), format)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
}
|
||||
if strings.Contains(log, "no space left on device") {
|
||||
return true
|
||||
|
||||
By("Verify PVC annotation says ready")
|
||||
found, err := utils.WaitPVCPodStatusReady(f.K8sClient, archivePVC)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(found).To(BeTrue())
|
||||
|
||||
var token string
|
||||
var expectedStatus = http.StatusOK
|
||||
if validToken {
|
||||
By("Get an upload token")
|
||||
token, err = utils.RequestUploadToken(f.CdiClient, archivePVC)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(token).ToNot(BeEmpty())
|
||||
} else {
|
||||
token = "abc"
|
||||
expectedStatus = http.StatusUnauthorized
|
||||
}
|
||||
if strings.Contains(log, "qemu-img execution failed") {
|
||||
return true
|
||||
|
||||
By("Do upload")
|
||||
Eventually(func() error {
|
||||
return uploader(archiveFilePath, uploadProxyURL, token, expectedStatus)
|
||||
}, timeout, pollingInterval).Should(BeNil(), "Upload should eventually succeed, even if initially pod is not ready")
|
||||
|
||||
if validToken {
|
||||
By("Verify PVC status annotation says succeeded")
|
||||
found, err := utils.WaitPVCPodStatusSucceeded(f.K8sClient, archivePVC)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(found).To(BeTrue())
|
||||
|
||||
By("Verify content")
|
||||
for file, expectedMd5 := range filesToUpload {
|
||||
pathInPvc := filepath.Join(utils.DefaultPvcMountPath, file)
|
||||
same, err := f.VerifyTargetPVCContentMD5(f.Namespace, archivePVC, pathInPvc, expectedMd5)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(same).To(BeTrue())
|
||||
By("Verifying the image is sparse")
|
||||
Expect(f.VerifySparse(f.Namespace, archivePVC, pathInPvc)).To(BeTrue())
|
||||
}
|
||||
} else {
|
||||
checkFailureNoValidToken(archivePVC)
|
||||
}
|
||||
if strings.Contains(log, "calculated new size is < than current size, not resizing") {
|
||||
return true
|
||||
},
|
||||
Entry("succeed given a valid token", uploadArchive, true, ""),
|
||||
Entry("succeed given a valid token (alpha)", uploadArchiveAlpha, true, ""),
|
||||
Entry("fail given an invalid token", uploadArchive, false, ""),
|
||||
Entry("succeed upload of tar.gz", uploadArchive, true, image.ExtGz),
|
||||
Entry("succeed upload of tar.xz", uploadArchive, true, image.ExtXz),
|
||||
)
|
||||
})
|
||||
|
||||
Context("Upload population", func() {
|
||||
var (
|
||||
pvc *v1.PersistentVolumeClaim
|
||||
pvcPrime *v1.PersistentVolumeClaim
|
||||
)
|
||||
|
||||
uploadSourceGVR := schema.GroupVersionResource{Group: "cdi.kubevirt.io", Version: "v1beta1", Resource: "volumeuploadsources"}
|
||||
|
||||
createUploadPopulatorCR := func(contentType cdiv1.DataVolumeContentType) error {
|
||||
By("Creating Upload Populator CR")
|
||||
uploadPopulatorCR := utils.UploadPopulatorCR(f.Namespace.Name, string(contentType))
|
||||
|
||||
_, err := f.DynamicClient.Resource(uploadSourceGVR).Namespace(f.Namespace.Name).Create(
|
||||
context.TODO(), uploadPopulatorCR, metav1.CreateOptions{})
|
||||
return err
|
||||
}
|
||||
|
||||
BeforeEach(func() {
|
||||
verifyCleanup(pvc)
|
||||
})
|
||||
|
||||
AfterEach(func() {
|
||||
By("Deleting verifier pod")
|
||||
err = utils.DeleteVerifierPod(f.K8sClient, f.Namespace.Name)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
||||
err := f.DynamicClient.Resource(uploadSourceGVR).Namespace(f.Namespace.Name).Delete(context.TODO(), "upload-populator-test", metav1.DeleteOptions{})
|
||||
if err != nil && !k8serrors.IsNotFound(err) {
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
}
|
||||
By("Failed to find error messages about a too large image in log:")
|
||||
By(log)
|
||||
return false
|
||||
}, controllerSkipPVCCompleteTimeout, assertionPollInterval).Should(BeTrue())
|
||||
},
|
||||
Entry("fail given a large virtual size RAW XZ file", utils.UploadFileLargeVirtualDiskXz),
|
||||
Entry("fail given a large virtual size QCOW2 file", utils.UploadFileLargeVirtualDiskQcow),
|
||||
Entry("fail given a large physical size RAW XZ file", utils.UploadFileLargePhysicalDiskXz),
|
||||
Entry("fail given a large physical size QCOW2 file", utils.UploadFileLargePhysicalDiskQcow),
|
||||
)
|
||||
|
||||
By("Delete upload population PVC")
|
||||
err = f.DeletePVC(pvc)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
||||
})
|
||||
Context("standard", func() {
|
||||
BeforeEach(func() {
|
||||
err := createUploadPopulatorCR(cdiv1.DataVolumeKubeVirt)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
})
|
||||
|
||||
DescribeTable("should", func(uploader uploadFunc, validToken, blockMode bool, expectedStatus int) {
|
||||
pvcDef := utils.UploadPopulationPVCDefinition()
|
||||
if blockMode {
|
||||
if !f.IsBlockVolumeStorageClassAvailable() {
|
||||
Skip("Storage Class for block volume is not available")
|
||||
}
|
||||
pvcDef = utils.UploadPopulationBlockPVCDefinition(f.BlockSCName)
|
||||
}
|
||||
pvc = f.CreateScheduledPVCFromDefinition(pvcDef)
|
||||
|
||||
By("Verify PVC prime was created")
|
||||
pvcPrime, err = utils.WaitForPVC(f.K8sClient, pvc.Namespace, populators.PVCPrimeName(pvc))
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
By("Verify PVC prime annotation says ready")
|
||||
found, err := utils.WaitPVCPodStatusReady(f.K8sClient, pvcPrime)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(found).To(BeTrue())
|
||||
|
||||
checkUploadCertSecrets(pvcPrime)
|
||||
|
||||
var token string
|
||||
if validToken {
|
||||
By("Get an upload token")
|
||||
token, err = utils.RequestUploadToken(f.CdiClient, pvc)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(token).ToNot(BeEmpty())
|
||||
} else {
|
||||
token = "abc"
|
||||
}
|
||||
|
||||
By("Do upload")
|
||||
Eventually(func() bool {
|
||||
err = uploader(uploadProxyURL, token, expectedStatus)
|
||||
if err != nil {
|
||||
fmt.Fprintf(GinkgoWriter, "ERROR: %s\n", err.Error())
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}, timeout, 5*time.Second).Should(BeTrue(), "Upload should eventually succeed, even if initially pod is not ready")
|
||||
|
||||
if validToken {
|
||||
By("Verify target PVC is bound")
|
||||
err = utils.WaitForPersistentVolumeClaimPhase(f.K8sClient, pvc.Namespace, v1.ClaimBound, pvc.Name)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
||||
By("Verify content")
|
||||
if blockMode {
|
||||
same, err := f.VerifyTargetPVCContentMD5(f.Namespace, pvc, utils.DefaultPvcMountPath, utils.UploadFileMD5, utils.UploadFileSize)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(same).To(BeTrue())
|
||||
} else {
|
||||
same, err := f.VerifyTargetPVCContentMD5(f.Namespace, pvc, utils.DefaultImagePath, utils.UploadFileMD5100kbytes, 100000)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(same).To(BeTrue())
|
||||
By("Verifying the image is sparse")
|
||||
Expect(f.VerifySparse(f.Namespace, pvc, utils.DefaultImagePath)).To(BeTrue())
|
||||
if utils.DefaultStorageCSIRespectsFsGroup {
|
||||
// CSI storage class, it should respect fsGroup
|
||||
By("Checking that disk image group is qemu")
|
||||
Expect(f.GetDiskGroup(f.Namespace, pvc, false)).To(Equal("107"))
|
||||
}
|
||||
By("Verifying permissions are 660")
|
||||
Expect(f.VerifyPermissions(f.Namespace, pvc)).To(BeTrue(), "Permissions on disk image are not 660")
|
||||
}
|
||||
By("Wait for PVC prime to be deleted")
|
||||
Eventually(func() bool {
|
||||
// Make sure pvcPrime was deleted after upload population
|
||||
_, err := f.FindPVC(pvcPrime.Name)
|
||||
return err != nil && k8serrors.IsNotFound(err)
|
||||
}, timeout, pollingInterval).Should(BeTrue())
|
||||
By("Wait for upload population pod to be deleted")
|
||||
deleted, err := utils.WaitPodDeleted(f.K8sClient, utils.UploadPodName(pvcPrime), f.Namespace.Name, time.Second*20)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(deleted).To(BeTrue())
|
||||
|
||||
} else {
|
||||
checkFailureNoValidToken(pvcPrime)
|
||||
}
|
||||
},
|
||||
Entry("succeed given a valid token", uploadImage, true, false, http.StatusOK),
|
||||
Entry("succeed given a valid token (async)", uploadImageAsync, true, false, http.StatusOK),
|
||||
Entry("succeed given a valid token (alpha)", uploadImageAlpha, true, false, http.StatusOK),
|
||||
Entry("succeed given a valid token (async alpha)", uploadImageAsyncAlpha, true, false, http.StatusOK),
|
||||
Entry("succeed given a valid token (form)", uploadForm, true, false, http.StatusOK),
|
||||
Entry("succeed given a valid token (form async)", uploadFormAsync, true, false, http.StatusOK),
|
||||
Entry("fail given an invalid token", uploadImage, false, false, http.StatusUnauthorized),
|
||||
Entry("succeed given a valid token and block mode", uploadImage, true, true, http.StatusOK),
|
||||
)
|
||||
})
|
||||
|
||||
Context("archive", func() {
|
||||
BeforeEach(func() {
|
||||
pvc = f.CreateScheduledPVCFromDefinition(utils.UploadPopulationPVCDefinition())
|
||||
err := createUploadPopulatorCR(cdiv1.DataVolumeArchive)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
})
|
||||
|
||||
DescribeTable("should", func(uploader uploadArchiveFunc, validToken bool, format string) {
|
||||
By("Create archive file to upload")
|
||||
cirrosFileMd5, err := util.Md5sum(utils.UploadCirrosFile)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
tinyCoreFileMd5, err := util.Md5sum(utils.UploadFile)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
filesToUpload := map[string]string{utils.TinyCoreFile: tinyCoreFileMd5, utils.CirrosQCow2File: cirrosFileMd5}
|
||||
archiveFilePath, err := utils.ArchiveFiles("archive", os.TempDir(), utils.UploadFile, utils.UploadCirrosFile)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
if format != "" {
|
||||
archiveFilePath, err = utils.FormatTestData(archiveFilePath, os.TempDir(), format)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
}
|
||||
|
||||
By("Verify PVC prime was created")
|
||||
pvcPrime, err = utils.WaitForPVC(f.K8sClient, pvc.Namespace, populators.PVCPrimeName(pvc))
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
By("Verify PVC prime annotation says ready")
|
||||
found, err := utils.WaitPVCPodStatusReady(f.K8sClient, pvcPrime)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(found).To(BeTrue())
|
||||
|
||||
checkUploadCertSecrets(pvcPrime)
|
||||
|
||||
var token string
|
||||
var expectedStatus = http.StatusOK
|
||||
if validToken {
|
||||
By("Get an upload token")
|
||||
token, err = utils.RequestUploadToken(f.CdiClient, pvc)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(token).ToNot(BeEmpty())
|
||||
} else {
|
||||
token = "abc"
|
||||
expectedStatus = http.StatusUnauthorized
|
||||
}
|
||||
|
||||
By("Do upload")
|
||||
Eventually(func() error {
|
||||
return uploader(archiveFilePath, uploadProxyURL, token, expectedStatus)
|
||||
}, timeout, pollingInterval).Should(BeNil(), "Upload should eventually succeed, even if initially pod is not ready")
|
||||
|
||||
if validToken {
|
||||
By("Verify target PVC is bound")
|
||||
err = utils.WaitForPersistentVolumeClaimPhase(f.K8sClient, pvc.Namespace, v1.ClaimBound, pvc.Name)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
||||
By("Verify content")
|
||||
for file, expectedMd5 := range filesToUpload {
|
||||
pathInPvc := filepath.Join(utils.DefaultPvcMountPath, file)
|
||||
same, err := f.VerifyTargetPVCContentMD5(f.Namespace, pvc, pathInPvc, expectedMd5)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(same).To(BeTrue())
|
||||
By("Verifying the image is sparse")
|
||||
Expect(f.VerifySparse(f.Namespace, pvc, pathInPvc)).To(BeTrue())
|
||||
}
|
||||
} else {
|
||||
checkFailureNoValidToken(pvcPrime)
|
||||
}
|
||||
},
|
||||
Entry("succeed given a valid token", uploadArchive, true, ""),
|
||||
Entry("succeed given a valid token (alpha)", uploadArchiveAlpha, true, ""),
|
||||
Entry("fail given an invalid token", uploadArchive, false, ""),
|
||||
Entry("succeed upload of tar.gz", uploadArchive, true, image.ExtGz),
|
||||
Entry("succeed upload of tar.xz", uploadArchive, true, image.ExtXz),
|
||||
)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
var ErrorTestFake = errors.New("TestFakeError")
|
||||
|
@ -41,6 +41,7 @@ go_library(
|
||||
"//vendor/k8s.io/apimachinery/pkg/api/errors:go_default_library",
|
||||
"//vendor/k8s.io/apimachinery/pkg/api/resource:go_default_library",
|
||||
"//vendor/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
|
||||
"//vendor/k8s.io/apimachinery/pkg/apis/meta/v1/unstructured:go_default_library",
|
||||
"//vendor/k8s.io/apimachinery/pkg/runtime/schema:go_default_library",
|
||||
"//vendor/k8s.io/apimachinery/pkg/types:go_default_library",
|
||||
"//vendor/k8s.io/apimachinery/pkg/util/wait:go_default_library",
|
||||
|
@ -3,14 +3,17 @@ package utils
|
||||
import (
|
||||
"context"
|
||||
|
||||
corev1 "k8s.io/api/core/v1"
|
||||
k8sv1 "k8s.io/api/core/v1"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
|
||||
"k8s.io/client-go/kubernetes"
|
||||
|
||||
cdiv1 "kubevirt.io/containerized-data-importer-api/pkg/apis/core/v1beta1"
|
||||
cdiuploadv1 "kubevirt.io/containerized-data-importer-api/pkg/apis/upload/v1beta1"
|
||||
cdiClientset "kubevirt.io/containerized-data-importer/pkg/client/clientset/versioned"
|
||||
"kubevirt.io/containerized-data-importer/pkg/common"
|
||||
cc "kubevirt.io/containerized-data-importer/pkg/controller/common"
|
||||
"kubevirt.io/containerized-data-importer/pkg/util/naming"
|
||||
)
|
||||
|
||||
@ -71,6 +74,45 @@ func UploadArchivePVCDefinition() *k8sv1.PersistentVolumeClaim {
|
||||
return pvc
|
||||
}
|
||||
|
||||
// UploadPopulationPVCDefinition creates a PVC with upload datasourceref
|
||||
func UploadPopulationPVCDefinition() *k8sv1.PersistentVolumeClaim {
|
||||
pvcDef := NewPVCDefinition("upload-populator-pvc-test", "1Gi", nil, nil)
|
||||
apiGroup := cc.AnnAPIGroup
|
||||
pvcDef.Spec.DataSourceRef = &k8sv1.TypedObjectReference{
|
||||
APIGroup: &apiGroup,
|
||||
Kind: cdiv1.VolumeUploadSourceRef,
|
||||
Name: "upload-populator-test",
|
||||
}
|
||||
return pvcDef
|
||||
}
|
||||
|
||||
// UploadPopulationBlockPVCDefinition creates a PVC with upload datasourceref
|
||||
// and volumeMode 'Block'
|
||||
func UploadPopulationBlockPVCDefinition(storageClassName string) *k8sv1.PersistentVolumeClaim {
|
||||
pvcDef := UploadPopulationPVCDefinition()
|
||||
pvcDef.Spec.StorageClassName = &storageClassName
|
||||
volumeMode := corev1.PersistentVolumeBlock
|
||||
pvcDef.Spec.VolumeMode = &volumeMode
|
||||
return pvcDef
|
||||
}
|
||||
|
||||
// UploadPopulatorCR creates an upload source CR
|
||||
func UploadPopulatorCR(namespace, contentType string) *unstructured.Unstructured {
|
||||
return &unstructured.Unstructured{
|
||||
Object: map[string]interface{}{
|
||||
"kind": cdiv1.VolumeUploadSourceRef,
|
||||
"apiVersion": "cdi.kubevirt.io/v1beta1",
|
||||
"metadata": map[string]interface{}{
|
||||
"name": "upload-populator-test",
|
||||
"namespace": namespace,
|
||||
},
|
||||
"spec": map[string]interface{}{
|
||||
"contentType": contentType,
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
// UploadBlockPVCDefinition creates a PVC with the upload target annotation for block PV
|
||||
func UploadBlockPVCDefinition(storageClass string) *k8sv1.PersistentVolumeClaim {
|
||||
annotations := map[string]string{uploadTargetAnnotation: ""}
|
||||
|
Loading…
Reference in New Issue
Block a user