Skip to content

Commit

Permalink
Add adapter logs for Inference API and validate adapters in e2e test
Browse files Browse the repository at this point in the history
Signed-off-by: Bangqi Zhu <bangqizhu@microsoft.com>
  • Loading branch information
Bangqi Zhu committed Aug 23, 2024
1 parent 5c30038 commit 1c4122e
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 3 deletions.
39 changes: 36 additions & 3 deletions test/e2e/inference_with_adapters_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
package e2e

import (
"fmt"
"strings"
"time"

kaitov1alpha1 "github.com/azure/kaito/api/v1alpha1"
Expand Down Expand Up @@ -38,8 +40,8 @@ var expectedInitContainers = []corev1.Container{
},
}

func validateAdapters(workspaceObj *kaitov1alpha1.Workspace, expectedInitContainers []corev1.Container) {
By("Checking the Adapters", func() {
func validateInitContainers(workspaceObj *kaitov1alpha1.Workspace, expectedInitContainers []corev1.Container) {
By("Checking the InitContainers", func() {
Eventually(func() bool {
var err error
var initContainers []corev1.Container
Expand Down Expand Up @@ -68,6 +70,36 @@ func validateAdapters(workspaceObj *kaitov1alpha1.Workspace, expectedInitContain

// GinkgoWriter.Printf("Resource '%s' not ready. Ready replicas: %d\n", workspaceObj.Name, readyReplicas)
return initContainer.Image == expectedInitContainer.Image && initContainer.Name == expectedInitContainer.Name
}, 20*time.Minute, utils.PollInterval).Should(BeTrue(), "Failed to wait for initContainers to be ready")
})
}

func validateAdapterAdded(workspaceObj *kaitov1alpha1.Workspace, deploymentName string, adapterName string) {
By("Checking the Adapters", func() {
Eventually(func() bool {
coreClient, err := utils.GetK8sConfig()
if err != nil {
GinkgoWriter.Printf("Failed to create core client: %v\n", err)
return false
}

namespace := workspaceObj.Namespace
podName, err := utils.GetPodNameForDeployment(coreClient, namespace, deploymentName)
if err != nil {
GinkgoWriter.Printf("Failed to get pod name for deployment %s: %v\n", deploymentName, err)
return false
}

logs, err := utils.GetPodLogs(coreClient, namespace, podName, "")
if err != nil {
GinkgoWriter.Printf("Failed to get logs from pod %s: %v\n", podName, err)
return false
}

searchStringAdapter := fmt.Sprintf("Adapter added: %s", adapterName)
searchStringModelSuccess := "Model loaded successfully"

return strings.Contains(logs, searchStringAdapter) && strings.Contains(logs, searchStringModelSuccess)
}, 20*time.Minute, utils.PollInterval).Should(BeTrue(), "Failed to wait for adapter resource to be ready")
})
}
Expand Down Expand Up @@ -110,7 +142,8 @@ var _ = Describe("Workspace Preset", func() {

validateWorkspaceReadiness(workspaceObj)

validateAdapters(workspaceObj, expectedInitContainers)
validateInitContainers(workspaceObj, expectedInitContainers)
validateAdapterAdded(workspaceObj, workspaceObj.Name, imageName)
})

})
15 changes: 15 additions & 0 deletions test/e2e/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,21 @@ func GetPodNameForJob(coreClient *kubernetes.Clientset, namespace, jobName strin
return podList.Items[0].Name, nil
}

func GetPodNameForDeployment(coreClient *kubernetes.Clientset, namespace, deploymentName string) (string, error) {
podList, err := coreClient.CoreV1().Pods(namespace).List(context.TODO(), metav1.ListOptions{
LabelSelector: fmt.Sprintf("kaito.sh/workspace=%s", deploymentName),
})
if err != nil {
return "", err
}

if len(podList.Items) == 0 {
return "", fmt.Errorf("no pods found for job %s", deploymentName)
}

return podList.Items[0].Name, nil
}

func GetK8sConfig() (*kubernetes.Clientset, error) {
var config *rest.Config
var err error
Expand Down

0 comments on commit 1c4122e

Please sign in to comment.