From 2a1a7aa015137e9687b7971a2af7df20cf08eb33 Mon Sep 17 00:00:00 2001 From: Artyom Lukianov Date: Wed, 6 Jun 2018 18:24:30 +0300 Subject: [PATCH] Remove all methods related to ISCSI secrets Signed-off-by: Artyom Lukianov --- tests/utils.go | 59 ++++++++++++++------------------------- tests/vm_userdata_test.go | 7 +++-- tests/vmlifecycle_test.go | 5 +++- 3 files changed, 30 insertions(+), 41 deletions(-) diff --git a/tests/utils.go b/tests/utils.go index 8d913658950f..e41b750177ba 100644 --- a/tests/utils.go +++ b/tests/utils.go @@ -127,8 +127,7 @@ const ( ) const ( - iscsiIqn = "iqn.2017-01.io.kubevirt:sn.42" - iscsiSecretName = "iscsi-demo-secret" + iscsiIqn = "iqn.2017-01.io.kubevirt:sn.42" ) const ( @@ -136,6 +135,10 @@ const ( defaultWindowsDiskSize = "30Gi" ) +const ( + SecretLabel = "kubevirt.io/secret" +) + const VmResource = "virtualmachines" type ProcessFunc func(event *k8sv1.Event) (done bool) @@ -309,7 +312,6 @@ func AfterTestSuitCleanup() { func BeforeTestCleanup() { cleanNamespaces() - createIscsiSecrets() } func BeforeTestSuitSetup() { @@ -319,7 +321,6 @@ func BeforeTestSuitSetup() { createNamespaces() createServiceAccounts() - createIscsiSecrets() CreatePvISCSI(osAlpineISCSI, 2) CreatePVC(osAlpineISCSI, defaultDiskSize) @@ -655,7 +656,12 @@ func cleanNamespaces() { PanicOnError(virtCli.CoreV1().RESTClient().Delete().Namespace(namespace).Resource("pods").Do().Error()) // Remove all VM Secrets - PanicOnError(virtCli.CoreV1().RESTClient().Delete().Namespace(namespace).Resource("secrets").Do().Error()) + labelSelector := fmt.Sprintf("%s", SecretLabel) + PanicOnError( + virtCli.CoreV1().Secrets(namespace).DeleteCollection( + &metav1.DeleteOptions{}, metav1.ListOptions{LabelSelector: labelSelector}, + ), + ) // Remove all VM Presets PanicOnError(virtCli.RestClient().Delete().Namespace(namespace).Resource("virtualmachinepresets").Do().Error()) @@ -683,30 +689,6 @@ func removeNamespaces() { } } -func createIscsiSecrets() { - virtCli, err := kubecli.GetKubevirtClient() - PanicOnError(err) - - // Create a Test Namespaces - for _, namespace := range testNamespaces { - secret := k8sv1.Secret{ - ObjectMeta: metav1.ObjectMeta{ - Name: iscsiSecretName, - }, - Type: "kubernetes.io/iscsi-chap", - Data: map[string][]byte{ - "node.session.auth.password": []byte("demopassword"), - "node.session.auth.username": []byte("demouser"), - }, - } - - _, err := virtCli.CoreV1().Secrets(namespace).Create(&secret) - if !errors.IsAlreadyExists(err) { - PanicOnError(err) - } - } -} - func createNamespaces() { virtCli, err := kubecli.GetKubevirtClient() PanicOnError(err) @@ -961,17 +943,18 @@ func NewRandomVMWithe1000NetworkInterface() *v1.VirtualMachine { } // Block until the specified VM started and return the target node name. -func waitForVmStart(vm runtime.Object, seconds int, ignoreWarnings bool) (nodeName string) { - _, ok := vm.(*v1.VirtualMachine) +func waitForVmStart(obj runtime.Object, seconds int, ignoreWarnings bool) (nodeName string) { + vm, ok := obj.(*v1.VirtualMachine) Expect(ok).To(BeTrue(), "Object is not of type *v1.VM") + virtClient, err := kubecli.GetKubevirtClient() Expect(err).ToNot(HaveOccurred()) // Fetch the VM, to make sure we have a resourceVersion as a starting point for the watch - vmMeta := vm.(*v1.VirtualMachine).ObjectMeta - obj, err := virtClient.RestClient().Get().Resource("virtualmachines").Namespace(vmMeta.Namespace).Name(vmMeta.Name).Do().Get() + vm, err = virtClient.VM(vm.Namespace).Get(vm.Name, metav1.GetOptions{}) + Expect(err).ToNot(HaveOccurred()) - objectEventWatcher := NewObjectEventWatcher(obj).SinceWatchedObjectResourceVersion().Timeout(time.Duration(seconds) * time.Second) + objectEventWatcher := NewObjectEventWatcher(vm).SinceWatchedObjectResourceVersion().Timeout(time.Duration(seconds) * time.Second) if ignoreWarnings != true { objectEventWatcher.FailOnWarnings() } @@ -979,13 +962,13 @@ func waitForVmStart(vm runtime.Object, seconds int, ignoreWarnings bool) (nodeNa // FIXME the event order is wrong. First the document should be updated Eventually(func() bool { - obj, err := virtClient.RestClient().Get().Resource("virtualmachines").Namespace(vmMeta.Namespace).Name(vmMeta.Name).Do().Get() + vm, err = virtClient.VM(vm.Namespace).Get(vm.Name, metav1.GetOptions{}) Expect(err).ToNot(HaveOccurred()) - fetchedVM := obj.(*v1.VirtualMachine) - nodeName = fetchedVM.Status.NodeName + + nodeName = vm.Status.NodeName // wait on both phase and graphics - if fetchedVM.Status.Phase == v1.Running { + if vm.Status.Phase == v1.Running { return true } return false diff --git a/tests/vm_userdata_test.go b/tests/vm_userdata_test.go index afab43af5c75..19ba540549b1 100644 --- a/tests/vm_userdata_test.go +++ b/tests/vm_userdata_test.go @@ -178,14 +178,17 @@ var _ = Describe("CloudInit UserData", func() { secret := kubev1.Secret{ ObjectMeta: metav1.ObjectMeta{ Name: secretID, - Namespace: vm.GetObjectMeta().GetNamespace(), + Namespace: vm.Namespace, + Labels: map[string]string{ + tests.SecretLabel: secretID, + }, }, Type: "Opaque", Data: map[string][]byte{ "userdata": []byte(userData), // The client encrypts the secret for us }, } - _, err := virtClient.CoreV1().Secrets(vm.GetObjectMeta().GetNamespace()).Create(&secret) + _, err := virtClient.CoreV1().Secrets(vm.Namespace).Create(&secret) Expect(err).To(BeNil()) break } diff --git a/tests/vmlifecycle_test.go b/tests/vmlifecycle_test.go index e811b00a53af..6fdceff80c2e 100644 --- a/tests/vmlifecycle_test.go +++ b/tests/vmlifecycle_test.go @@ -243,7 +243,10 @@ var _ = Describe("Vmlifecycle", func() { secret := k8sv1.Secret{ ObjectMeta: metav1.ObjectMeta{ Name: "nonexistent", - Namespace: vm.GetObjectMeta().GetNamespace(), + Namespace: vm.Namespace, + Labels: map[string]string{ + tests.SecretLabel: "nonexistent", + }, }, Type: "Opaque", Data: map[string][]byte{