From c716e32534918af32700d72555106efb98e6f1f1 Mon Sep 17 00:00:00 2001 From: "Michael N. Lipp" Date: Sun, 30 Mar 2025 11:42:03 +0200 Subject: [PATCH] Make tests work again. --- .../test-resources/basic-vm.yaml | 4 +- .../test-resources/kustomization.yaml | 111 ++++++++++++++++++ .../vmoperator/manager/BasicTests.java | 28 ++--- 3 files changed, 127 insertions(+), 16 deletions(-) create mode 100644 org.jdrupes.vmoperator.manager/test-resources/kustomization.yaml diff --git a/org.jdrupes.vmoperator.manager/test-resources/basic-vm.yaml b/org.jdrupes.vmoperator.manager/test-resources/basic-vm.yaml index 54ea110..36054a2 100644 --- a/org.jdrupes.vmoperator.manager/test-resources/basic-vm.yaml +++ b/org.jdrupes.vmoperator.manager/test-resources/basic-vm.yaml @@ -1,8 +1,8 @@ apiVersion: "vmoperator.jdrupes.org/v1" kind: VirtualMachine metadata: - namespace: vmop-dev - name: unittest-vm + namespace: vmop-test + name: test-vm spec: image: repository: docker-registry.lan.mnl.de diff --git a/org.jdrupes.vmoperator.manager/test-resources/kustomization.yaml b/org.jdrupes.vmoperator.manager/test-resources/kustomization.yaml new file mode 100644 index 0000000..3a8451e --- /dev/null +++ b/org.jdrupes.vmoperator.manager/test-resources/kustomization.yaml @@ -0,0 +1,111 @@ +apiVersion: kustomize.config.k8s.io/v1beta1 +kind: Kustomization + +resources: +- ../../deploy + +namespace: vmop-test + +patches: +- patch: |- + kind: PersistentVolumeClaim + apiVersion: v1 + metadata: + name: vmop-image-repository + spec: + accessModes: + - ReadWriteOnce + resources: + requests: + storage: 10Gi + storageClassName: local-path + +- patch: |- + kind: ConfigMap + apiVersion: v1 + metadata: + name: vm-operator + data: + # Keep in sync with config.yaml + config.yaml: | + "/Manager": + # clusterName: "test" + "/Controller": + "/Reconciler": + runnerData: + storageClassName: null + loadBalancerService: + labels: + label1: label1 + label2: toBeReplaced + annotations: + metallb.universe.tf/loadBalancerIPs: 192.168.168.1 + metallb.universe.tf/ip-allocated-from-pool: single-common + metallb.universe.tf/allow-shared-ip: single-common + "/GuiSocketServer": + port: 8888 + "/GuiHttpServer": + # This configures the GUI + "/ConsoleWeblet": + "/WebConsole": + "/LoginConlet": + users: + - name: admin + fullName: Administrator + password: "$2b$05$NiBd74ZGdplLC63ePZf1f.UtjMKkbQ23cQoO2OKOFalDBHWAOy21." + - name: test1 + fullName: Test Account + password: "$2b$05$hZaI/jToXf/d3BctZdT38Or7H7h6Pn2W3WiB49p5AyhDHFkkYCvo2" + - name: test2 + fullName: Test Account + password: "$2b$05$hZaI/jToXf/d3BctZdT38Or7H7h6Pn2W3WiB49p5AyhDHFkkYCvo2" + - name: test3 + fullName: Test Account + password: "$2b$05$hZaI/jToXf/d3BctZdT38Or7H7h6Pn2W3WiB49p5AyhDHFkkYCvo2" + "/RoleConfigurator": + rolesByUser: + # User admin has role admin + admin: + - admin + test1: + - user + test2: + - user + test3: + - user + # All users have role other + "*": + - other + replace: false + "/RoleConletFilter": + conletTypesByRole: + # Admins can use all conlets + admin: + - "*" + user: + - org.jdrupes.vmoperator.vmviewer.VmViewer + # Others cannot use any conlet (except login conlet to log out) + other: + - org.jgrapes.webconlet.locallogin.LoginConlet + "/ComponentCollector": + "/VmAccess": + displayResource: + preferredIpVersion: ipv4 + syncPreviewsFor: + - role: user +- target: + group: apps + version: v1 + kind: Deployment + name: vm-operator + patch: |- + - op: replace + path: /spec/template/spec/containers/0/image + value: docker-registry.lan.mnl.de/vmoperator/org.jdrupes.vmoperator.manager:test + - op: replace + path: /spec/template/spec/containers/0/imagePullPolicy + value: Always + - op: replace + path: /spec/replicas + value: 0 + \ No newline at end of file diff --git a/org.jdrupes.vmoperator.manager/test/org/jdrupes/vmoperator/manager/BasicTests.java b/org.jdrupes.vmoperator.manager/test/org/jdrupes/vmoperator/manager/BasicTests.java index 03db0d2..d600d3c 100644 --- a/org.jdrupes.vmoperator.manager/test/org/jdrupes/vmoperator/manager/BasicTests.java +++ b/org.jdrupes.vmoperator.manager/test/org/jdrupes/vmoperator/manager/BasicTests.java @@ -41,7 +41,7 @@ class BasicTests { private static APIResource vmsContext; private static K8sV1DeploymentStub mgrDeployment; private static K8sDynamicStub vmStub; - private static final String VM_NAME = "unittest-vm"; + private static final String VM_NAME = "test-vm"; private static final Object EXISTS = new Object(); @BeforeAll @@ -54,7 +54,7 @@ class BasicTests { // Update manager pod by scaling deployment mgrDeployment - = K8sV1DeploymentStub.get(client, "vmop-dev", "vm-operator"); + = K8sV1DeploymentStub.get(client, "vmop-test", "vm-operator"); mgrDeployment.scale(0); mgrDeployment.scale(1); waitForManager(); @@ -65,13 +65,13 @@ class BasicTests { vmsContext = apiRes.get(); // Cleanup existing VM - K8sDynamicStub.get(client, vmsContext, "vmop-dev", VM_NAME) + K8sDynamicStub.get(client, vmsContext, "vmop-test", VM_NAME) .delete(); ListOptions listOpts = new ListOptions(); listOpts.setLabelSelector("app.kubernetes.io/name=" + APP_NAME + "," + "app.kubernetes.io/instance=" + VM_NAME + "," + "app.kubernetes.io/component=" + DisplaySecret.NAME); - var secrets = K8sV1SecretStub.list(client, "vmop-dev", listOpts); + var secrets = K8sV1SecretStub.list(client, "vmop-test", listOpts); for (var secret : secrets) { secret.delete(); } @@ -103,7 +103,7 @@ class BasicTests { "app.kubernetes.io/managed-by=" + VM_OP_NAME + "," + "app.kubernetes.io/name=" + APP_NAME + "," + "app.kubernetes.io/instance=" + VM_NAME); - var knownPvcs = K8sV1PvcStub.list(client, "vmop-dev", listOpts); + var knownPvcs = K8sV1PvcStub.list(client, "vmop-test", listOpts); for (var pvc : knownPvcs) { pvc.delete(); } @@ -112,7 +112,7 @@ class BasicTests { @AfterAll static void tearDownAfterClass() throws Exception { // Cleanup - K8sDynamicStub.get(client, vmsContext, "vmop-dev", VM_NAME) + K8sDynamicStub.get(client, vmsContext, "vmop-test", VM_NAME) .delete(); deletePvcs(); @@ -124,7 +124,7 @@ class BasicTests { void testConfigMap() throws IOException, InterruptedException, ApiException { K8sV1ConfigMapStub stub - = K8sV1ConfigMapStub.get(client, "vmop-dev", VM_NAME); + = K8sV1ConfigMapStub.get(client, "vmop-test", VM_NAME); for (int i = 0; i < 10; i++) { if (stub.model().isPresent()) { break; @@ -134,7 +134,7 @@ class BasicTests { // Check config map var config = stub.model().get(); Map, Object> toCheck = Map.of( - List.of("namespace"), "vmop-dev", + List.of("namespace"), "vmop-test", List.of("name"), VM_NAME, List.of("labels", "app.kubernetes.io/name"), Constants.APP_NAME, List.of("labels", "app.kubernetes.io/instance"), VM_NAME, @@ -191,7 +191,7 @@ class BasicTests { + "app.kubernetes.io/component=" + DisplaySecret.NAME); Collection secrets = null; for (int i = 0; i < 10; i++) { - secrets = K8sV1SecretStub.list(client, "vmop-dev", listOpts); + secrets = K8sV1SecretStub.list(client, "vmop-test", listOpts); if (secrets.size() > 0) { break; } @@ -207,7 +207,7 @@ class BasicTests { @Test void testRunnerPvc() throws ApiException, InterruptedException { var stub - = K8sV1PvcStub.get(client, "vmop-dev", VM_NAME + "-runner-data"); + = K8sV1PvcStub.get(client, "vmop-test", VM_NAME + "-runner-data"); for (int i = 0; i < 10; i++) { if (stub.model().isPresent()) { break; @@ -227,7 +227,7 @@ class BasicTests { @Test void testSystemDiskPvc() throws ApiException, InterruptedException { var stub - = K8sV1PvcStub.get(client, "vmop-dev", VM_NAME + "-system-disk"); + = K8sV1PvcStub.get(client, "vmop-test", VM_NAME + "-system-disk"); for (int i = 0; i < 10; i++) { if (stub.model().isPresent()) { break; @@ -248,7 +248,7 @@ class BasicTests { @Test void testDisk1Pvc() throws ApiException, InterruptedException { var stub - = K8sV1PvcStub.get(client, "vmop-dev", VM_NAME + "-disk-1"); + = K8sV1PvcStub.get(client, "vmop-test", VM_NAME + "-disk-1"); for (int i = 0; i < 10; i++) { if (stub.model().isPresent()) { break; @@ -274,7 +274,7 @@ class BasicTests { new V1Patch("[{\"op\": \"replace\", \"path\": \"/spec/vm/state" + "\", \"value\": \"Running\"}]"), client.defaultPatchOptions()).isPresent()); - var stub = K8sV1PodStub.get(client, "vmop-dev", VM_NAME); + var stub = K8sV1PodStub.get(client, "vmop-test", VM_NAME); for (int i = 0; i < 20; i++) { if (stub.model().isPresent()) { break; @@ -303,7 +303,7 @@ class BasicTests { @Test public void testLoadBalancer() throws ApiException, InterruptedException { - var stub = K8sV1ServiceStub.get(client, "vmop-dev", VM_NAME); + var stub = K8sV1ServiceStub.get(client, "vmop-test", VM_NAME); for (int i = 0; i < 10; i++) { if (stub.model().isPresent()) { break;