|
| 1 | +package kfto |
| 2 | + |
| 3 | +import ( |
| 4 | + "context" |
| 5 | + "strings" |
| 6 | + "testing" |
| 7 | + "time" |
| 8 | + |
| 9 | + . "github.com/onsi/gomega" |
| 10 | + |
| 11 | + appsv1 "k8s.io/api/apps/v1" |
| 12 | + corev1 "k8s.io/api/core/v1" |
| 13 | + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" |
| 14 | + |
| 15 | + openshiftclient "github.com/openshift/client-go/config/clientset/versioned" |
| 16 | + |
| 17 | + . "github.com/opendatahub-io/distributed-workloads/tests/common" |
| 18 | + . "github.com/opendatahub-io/distributed-workloads/tests/common/support" |
| 19 | +) |
| 20 | + |
| 21 | +func TestKftoSmoke(t *testing.T) { |
| 22 | + Tags(t, Smoke) |
| 23 | + runSmoke(t, "kubeflow-training-operator", "odh-training-operator") |
| 24 | +} |
| 25 | + |
| 26 | +// runSmoke runs a smoke test for a given deployment and expected image name. |
| 27 | +func runSmoke(t *testing.T, deploymentName string, expectedImage string) { |
| 28 | + test := With(t) |
| 29 | + namespace := GetOpenDataHubNamespace(test) |
| 30 | + |
| 31 | + test.T().Logf("Waiting for %s deployment to be available ...", deploymentName) |
| 32 | + test.Eventually(func(g Gomega, ctx context.Context) { |
| 33 | + deployment, err := test.Client().Core().AppsV1().Deployments(namespace).Get( |
| 34 | + ctx, deploymentName, metav1.GetOptions{}) |
| 35 | + g.Expect(err).NotTo(HaveOccurred()) |
| 36 | + |
| 37 | + status := ConditionStatus(appsv1.DeploymentAvailable)(deployment) |
| 38 | + g.Expect(status).To(Equal(corev1.ConditionTrue), "deployment %s not available", deploymentName) |
| 39 | + }, 5*time.Minute, 5*time.Second).WithContext(test.Ctx()).Should(Succeed()) |
| 40 | + |
| 41 | + test.T().Logf("%s deployment is available", deploymentName) |
| 42 | + |
| 43 | + // Determine registry based on cluster environment |
| 44 | + configClient, err := openshiftclient.NewForConfig(test.Config()) |
| 45 | + test.Expect(err).NotTo(HaveOccurred()) |
| 46 | + |
| 47 | + infra, err := configClient.ConfigV1().Infrastructures().Get(test.Ctx(), "cluster", metav1.GetOptions{}) |
| 48 | + test.Expect(err).NotTo(HaveOccurred()) |
| 49 | + |
| 50 | + envType := infra.Labels["hypershift.openshift.io/managed"] |
| 51 | + registryName := "registry.redhat.io" |
| 52 | + if envType == "true" { |
| 53 | + registryName = "quay.io" |
| 54 | + } |
| 55 | + |
| 56 | + test.T().Logf("Verifying %s container image is referred from expected registry ...", deploymentName) |
| 57 | + |
| 58 | + // List all running pods in the namespace |
| 59 | + podList := GetPods(test, namespace, metav1.ListOptions{ |
| 60 | + FieldSelector: "status.phase=Running", |
| 61 | + }) |
| 62 | + |
| 63 | + // Filter pods whose name starts with the prefix - deployment Name |
| 64 | + var matchedPods []corev1.Pod |
| 65 | + for _, pod := range podList { |
| 66 | + if strings.HasPrefix(pod.Name, deploymentName+"-") { |
| 67 | + matchedPods = append(matchedPods, pod) |
| 68 | + } |
| 69 | + } |
| 70 | + |
| 71 | + if len(matchedPods) != 1 { |
| 72 | + var podNames []string |
| 73 | + for _, pod := range matchedPods { |
| 74 | + podNames = append(podNames, pod.Name) |
| 75 | + } |
| 76 | + test.T().Logf("Found pods matching prefix '%s-': %v", deploymentName, podNames) |
| 77 | + test.T().Errorf("Expected exactly one pod, found %d", len(matchedPods)) |
| 78 | + test.T().FailNow() |
| 79 | + } |
| 80 | + |
| 81 | + containerImage := matchedPods[0].Spec.Containers[0].Image |
| 82 | + test.Expect(containerImage).To(ContainSubstring(registryName + "/rhoai/" + expectedImage)) |
| 83 | + test.T().Logf("%s container image is referred from %s", deploymentName, registryName) |
| 84 | +} |
0 commit comments