|
| 1 | +package e2e |
| 2 | + |
| 3 | +import ( |
| 4 | + "fmt" |
| 5 | + . "github.com/onsi/gomega" |
| 6 | + . "github.com/project-codeflare/codeflare-operator/test/support" |
| 7 | + mcadv1beta1 "github.com/project-codeflare/multi-cluster-app-dispatcher/pkg/apis/controller/v1beta1" |
| 8 | + corev1 "k8s.io/api/core/v1" |
| 9 | + "k8s.io/apimachinery/pkg/api/resource" |
| 10 | + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" |
| 11 | + "testing" |
| 12 | +) |
| 13 | + |
| 14 | +var ( |
| 15 | + ocmToken string |
| 16 | + machinePoolsExist bool |
| 17 | + numInitialNodePools int |
| 18 | + numInitialMachineSets int |
| 19 | +) |
| 20 | + |
| 21 | +func TestInstascale(t *testing.T) { |
| 22 | + |
| 23 | + test := With(t) |
| 24 | + test.T().Parallel() |
| 25 | + |
| 26 | + namespace := test.NewTestNamespace() |
| 27 | + |
| 28 | + connection, err := CreateOCMConnection() |
| 29 | + if err != nil { |
| 30 | + test.T().Errorf("Unable to create ocm connection - Error : %v", err) |
| 31 | + } |
| 32 | + defer connection.Close() |
| 33 | + |
| 34 | + machinePoolsExist = true |
| 35 | + // check existing machine pools |
| 36 | + numInitialMachinePools, err := MachinePoolsCount(connection) |
| 37 | + if err != nil { |
| 38 | + test.T().Errorf("Unable to count machine pools - Error : %v", err) |
| 39 | + } |
| 40 | + |
| 41 | + if numInitialMachinePools == 0 { |
| 42 | + machinePoolsExist = false |
| 43 | + numInitialNodePools, err = NodePoolsCount(connection) |
| 44 | + if err != nil { |
| 45 | + test.T().Errorf("Unable to count node pools - Error : %v", err) |
| 46 | + } |
| 47 | + if numInitialNodePools == 0 { |
| 48 | + numInitialMachineSets, err = MachineSetsCount(connection) |
| 49 | + if err != nil { |
| 50 | + test.T().Errorf("Unable to count machine sets - Error : %v", err) |
| 51 | + } |
| 52 | + } |
| 53 | + } |
| 54 | + |
| 55 | + // create an appwrapper |
| 56 | + aw := &mcadv1beta1.AppWrapper{ |
| 57 | + ObjectMeta: metav1.ObjectMeta{ |
| 58 | + Name: "test-instascale", |
| 59 | + Namespace: namespace.Name, |
| 60 | + Labels: map[string]string{ |
| 61 | + "orderedinstance": "m5.xlarge_g4dn.xlarge", |
| 62 | + }, |
| 63 | + }, |
| 64 | + Spec: mcadv1beta1.AppWrapperSpec{ |
| 65 | + AggrResources: mcadv1beta1.AppWrapperResourceList{ |
| 66 | + GenericItems: []mcadv1beta1.AppWrapperGenericResource{ |
| 67 | + { |
| 68 | + CustomPodResources: []mcadv1beta1.CustomPodResourceTemplate{ |
| 69 | + { |
| 70 | + Replicas: 1, |
| 71 | + Requests: corev1.ResourceList{ |
| 72 | + corev1.ResourceCPU: resource.MustParse("250m"), |
| 73 | + corev1.ResourceMemory: resource.MustParse("512Mi"), |
| 74 | + }, |
| 75 | + Limits: corev1.ResourceList{ |
| 76 | + corev1.ResourceCPU: resource.MustParse("500m"), |
| 77 | + corev1.ResourceMemory: resource.MustParse("1G"), |
| 78 | + }, |
| 79 | + }, |
| 80 | + { |
| 81 | + Replicas: 1, |
| 82 | + Requests: corev1.ResourceList{ |
| 83 | + corev1.ResourceCPU: resource.MustParse("250m"), |
| 84 | + corev1.ResourceMemory: resource.MustParse("512Mi"), |
| 85 | + }, |
| 86 | + Limits: corev1.ResourceList{ |
| 87 | + corev1.ResourceCPU: resource.MustParse("500m"), |
| 88 | + corev1.ResourceMemory: resource.MustParse("1G"), |
| 89 | + }, |
| 90 | + }, |
| 91 | + }, |
| 92 | + }, |
| 93 | + }, |
| 94 | + }, |
| 95 | + }, |
| 96 | + } |
| 97 | + |
| 98 | + aw, err = test.Client().MCAD().McadV1beta1().AppWrappers(namespace.Name).Create(test.Ctx(), aw, metav1.CreateOptions{}) |
| 99 | + test.Expect(err).NotTo(HaveOccurred()) |
| 100 | + test.T().Logf("AppWrapper created successfully %s/%s", aw.Namespace, aw.Name) |
| 101 | + |
| 102 | + test.Eventually(AppWrapper(test, namespace, aw.Name), TestTimeoutMedium). |
| 103 | + Should(WithTransform(AppWrapperState, Equal(mcadv1beta1.AppWrapperStateActive))) |
| 104 | + |
| 105 | + if !machinePoolsExist { |
| 106 | + numNodePools, err := NodePoolsCount(connection) |
| 107 | + if err != nil { |
| 108 | + test.T().Errorf("Unable to count node pools - Error : %v", err) |
| 109 | + } |
| 110 | + fmt.Println(numNodePools) |
| 111 | + test.Expect(numNodePools).To(BeNumerically(">", numInitialNodePools)) |
| 112 | + test.T().Logf("number of machine pools increased") |
| 113 | + |
| 114 | + } else if machinePoolsExist { |
| 115 | + numMachinePools, err := MachinePoolsCount(connection) |
| 116 | + if err != nil { |
| 117 | + test.T().Errorf("Unable to count machine pools - Error : %v", err) |
| 118 | + } |
| 119 | + fmt.Println(numMachinePools) |
| 120 | + test.Expect(numMachinePools).To(BeNumerically(">", numInitialMachinePools)) |
| 121 | + test.T().Logf("number of machine pools increased") |
| 122 | + } else { |
| 123 | + numMachineSets, err := MachineSetsCount(connection) |
| 124 | + if err != nil { |
| 125 | + test.T().Errorf("Unable to count machine sets - Error : %v", err) |
| 126 | + } |
| 127 | + fmt.Println(numMachineSets) |
| 128 | + test.Expect(numMachineSets).To(BeNumerically(">", numInitialMachineSets)) |
| 129 | + test.T().Logf("number of machine sets increased") |
| 130 | + } |
| 131 | + |
| 132 | + // TODO submit and check that the job has completed and that resources are released/scaled down |
| 133 | +} |
0 commit comments