-
Notifications
You must be signed in to change notification settings - Fork 34
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
test(CNV-43603): add disk-uploader functional tests #549
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,6 @@ | |
export DEV_MODE="${DEV_MODE:-false}" | ||
export STORAGE_CLASS="${STORAGE_CLASS:-}" | ||
export NUM_NODES=${NUM_NODES:-2} | ||
export REGISTRY_IMAGE_DESTINATION="quay.io/kubevirt/e2e-tests-example-vm" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there absolutely no way to use an ephemeral registry? Why do we have to store test artifacts on a live registry? (quay.io) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I replied here earlier. The issue is that there is no built-in registry in Kubernetes cluster (only on OpenShift). So we have 3 options: 1). Deploy a new pod that will use registry image to push there |
||
export REGISTRY_ACCESS_KEY_ID="" | ||
export REGISTRY_SECRET_KEY="" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
package test | ||
|
||
import ( | ||
"context" | ||
"os" | ||
|
||
. "github.com/onsi/ginkgo/v2" | ||
. "github.com/onsi/gomega" | ||
|
||
corev1 "k8s.io/api/core/v1" | ||
"k8s.io/apimachinery/pkg/api/resource" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
kubeclientcorev1 "k8s.io/client-go/kubernetes/typed/core/v1" | ||
|
||
v1 "kubevirt.io/api/core/v1" | ||
kubevirtcliv1 "kubevirt.io/client-go/kubecli" | ||
cdiv1beta1 "kubevirt.io/containerized-data-importer-api/pkg/apis/core/v1beta1" | ||
"kubevirt.io/kubevirt/pkg/libvmi" | ||
"kubevirt.io/kubevirt/tests/libdv" | ||
|
||
"github.com/kubevirt/kubevirt-tekton-tasks/test/constants" | ||
"github.com/kubevirt/kubevirt-tekton-tasks/test/framework" | ||
"github.com/kubevirt/kubevirt-tekton-tasks/test/runner" | ||
"github.com/kubevirt/kubevirt-tekton-tasks/test/testconfigs" | ||
"github.com/kubevirt/kubevirt-tekton-tasks/test/vm" | ||
) | ||
|
||
var _ = Describe("Run disk-uploader", func() { | ||
f := framework.NewFramework() | ||
|
||
BeforeEach(func() { | ||
if f.TestOptions.SkipDiskUploaderTests { | ||
Skip("skipDiskUploaderTests is set to true, skipping tests") | ||
} | ||
}) | ||
|
||
It("Extracts disk from VM and upload to container registry", func() { | ||
imageDestination := os.Getenv("REGISTRY_IMAGE_DESTINATION") | ||
Expect(imageDestination).ToNot(BeEmpty()) | ||
|
||
registryCredentials, err := createRegistryCredentials(f.CoreV1Client, f.DeployNamespace) | ||
Expect(err).ToNot(HaveOccurred()) | ||
|
||
cirrosVm, err := createCirrosVM(f.KubevirtClient, f.DeployNamespace) | ||
Expect(err).ToNot(HaveOccurred()) | ||
|
||
_, err = vm.WaitForVM(f.KubevirtClient, f.DeployNamespace, cirrosVm.Name, "", constants.Timeouts.WaitForVMStart.Duration, false) | ||
Expect(err).ToNot(HaveOccurred()) | ||
Comment on lines
+38
to
+48
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Move this to BeforeEach? |
||
|
||
config := &testconfigs.DiskUploaderTestConfig{ | ||
TaskRunTestConfig: testconfigs.TaskRunTestConfig{}, | ||
TaskData: testconfigs.DiskUploaderTaskData{ | ||
ExportSourceKind: "vm", | ||
ExportSourceName: cirrosVm.Name, | ||
VolumeName: cirrosVm.Spec.Template.Spec.Volumes[0].DataVolume.Name, | ||
ImageDestination: imageDestination, | ||
SecretName: registryCredentials.Name, | ||
}, | ||
} | ||
f.TestSetup(config) | ||
|
||
runner.NewTaskRunRunner(f, config.GetTaskRun()). | ||
CreateTaskRun(). | ||
ExpectSuccess(). | ||
ExpectLogs(config.GetAllExpectedLogs()...). | ||
ExpectResults(nil) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Query the repository after to verify disk was uploaded? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yep good idea, need to check it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are you going to add a check? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes. We may want to delete the repository after completing running the tests. If we won't delete it, and re-run the functional tests, it may be false check. |
||
}) | ||
}) | ||
|
||
func createRegistryCredentials(client kubeclientcorev1.CoreV1Interface, namespace string) (*corev1.Secret, error) { | ||
registryKeyId := os.Getenv("REGISTRY_ACCESS_KEY_ID") | ||
Expect(registryKeyId).ToNot(BeEmpty()) | ||
|
||
registryKey := os.Getenv("REGISTRY_SECRET_KEY") | ||
Expect(registryKey).ToNot(BeEmpty()) | ||
|
||
v1Secret := &corev1.Secret{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: constants.E2ETestsRandomName("disk-uploader-credentials"), | ||
}, | ||
Type: corev1.SecretTypeOpaque, | ||
Data: map[string][]byte{ | ||
"accessKeyId": []byte(registryKeyId), | ||
"secretKey": []byte(registryKey), | ||
}, | ||
} | ||
|
||
return client.Secrets(namespace).Create(context.Background(), v1Secret, metav1.CreateOptions{}) | ||
} | ||
|
||
func createCirrosVM(client kubevirtcliv1.KubevirtClient, namespace string) (*v1.VirtualMachine, error) { | ||
dataVolume := libdv.NewDataVolume( | ||
libdv.WithRegistryURLSource("docker://quay.io/kubevirt/cirros-container-disk-demo"), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please do not use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @0xFelix Don't you think that this is an issue that such important libs for external projects tests living under |
||
libdv.WithForceBindAnnotation(), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should not be required, if the VM was started at least once. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. VM can't be exported if started and it's running. It should be stopped. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. VM is created as stopped by default. |
||
) | ||
dataVolume.Spec.Storage = &cdiv1beta1.StorageSpec{ | ||
Resources: corev1.ResourceRequirements{ | ||
Requests: corev1.ResourceList{ | ||
"storage": resource.MustParse("512Mi"), | ||
}, | ||
}, | ||
} | ||
v1VirtualMachine := libvmi.NewVirtualMachine( | ||
libvmi.New( | ||
libvmi.WithDataVolume("datavolumedisk", dataVolume.Name), | ||
libvmi.WithResourceMemory("256M"), | ||
), | ||
libvmi.WithDataVolumeTemplate(dataVolume), | ||
) | ||
|
||
return client.VirtualMachine(namespace).Create(context.Background(), v1VirtualMachine, metav1.CreateOptions{}) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
package testconfigs | ||
|
||
import ( | ||
pipev1 "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
|
||
"github.com/kubevirt/kubevirt-tekton-tasks/test/constants" | ||
"github.com/kubevirt/kubevirt-tekton-tasks/test/framework/testoptions" | ||
) | ||
|
||
type DiskUploaderTaskData struct { | ||
ExportSourceKind string | ||
ExportSourceName string | ||
VolumeName string | ||
ImageDestination string | ||
PushTimeout string | ||
SecretName string | ||
} | ||
|
||
type DiskUploaderTestConfig struct { | ||
TaskRunTestConfig | ||
TaskData DiskUploaderTaskData | ||
|
||
deploymentNamespace string | ||
} | ||
|
||
func (c *DiskUploaderTestConfig) Init(options *testoptions.TestOptions) { | ||
c.deploymentNamespace = options.DeployNamespace | ||
} | ||
|
||
func (c *DiskUploaderTestConfig) GetTaskRun() *pipev1.TaskRun { | ||
params := []pipev1.Param{ | ||
{ | ||
Name: "EXPORT_SOURCE_KIND", | ||
Value: pipev1.ParamValue{ | ||
Type: pipev1.ParamTypeString, | ||
StringVal: c.TaskData.ExportSourceKind, | ||
}, | ||
}, | ||
{ | ||
Name: "EXPORT_SOURCE_NAME", | ||
Value: pipev1.ParamValue{ | ||
Type: pipev1.ParamTypeString, | ||
StringVal: c.TaskData.ExportSourceName, | ||
}, | ||
}, | ||
{ | ||
Name: "VOLUME_NAME", | ||
Value: pipev1.ParamValue{ | ||
Type: pipev1.ParamTypeString, | ||
StringVal: c.TaskData.VolumeName, | ||
}, | ||
}, | ||
{ | ||
Name: "IMAGE_DESTINATION", | ||
Value: pipev1.ParamValue{ | ||
Type: pipev1.ParamTypeString, | ||
StringVal: c.TaskData.ImageDestination, | ||
}, | ||
}, | ||
{ | ||
Name: "PUSH_TIMEOUT", | ||
Value: pipev1.ParamValue{ | ||
Type: pipev1.ParamTypeString, | ||
StringVal: c.TaskData.PushTimeout, | ||
}, | ||
}, | ||
{ | ||
Name: "SECRET_NAME", | ||
Value: pipev1.ParamValue{ | ||
Type: pipev1.ParamTypeString, | ||
StringVal: c.TaskData.SecretName, | ||
}, | ||
}, | ||
} | ||
|
||
return &pipev1.TaskRun{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: constants.E2ETestsRandomName("taskrun-disk-uploader"), | ||
Namespace: c.deploymentNamespace, | ||
}, | ||
Spec: pipev1.TaskRunSpec{ | ||
TaskRef: &pipev1.TaskRef{ | ||
Name: "disk-uploader", | ||
Kind: pipev1.NamespacedTaskKind, | ||
}, | ||
Timeout: &metav1.Duration{Duration: c.GetTaskRunTimeout()}, | ||
Params: params, | ||
}, | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
DataVolumes
FG can be dropped I guess.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep just want to get confirmation from @ksimon1 about it, so this PR won't do any other changes except adding new tests.