Skip to content

Commit 0b56ac8

Browse files
committed
[history server][e2e] Remove duplicate test support functions
Refactor ApplyHistoryServer to accept an optional manifest path parameter, eliminating the need for a separate ApplyAzureHistoryServer function. Remove PrepareAzureHistoryServerTestEnv as it was identical to PrepareAzureBlobTestEnv.
1 parent 62e9f86 commit 0b56ac8

File tree

4 files changed

+12
-66
lines changed

4 files changed

+12
-66
lines changed

historyserver/test/e2e/historyserver_azureblob_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@ func TestAzureHistoryServer(t *testing.T) {
3636
}
3737

3838
func testAzureLiveClusters(test Test, g *WithT, namespace *corev1.Namespace, azureClient *azblob.Client) {
39-
rayCluster := PrepareAzureHistoryServerTestEnv(test, g, namespace, azureClient)
39+
rayCluster := PrepareAzureBlobTestEnv(test, g, namespace, azureClient)
4040
ApplyRayJobAndWaitForCompletion(test, g, namespace, rayCluster)
41-
ApplyAzureHistoryServer(test, g, namespace)
41+
ApplyHistoryServer(test, g, namespace, AzureHistoryServerManifestPath)
4242
historyServerURL := GetHistoryServerURL(test, g, namespace)
4343

4444
clusterInfo := getClusterFromList(test, g, historyServerURL, rayCluster.Name, namespace.Name)

historyserver/test/e2e/historyserver_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ func TestHistoryServer(t *testing.T) {
4646
func testLiveClusters(test Test, g *WithT, namespace *corev1.Namespace, s3Client *s3.S3) {
4747
rayCluster := PrepareTestEnv(test, g, namespace, s3Client)
4848
ApplyRayJobAndWaitForCompletion(test, g, namespace, rayCluster)
49-
ApplyHistoryServer(test, g, namespace)
49+
ApplyHistoryServer(test, g, namespace, "")
5050
historyServerURL := GetHistoryServerURL(test, g, namespace)
5151

5252
clusterInfo := getClusterFromList(test, g, historyServerURL, rayCluster.Name, namespace.Name)

historyserver/test/support/azureblob.go

Lines changed: 0 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88
"github.com/Azure/azure-sdk-for-go/sdk/storage/azblob"
99
. "github.com/onsi/gomega"
1010
corev1 "k8s.io/api/core/v1"
11-
k8serrors "k8s.io/apimachinery/pkg/api/errors"
1211
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1312

1413
rayv1 "github.com/ray-project/kuberay/ray-operator/apis/ray/v1"
@@ -157,58 +156,3 @@ func ApplyAzureRayClusterWithCollector(test Test, g *WithT, namespace *corev1.Na
157156
return rayCluster
158157
}
159158

160-
// ApplyAzureHistoryServer deploys the HistoryServer configured for Azure Blob Storage.
161-
func ApplyAzureHistoryServer(test Test, g *WithT, namespace *corev1.Namespace) {
162-
sa, clusterRole, clusterRoleBinding := DeserializeRBACFromYAML(test, ServiceAccountManifestPath)
163-
sa.Namespace = namespace.Name
164-
clusterRoleBinding.Name = fmt.Sprintf("historyserver-%s", namespace.Name)
165-
clusterRoleBinding.Subjects[0].Namespace = namespace.Name
166-
167-
_, err := test.Client().Core().CoreV1().ServiceAccounts(namespace.Name).Create(test.Ctx(), sa, metav1.CreateOptions{})
168-
g.Expect(err).NotTo(HaveOccurred())
169-
170-
_, err = test.Client().Core().RbacV1().ClusterRoles().Create(test.Ctx(), clusterRole, metav1.CreateOptions{})
171-
if err != nil && !k8serrors.IsAlreadyExists(err) {
172-
g.Expect(err).NotTo(HaveOccurred())
173-
}
174-
175-
_, err = test.Client().Core().RbacV1().ClusterRoleBindings().Create(test.Ctx(), clusterRoleBinding, metav1.CreateOptions{})
176-
g.Expect(err).NotTo(HaveOccurred())
177-
178-
test.T().Cleanup(func() {
179-
_ = test.Client().Core().RbacV1().ClusterRoleBindings().Delete(
180-
context.Background(), clusterRoleBinding.Name, metav1.DeleteOptions{})
181-
})
182-
183-
KubectlApplyYAML(test, AzureHistoryServerManifestPath, namespace.Name)
184-
185-
LogWithTimestamp(test.T(), "Waiting for Azure HistoryServer to be ready")
186-
g.Eventually(func(gg Gomega) {
187-
pods, err := test.Client().Core().CoreV1().Pods(namespace.Name).List(
188-
test.Ctx(), metav1.ListOptions{
189-
LabelSelector: "app=historyserver",
190-
},
191-
)
192-
gg.Expect(err).NotTo(HaveOccurred())
193-
gg.Expect(pods.Items).NotTo(BeEmpty())
194-
gg.Expect(AllPodsRunningAndReady(pods.Items)).To(BeTrue())
195-
}, TestTimeoutMedium).Should(Succeed())
196-
LogWithTimestamp(test.T(), "Azure HistoryServer is ready")
197-
}
198-
199-
// PrepareAzureHistoryServerTestEnv prepares test environment for Azure History Server tests.
200-
func PrepareAzureHistoryServerTestEnv(test Test, g *WithT, namespace *corev1.Namespace, azureClient *azblob.Client) *rayv1.RayCluster {
201-
rayCluster := ApplyAzureRayClusterWithCollector(test, g, namespace)
202-
203-
headPod, err := GetHeadPod(test, rayCluster)
204-
g.Expect(err).NotTo(HaveOccurred())
205-
g.Expect(headPod.Spec.Containers).To(ContainElement(
206-
WithTransform(func(c corev1.Container) string { return c.Name }, Equal("collector")),
207-
))
208-
209-
containerClient := azureClient.ServiceClient().NewContainerClient(AzureContainerName)
210-
_, err = containerClient.GetProperties(context.Background(), nil)
211-
g.Expect(err).NotTo(HaveOccurred())
212-
213-
return rayCluster
214-
}

historyserver/test/support/historyserver.go

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,32 +49,34 @@ var HistoryServerEndpoints = []string{
4949
}
5050

5151
// ApplyHistoryServer deploys the HistoryServer and RBAC resources.
52-
func ApplyHistoryServer(test Test, g *WithT, namespace *corev1.Namespace) {
53-
// Read RBAC resources from YAML and modify namespace fields.
52+
// If manifestPath is empty, the default HistoryServerManifestPath is used.
53+
func ApplyHistoryServer(test Test, g *WithT, namespace *corev1.Namespace, manifestPath string) {
54+
if manifestPath == "" {
55+
manifestPath = HistoryServerManifestPath
56+
}
57+
5458
sa, clusterRole, clusterRoleBinding := DeserializeRBACFromYAML(test, ServiceAccountManifestPath)
5559
sa.Namespace = namespace.Name
5660
clusterRoleBinding.Name = fmt.Sprintf("historyserver-%s", namespace.Name)
5761
clusterRoleBinding.Subjects[0].Namespace = namespace.Name
5862

59-
// Create RBAC resources
6063
_, err := test.Client().Core().CoreV1().ServiceAccounts(namespace.Name).Create(test.Ctx(), sa, metav1.CreateOptions{})
6164
g.Expect(err).NotTo(HaveOccurred())
62-
// ClusterRole is shared across tests, ignore if already exists.
65+
6366
_, err = test.Client().Core().RbacV1().ClusterRoles().Create(test.Ctx(), clusterRole, metav1.CreateOptions{})
6467
if err != nil && !k8serrors.IsAlreadyExists(err) {
6568
g.Expect(err).NotTo(HaveOccurred())
6669
}
70+
6771
_, err = test.Client().Core().RbacV1().ClusterRoleBindings().Create(test.Ctx(), clusterRoleBinding, metav1.CreateOptions{})
6872
g.Expect(err).NotTo(HaveOccurred())
6973

70-
// ClusterRoleBinding is cluster-scoped and won't be deleted when the namespace is cleaned up.
71-
// Register cleanup to prevent accumulation across test runs.
7274
test.T().Cleanup(func() {
7375
_ = test.Client().Core().RbacV1().ClusterRoleBindings().Delete(
7476
context.Background(), clusterRoleBinding.Name, metav1.DeleteOptions{})
7577
})
7678

77-
KubectlApplyYAML(test, HistoryServerManifestPath, namespace.Name)
79+
KubectlApplyYAML(test, manifestPath, namespace.Name)
7880

7981
LogWithTimestamp(test.T(), "Waiting for HistoryServer to be ready")
8082
g.Eventually(func(gg Gomega) {

0 commit comments

Comments
 (0)