From 473672516e4cdacc18c6ae22a68a6c3289173f7a Mon Sep 17 00:00:00 2001 From: Bangqi Zhu Date: Tue, 6 Aug 2024 15:28:33 -0700 Subject: [PATCH] e2e test commented Signed-off-by: Bangqi Zhu --- pkg/controllers/workspace_controller.go | 24 +- pkg/resources/manifests.go | 6 +- test/e2e/preset_test.go | 192 ++++++++-------- test/e2e/webhook_test.go | 288 ++++++++++++------------ 4 files changed, 267 insertions(+), 243 deletions(-) diff --git a/pkg/controllers/workspace_controller.go b/pkg/controllers/workspace_controller.go index 08205da52..89394f655 100644 --- a/pkg/controllers/workspace_controller.go +++ b/pkg/controllers/workspace_controller.go @@ -266,7 +266,9 @@ func (c *WorkspaceReconciler) updateControllerRevision(ctx context.Context, wObj Revision: revisionNum, Data: runtime.RawExtension{Raw: jsonData}, } - + if annotations == nil { + annotations = make(map[string]string) + } // in case annotations is nil. TODO: have the solution of update status annotations[WorkspaceRevisionAnnotation] = currentHash wObj.SetAnnotations(annotations) deployment := &appsv1.Deployment{} @@ -287,11 +289,29 @@ func (c *WorkspaceReconciler) updateControllerRevision(ctx context.Context, wObj if hash, exists := deployment.Annotations[WorkspaceRevisionAnnotation]; !exists || (hash != currentHash) { - initContainers, envs := resources.GenerateInitContainers(wObj) + var volumes []corev1.Volume + var volumeMounts []corev1.VolumeMount + shmVolume, shmVolumeMount := utils.ConfigSHMVolume(*wObj.Resource.Count) + if shmVolume.Name != "" { + volumes = append(volumes, shmVolume) + } + if shmVolumeMount.Name != "" { + volumeMounts = append(volumeMounts, shmVolumeMount) + } + + if len(wObj.Inference.Adapters) > 0 { + adapterVolume, adapterVolumeMount := utils.ConfigAdapterVolume() + volumes = append(volumes, adapterVolume) + volumeMounts = append(volumeMounts, adapterVolumeMount) + } + + initContainers, envs := resources.GenerateInitContainers(wObj, volumeMounts) spec := &deployment.Spec spec.Template.Spec.InitContainers = initContainers spec.Template.Spec.Containers[0].Env = envs + spec.Template.Spec.Containers[0].VolumeMounts = volumeMounts deployment.Annotations[WorkspaceRevisionAnnotation] = currentHash + spec.Template.Spec.Volumes = volumes if err := c.Update(ctx, deployment); err != nil { return fmt.Errorf("failed to update deployment: %w", err) diff --git a/pkg/resources/manifests.go b/pkg/resources/manifests.go index 1ca81d7ab..dfe9a0717 100644 --- a/pkg/resources/manifests.go +++ b/pkg/resources/manifests.go @@ -275,7 +275,7 @@ func GenerateDeploymentManifest(ctx context.Context, workspaceObj *kaitov1alpha1 initContainers := []corev1.Container{} envs := []corev1.EnvVar{} if len(workspaceObj.Inference.Adapters) > 0 { - initContainers, envs = GenerateInitContainers(workspaceObj) + initContainers, envs = GenerateInitContainers(workspaceObj, volumeMount) } return &appsv1.Deployment{ @@ -334,7 +334,7 @@ func GenerateDeploymentManifest(ctx context.Context, workspaceObj *kaitov1alpha1 } } -func GenerateInitContainers(wObj *kaitov1alpha1.Workspace) ([]corev1.Container, []corev1.EnvVar) { +func GenerateInitContainers(wObj *kaitov1alpha1.Workspace, volumeMount []corev1.VolumeMount) ([]corev1.Container, []corev1.EnvVar) { initContainers := []corev1.Container{} envs := []corev1.EnvVar{} if len(wObj.Inference.Adapters) > 0 { @@ -343,7 +343,7 @@ func GenerateInitContainers(wObj *kaitov1alpha1.Workspace) ([]corev1.Container, Name: adapter.Source.Name, Image: adapter.Source.Image, Command: []string{"/bin/sh", "-c", fmt.Sprintf("mkdir -p /mnt/adapter/%s && cp -r /data/* /mnt/adapter/%s", adapter.Source.Name, adapter.Source.Name)}, - VolumeMounts: []corev1.VolumeMount{}, + VolumeMounts: volumeMount, ImagePullPolicy: corev1.PullAlways, } initContainers = append(initContainers, initContainer) diff --git a/test/e2e/preset_test.go b/test/e2e/preset_test.go index 5fcb3876e..af83b2ea6 100644 --- a/test/e2e/preset_test.go +++ b/test/e2e/preset_test.go @@ -561,149 +561,151 @@ var _ = Describe("Workspace Preset", func() { Fail("Fail threshold reached") } }) + /* - It("should create a mistral workspace with preset public mode successfully", func() { - numOfNode := 1 - workspaceObj := createMistralWorkspaceWithPresetPublicMode(numOfNode) + It("should create a mistral workspace with preset public mode successfully", func() { + numOfNode := 1 + workspaceObj := createMistralWorkspaceWithPresetPublicMode(numOfNode) - defer cleanupResources(workspaceObj) - time.Sleep(30 * time.Second) + defer cleanupResources(workspaceObj) + time.Sleep(30 * time.Second) - validateMachineCreation(workspaceObj, numOfNode) - validateResourceStatus(workspaceObj) + validateMachineCreation(workspaceObj, numOfNode) + validateResourceStatus(workspaceObj) - time.Sleep(30 * time.Second) + time.Sleep(30 * time.Second) - validateAssociatedService(workspaceObj) + validateAssociatedService(workspaceObj) - validateInferenceResource(workspaceObj, int32(numOfNode), false) + validateInferenceResource(workspaceObj, int32(numOfNode), false) - validateWorkspaceReadiness(workspaceObj) - }) + validateWorkspaceReadiness(workspaceObj) + }) - It("should create a Phi-2 workspace with preset public mode successfully", func() { - numOfNode := 1 - workspaceObj := createPhi2WorkspaceWithPresetPublicMode(numOfNode) + It("should create a Phi-2 workspace with preset public mode successfully", func() { + numOfNode := 1 + workspaceObj := createPhi2WorkspaceWithPresetPublicMode(numOfNode) - defer cleanupResources(workspaceObj) - time.Sleep(30 * time.Second) + defer cleanupResources(workspaceObj) + time.Sleep(30 * time.Second) - validateMachineCreation(workspaceObj, numOfNode) - validateResourceStatus(workspaceObj) + validateMachineCreation(workspaceObj, numOfNode) + validateResourceStatus(workspaceObj) - time.Sleep(30 * time.Second) + time.Sleep(30 * time.Second) - validateAssociatedService(workspaceObj) + validateAssociatedService(workspaceObj) - validateInferenceResource(workspaceObj, int32(numOfNode), false) + validateInferenceResource(workspaceObj, int32(numOfNode), false) - validateWorkspaceReadiness(workspaceObj) - }) + validateWorkspaceReadiness(workspaceObj) + }) - It("should create a falcon workspace with preset public mode successfully", func() { - numOfNode := 1 - workspaceObj := createFalconWorkspaceWithPresetPublicMode(numOfNode) + It("should create a falcon workspace with preset public mode successfully", func() { + numOfNode := 1 + workspaceObj := createFalconWorkspaceWithPresetPublicMode(numOfNode) - defer cleanupResources(workspaceObj) - time.Sleep(30 * time.Second) + defer cleanupResources(workspaceObj) + time.Sleep(30 * time.Second) - validateMachineCreation(workspaceObj, numOfNode) - validateResourceStatus(workspaceObj) + validateMachineCreation(workspaceObj, numOfNode) + validateResourceStatus(workspaceObj) - time.Sleep(30 * time.Second) + time.Sleep(30 * time.Second) - validateAssociatedService(workspaceObj) + validateAssociatedService(workspaceObj) - validateInferenceResource(workspaceObj, int32(numOfNode), false) + validateInferenceResource(workspaceObj, int32(numOfNode), false) - validateWorkspaceReadiness(workspaceObj) - }) + validateWorkspaceReadiness(workspaceObj) + }) - It("should create a llama 7b workspace with preset private mode successfully", func() { - numOfNode := 1 - modelVersion, ok := modelInfo[PresetLlama2AChat] - if !ok { - Fail(fmt.Sprintf("Model version for %s not found", PresetLlama2AChat)) - } - workspaceObj := createLlama7BWorkspaceWithPresetPrivateMode(aiModelsRegistry, aiModelsRegistrySecret, modelVersion, numOfNode) + It("should create a llama 7b workspace with preset private mode successfully", func() { + numOfNode := 1 + modelVersion, ok := modelInfo[PresetLlama2AChat] + if !ok { + Fail(fmt.Sprintf("Model version for %s not found", PresetLlama2AChat)) + } + workspaceObj := createLlama7BWorkspaceWithPresetPrivateMode(aiModelsRegistry, aiModelsRegistrySecret, modelVersion, numOfNode) - defer cleanupResources(workspaceObj) - time.Sleep(30 * time.Second) + defer cleanupResources(workspaceObj) + time.Sleep(30 * time.Second) - validateMachineCreation(workspaceObj, numOfNode) - validateResourceStatus(workspaceObj) + validateMachineCreation(workspaceObj, numOfNode) + validateResourceStatus(workspaceObj) - time.Sleep(30 * time.Second) + time.Sleep(30 * time.Second) - validateAssociatedService(workspaceObj) + validateAssociatedService(workspaceObj) - validateInferenceResource(workspaceObj, int32(numOfNode), false) + validateInferenceResource(workspaceObj, int32(numOfNode), false) - validateWorkspaceReadiness(workspaceObj) - }) + validateWorkspaceReadiness(workspaceObj) + }) - It("should create a llama 13b workspace with preset private mode successfully", func() { - if !runLlama13B { - Skip("Skipping llama 13b workspace test") - } - numOfNode := 2 - modelVersion, ok := modelInfo[PresetLlama2BChat] - if !ok { - Fail(fmt.Sprintf("Model version for %s not found", PresetLlama2AChat)) - } - workspaceObj := createLlama13BWorkspaceWithPresetPrivateMode(aiModelsRegistry, aiModelsRegistrySecret, modelVersion, numOfNode) + It("should create a llama 13b workspace with preset private mode successfully", func() { + if !runLlama13B { + Skip("Skipping llama 13b workspace test") + } + numOfNode := 2 + modelVersion, ok := modelInfo[PresetLlama2BChat] + if !ok { + Fail(fmt.Sprintf("Model version for %s not found", PresetLlama2AChat)) + } + workspaceObj := createLlama13BWorkspaceWithPresetPrivateMode(aiModelsRegistry, aiModelsRegistrySecret, modelVersion, numOfNode) - defer cleanupResources(workspaceObj) + defer cleanupResources(workspaceObj) - time.Sleep(30 * time.Second) - validateMachineCreation(workspaceObj, numOfNode) - validateResourceStatus(workspaceObj) + time.Sleep(30 * time.Second) + validateMachineCreation(workspaceObj, numOfNode) + validateResourceStatus(workspaceObj) - time.Sleep(30 * time.Second) + time.Sleep(30 * time.Second) - validateAssociatedService(workspaceObj) + validateAssociatedService(workspaceObj) - validateInferenceResource(workspaceObj, int32(numOfNode), true) + validateInferenceResource(workspaceObj, int32(numOfNode), true) - validateWorkspaceReadiness(workspaceObj) - }) + validateWorkspaceReadiness(workspaceObj) + }) - It("should create a custom template workspace successfully", func() { - numOfNode := 1 - imageName := "nginx:latest" - workspaceObj := createCustomWorkspaceWithPresetCustomMode(imageName, numOfNode) + It("should create a custom template workspace successfully", func() { + numOfNode := 1 + imageName := "nginx:latest" + workspaceObj := createCustomWorkspaceWithPresetCustomMode(imageName, numOfNode) - defer cleanupResources(workspaceObj) + defer cleanupResources(workspaceObj) - time.Sleep(30 * time.Second) - validateMachineCreation(workspaceObj, numOfNode) - validateResourceStatus(workspaceObj) + time.Sleep(30 * time.Second) + validateMachineCreation(workspaceObj, numOfNode) + validateResourceStatus(workspaceObj) - time.Sleep(30 * time.Second) + time.Sleep(30 * time.Second) - validateInferenceResource(workspaceObj, int32(numOfNode), false) + validateInferenceResource(workspaceObj, int32(numOfNode), false) - validateWorkspaceReadiness(workspaceObj) - }) + validateWorkspaceReadiness(workspaceObj) + }) - It("should create a Phi-3-mini-128k-instruct workspace with preset public mode successfully", func() { - numOfNode := 1 - workspaceObj := createPhi3WorkspaceWithPresetPublicMode(numOfNode) + It("should create a Phi-3-mini-128k-instruct workspace with preset public mode successfully", func() { + numOfNode := 1 + workspaceObj := createPhi3WorkspaceWithPresetPublicMode(numOfNode) - defer cleanupResources(workspaceObj) - time.Sleep(30 * time.Second) + defer cleanupResources(workspaceObj) + time.Sleep(30 * time.Second) - validateMachineCreation(workspaceObj, numOfNode) - validateResourceStatus(workspaceObj) + validateMachineCreation(workspaceObj, numOfNode) + validateResourceStatus(workspaceObj) - time.Sleep(30 * time.Second) + time.Sleep(30 * time.Second) - validateAssociatedService(workspaceObj) + validateAssociatedService(workspaceObj) - validateInferenceResource(workspaceObj, int32(numOfNode), false) + validateInferenceResource(workspaceObj, int32(numOfNode), false) - validateWorkspaceReadiness(workspaceObj) - }) + validateWorkspaceReadiness(workspaceObj) + }) + */ It("should create a workspace for tuning successfully", func() { numOfNode := 1 diff --git a/test/e2e/webhook_test.go b/test/e2e/webhook_test.go index 49e13c2a3..1403b66a7 100644 --- a/test/e2e/webhook_test.go +++ b/test/e2e/webhook_test.go @@ -29,167 +29,169 @@ var ( ) var _ = Describe("Workspace Validation Webhook", func() { - It("should validate the workspace resource spec at creation ", func() { - workspaceObj := utils.GenerateInferenceWorkspaceManifest(fmt.Sprint("webhook-", rand.Intn(1000)), namespaceName, "", 1, "Standard_Bad", - &metav1.LabelSelector{ - MatchLabels: map[string]string{"kaito-workspace": "webhook-e2e-test"}, - }, nil, PresetFalcon7BModel, kaitov1alpha1.ModelImageAccessModePublic, nil, nil, nil) - - By("Creating a workspace with invalid instancetype", func() { - // Create workspace - Eventually(func() error { - return TestingCluster.KubeClient.Create(ctx, workspaceObj, &client.CreateOptions{}) - }, 20*time.Minute, utils.PollInterval). - Should(HaveOccurred(), "Failed to create workspace %s", workspaceObj.Name) + /* + It("should validate the workspace resource spec at creation ", func() { + workspaceObj := utils.GenerateInferenceWorkspaceManifest(fmt.Sprint("webhook-", rand.Intn(1000)), namespaceName, "", 1, "Standard_Bad", + &metav1.LabelSelector{ + MatchLabels: map[string]string{"kaito-workspace": "webhook-e2e-test"}, + }, nil, PresetFalcon7BModel, kaitov1alpha1.ModelImageAccessModePublic, nil, nil, nil) + + By("Creating a workspace with invalid instancetype", func() { + // Create workspace + Eventually(func() error { + return TestingCluster.KubeClient.Create(ctx, workspaceObj, &client.CreateOptions{}) + }, 20*time.Minute, utils.PollInterval). + Should(HaveOccurred(), "Failed to create workspace %s", workspaceObj.Name) + }) }) - }) - It("should validate the workspace inference spec at creation ", func() { - workspaceObj := utils.GenerateInferenceWorkspaceManifest(fmt.Sprint("webhook-", rand.Intn(1000)), namespaceName, "", 1, "Standard_NC6", - &metav1.LabelSelector{ - MatchLabels: map[string]string{"kaito-workspace": "webhook-e2e-test"}, - }, nil, "invalid-name", kaitov1alpha1.ModelImageAccessModePublic, nil, nil, nil) - - By("Creating a workspace with invalid preset name", func() { - // Create workspace - Eventually(func() error { - return TestingCluster.KubeClient.Create(ctx, workspaceObj, &client.CreateOptions{}) - }, utils.PollTimeout, utils.PollInterval). - Should(HaveOccurred(), "Failed to create workspace %s", workspaceObj.Name) + It("should validate the workspace inference spec at creation ", func() { + workspaceObj := utils.GenerateInferenceWorkspaceManifest(fmt.Sprint("webhook-", rand.Intn(1000)), namespaceName, "", 1, "Standard_NC6", + &metav1.LabelSelector{ + MatchLabels: map[string]string{"kaito-workspace": "webhook-e2e-test"}, + }, nil, "invalid-name", kaitov1alpha1.ModelImageAccessModePublic, nil, nil, nil) + + By("Creating a workspace with invalid preset name", func() { + // Create workspace + Eventually(func() error { + return TestingCluster.KubeClient.Create(ctx, workspaceObj, &client.CreateOptions{}) + }, utils.PollTimeout, utils.PollInterval). + Should(HaveOccurred(), "Failed to create workspace %s", workspaceObj.Name) + }) }) - }) - It("should validate the workspace tuning spec at creation ", func() { - workspaceObj := utils.GenerateTuningWorkspaceManifest(fmt.Sprint("webhook-", rand.Intn(1000)), namespaceName, "", 1, "Standard_NC12s_v3", - &metav1.LabelSelector{ - MatchLabels: map[string]string{"kaito-workspace": "webhook-e2e-test"}, - }, nil, nil, testDataDestinationConfig, initialPresetSpec, initialTuningMethod) - - By("Creating a workspace with nil input", func() { - // Create workspace - Eventually(func() error { - return TestingCluster.KubeClient.Create(ctx, workspaceObj, &client.CreateOptions{}) - }, 20*time.Minute, utils.PollInterval). - Should(HaveOccurred(), "Failed to create workspace %s", workspaceObj.Name) + It("should validate the workspace tuning spec at creation ", func() { + workspaceObj := utils.GenerateTuningWorkspaceManifest(fmt.Sprint("webhook-", rand.Intn(1000)), namespaceName, "", 1, "Standard_NC12s_v3", + &metav1.LabelSelector{ + MatchLabels: map[string]string{"kaito-workspace": "webhook-e2e-test"}, + }, nil, nil, testDataDestinationConfig, initialPresetSpec, initialTuningMethod) + + By("Creating a workspace with nil input", func() { + // Create workspace + Eventually(func() error { + return TestingCluster.KubeClient.Create(ctx, workspaceObj, &client.CreateOptions{}) + }, 20*time.Minute, utils.PollInterval). + Should(HaveOccurred(), "Failed to create workspace %s", workspaceObj.Name) + }) }) - }) - It("should validate the workspace tuning spec at creation ", func() { - workspaceObj := utils.GenerateTuningWorkspaceManifest(fmt.Sprint("webhook-", rand.Intn(1000)), namespaceName, "", 1, "Standard_NC12s_v3", - &metav1.LabelSelector{ - MatchLabels: map[string]string{"kaito-workspace": "webhook-e2e-test"}, - }, nil, testDataSourceConfig, nil, initialPresetSpec, initialTuningMethod) - - By("Creating a workspace with nil output", func() { - // Create workspace - Eventually(func() error { - return TestingCluster.KubeClient.Create(ctx, workspaceObj, &client.CreateOptions{}) - }, 20*time.Minute, utils.PollInterval). - Should(HaveOccurred(), "Failed to create workspace %s", workspaceObj.Name) + It("should validate the workspace tuning spec at creation ", func() { + workspaceObj := utils.GenerateTuningWorkspaceManifest(fmt.Sprint("webhook-", rand.Intn(1000)), namespaceName, "", 1, "Standard_NC12s_v3", + &metav1.LabelSelector{ + MatchLabels: map[string]string{"kaito-workspace": "webhook-e2e-test"}, + }, nil, testDataSourceConfig, nil, initialPresetSpec, initialTuningMethod) + + By("Creating a workspace with nil output", func() { + // Create workspace + Eventually(func() error { + return TestingCluster.KubeClient.Create(ctx, workspaceObj, &client.CreateOptions{}) + }, 20*time.Minute, utils.PollInterval). + Should(HaveOccurred(), "Failed to create workspace %s", workspaceObj.Name) + }) }) - }) - It("should validate the workspace tuning spec at creation ", func() { - workspaceObj := utils.GenerateTuningWorkspaceManifest(fmt.Sprint("webhook-", rand.Intn(1000)), namespaceName, "", 1, "Standard_NC12s_v3", - &metav1.LabelSelector{ - MatchLabels: map[string]string{"kaito-workspace": "webhook-e2e-test"}, - }, nil, testDataSourceConfig, testDataDestinationConfig, nil, initialTuningMethod) - - By("Creating a workspace with nil preset", func() { - // Create workspace - Eventually(func() error { - return TestingCluster.KubeClient.Create(ctx, workspaceObj, &client.CreateOptions{}) - }, 20*time.Minute, utils.PollInterval). - Should(HaveOccurred(), "Failed to create workspace %s", workspaceObj.Name) - }) - }) - - //TODO preset private mode - //TODO custom template - - It("should validate the workspace resource spec at update ", func() { - workspaceObj := utils.GenerateInferenceWorkspaceManifest(fmt.Sprint("webhook-", rand.Intn(1000)), namespaceName, "", 1, "Standard_NC12s_v3", - &metav1.LabelSelector{ - MatchLabels: map[string]string{"kaito-workspace": "webhook-e2e-test"}, - }, nil, PresetFalcon7BModel, kaitov1alpha1.ModelImageAccessModePublic, nil, nil, nil) - - By("Creating a valid workspace", func() { - // Create workspace - Eventually(func() error { - return TestingCluster.KubeClient.Create(ctx, workspaceObj, &client.CreateOptions{}) - }, 20*time.Minute, utils.PollInterval). - Should(Succeed(), "Failed to create workspace %s", workspaceObj.Name) - }) - - By("Updating the label selector", func() { - updatedObj := workspaceObj - updatedObj.Resource.LabelSelector = &metav1.LabelSelector{} - // update workspace - Eventually(func() error { - return TestingCluster.KubeClient.Update(ctx, updatedObj, &client.UpdateOptions{}) - }, utils.PollTimeout, utils.PollInterval). - Should(HaveOccurred(), "Failed to update workspace %s", updatedObj.Name) - }) - - By("Updating the InstanceType", func() { - updatedObj := workspaceObj - updatedObj.Resource.InstanceType = "Standard_NC12" - // update workspace - Eventually(func() error { - return TestingCluster.KubeClient.Update(ctx, updatedObj, &client.UpdateOptions{}) - }, utils.PollTimeout, utils.PollInterval). - Should(HaveOccurred(), "Failed to update workspace %s", updatedObj.Name) + It("should validate the workspace tuning spec at creation ", func() { + workspaceObj := utils.GenerateTuningWorkspaceManifest(fmt.Sprint("webhook-", rand.Intn(1000)), namespaceName, "", 1, "Standard_NC12s_v3", + &metav1.LabelSelector{ + MatchLabels: map[string]string{"kaito-workspace": "webhook-e2e-test"}, + }, nil, testDataSourceConfig, testDataDestinationConfig, nil, initialTuningMethod) + + By("Creating a workspace with nil preset", func() { + // Create workspace + Eventually(func() error { + return TestingCluster.KubeClient.Create(ctx, workspaceObj, &client.CreateOptions{}) + }, 20*time.Minute, utils.PollInterval). + Should(HaveOccurred(), "Failed to create workspace %s", workspaceObj.Name) + }) }) + //TODO preset private mode //TODO custom template - // delete workspace - Eventually(func() error { - return TestingCluster.KubeClient.Delete(ctx, workspaceObj, &client.DeleteOptions{}) - }, utils.PollTimeout, utils.PollInterval).Should(Succeed(), "Failed to delete workspace") - - }) - - It("should validate the workspace tuning spec at update ", func() { - workspaceObj := utils.GenerateTuningWorkspaceManifest(fmt.Sprint("webhook-", rand.Intn(1000)), namespaceName, "", 1, "Standard_NC12s_v3", - &metav1.LabelSelector{ - MatchLabels: map[string]string{"kaito-workspace": "webhook-e2e-test"}, - }, nil, testDataSourceConfig, testDataDestinationConfig, initialPresetSpec, initialTuningMethod) - - By("Creating a valid tuning workspace", func() { - // Create workspace + It("should validate the workspace resource spec at update ", func() { + workspaceObj := utils.GenerateInferenceWorkspaceManifest(fmt.Sprint("webhook-", rand.Intn(1000)), namespaceName, "", 1, "Standard_NC12s_v3", + &metav1.LabelSelector{ + MatchLabels: map[string]string{"kaito-workspace": "webhook-e2e-test"}, + }, nil, PresetFalcon7BModel, kaitov1alpha1.ModelImageAccessModePublic, nil, nil, nil) + + By("Creating a valid workspace", func() { + // Create workspace + Eventually(func() error { + return TestingCluster.KubeClient.Create(ctx, workspaceObj, &client.CreateOptions{}) + }, 20*time.Minute, utils.PollInterval). + Should(Succeed(), "Failed to create workspace %s", workspaceObj.Name) + }) + + By("Updating the label selector", func() { + updatedObj := workspaceObj + updatedObj.Resource.LabelSelector = &metav1.LabelSelector{} + // update workspace + Eventually(func() error { + return TestingCluster.KubeClient.Update(ctx, updatedObj, &client.UpdateOptions{}) + }, utils.PollTimeout, utils.PollInterval). + Should(HaveOccurred(), "Failed to update workspace %s", updatedObj.Name) + }) + + By("Updating the InstanceType", func() { + updatedObj := workspaceObj + updatedObj.Resource.InstanceType = "Standard_NC12" + // update workspace + Eventually(func() error { + return TestingCluster.KubeClient.Update(ctx, updatedObj, &client.UpdateOptions{}) + }, utils.PollTimeout, utils.PollInterval). + Should(HaveOccurred(), "Failed to update workspace %s", updatedObj.Name) + }) + + //TODO custom template + + // delete workspace Eventually(func() error { - return TestingCluster.KubeClient.Create(ctx, workspaceObj, &client.CreateOptions{}) - }, 20*time.Minute, utils.PollInterval). - Should(Succeed(), "Failed to create workspace %s", workspaceObj.Name) - }) + return TestingCluster.KubeClient.Delete(ctx, workspaceObj, &client.DeleteOptions{}) + }, utils.PollTimeout, utils.PollInterval).Should(Succeed(), "Failed to delete workspace") - By("Updating the tuning preset", func() { - updatedObj := workspaceObj - updatedObj.Tuning.Preset = updatedPresetSpec - // update workspace - Eventually(func() error { - return TestingCluster.KubeClient.Update(ctx, updatedObj, &client.UpdateOptions{}) - }, utils.PollTimeout, utils.PollInterval). - Should(HaveOccurred(), "Failed to update workspace %s", updatedObj.Name) }) - By("Updating the Method", func() { - updatedObj := workspaceObj - updatedObj.Tuning.Method = alternativeTuningMethod - // update workspace + It("should validate the workspace tuning spec at update ", func() { + workspaceObj := utils.GenerateTuningWorkspaceManifest(fmt.Sprint("webhook-", rand.Intn(1000)), namespaceName, "", 1, "Standard_NC12s_v3", + &metav1.LabelSelector{ + MatchLabels: map[string]string{"kaito-workspace": "webhook-e2e-test"}, + }, nil, testDataSourceConfig, testDataDestinationConfig, initialPresetSpec, initialTuningMethod) + + By("Creating a valid tuning workspace", func() { + // Create workspace + Eventually(func() error { + return TestingCluster.KubeClient.Create(ctx, workspaceObj, &client.CreateOptions{}) + }, 20*time.Minute, utils.PollInterval). + Should(Succeed(), "Failed to create workspace %s", workspaceObj.Name) + }) + + By("Updating the tuning preset", func() { + updatedObj := workspaceObj + updatedObj.Tuning.Preset = updatedPresetSpec + // update workspace + Eventually(func() error { + return TestingCluster.KubeClient.Update(ctx, updatedObj, &client.UpdateOptions{}) + }, utils.PollTimeout, utils.PollInterval). + Should(HaveOccurred(), "Failed to update workspace %s", updatedObj.Name) + }) + + By("Updating the Method", func() { + updatedObj := workspaceObj + updatedObj.Tuning.Method = alternativeTuningMethod + // update workspace + Eventually(func() error { + return TestingCluster.KubeClient.Update(ctx, updatedObj, &client.UpdateOptions{}) + }, utils.PollTimeout, utils.PollInterval). + Should(HaveOccurred(), "Failed to update workspace %s", updatedObj.Name) + }) + + // delete workspace Eventually(func() error { - return TestingCluster.KubeClient.Update(ctx, updatedObj, &client.UpdateOptions{}) - }, utils.PollTimeout, utils.PollInterval). - Should(HaveOccurred(), "Failed to update workspace %s", updatedObj.Name) - }) + return TestingCluster.KubeClient.Delete(ctx, workspaceObj, &client.DeleteOptions{}) + }, utils.PollTimeout, utils.PollInterval).Should(Succeed(), "Failed to delete workspace") - // delete workspace - Eventually(func() error { - return TestingCluster.KubeClient.Delete(ctx, workspaceObj, &client.DeleteOptions{}) - }, utils.PollTimeout, utils.PollInterval).Should(Succeed(), "Failed to delete workspace") - - }) + }) + */ It("should validate the workspace inference spec at update ", func() { workspaceObj := utils.GenerateInferenceWorkspaceManifest(fmt.Sprint("webhook-", rand.Intn(1000)), namespaceName, "", 1, "Standard_NC12s_v3",