Skip to content

Commit 042fb17

Browse files
committed
Add common functions for SDK test
1 parent 5463537 commit 042fb17

File tree

4 files changed

+96
-2
lines changed

4 files changed

+96
-2
lines changed

support/core.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,3 +164,23 @@ func CreatePersistentVolumeClaim(t Test, namespace string, storageSize string, a
164164

165165
return pvc
166166
}
167+
168+
func GetNodes(t Test) []corev1.Node {
169+
t.T().Helper()
170+
nodes, err := t.Client().Core().CoreV1().Nodes().List(t.Ctx(), metav1.ListOptions{})
171+
t.Expect(err).NotTo(gomega.HaveOccurred())
172+
return nodes.Items
173+
}
174+
175+
func GetNodeInternalIP(t Test, node corev1.Node) (IP string) {
176+
t.T().Helper()
177+
178+
for _, address := range node.Status.Addresses {
179+
if address.Type == "InternalIP" {
180+
IP = address.Address
181+
}
182+
}
183+
t.Expect(IP).Should(gomega.Not(gomega.BeEmpty()), "Node internal IP address not found")
184+
185+
return
186+
}

support/defaults.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ package support
55
// ***********************
66

77
const (
8-
CodeFlareSDKVersion = "0.9.0"
8+
CodeFlareSDKVersion = "0.12.0"
99
RayVersion = "2.5.0"
10-
RayImage = "rayproject/ray:2.5.0"
10+
RayImage = "quay.io/project-codeflare/ray:latest-py39-cu118"
1111
)

support/environment.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ const (
4141

4242
// Type of cluster test is run on
4343
ClusterTypeEnvVar = "CLUSTER_TYPE"
44+
45+
// Hostname of the Kubernetes cluster
46+
ClusterHostname = "CLUSTER_HOSTNAME"
4447
)
4548

4649
type ClusterType string
@@ -49,6 +52,7 @@ const (
4952
OsdCluster ClusterType = "OSD"
5053
OcpCluster ClusterType = "OCP"
5154
HypershiftCluster ClusterType = "HYPERSHIFT"
55+
KindCluster ClusterType = "KIND"
5256
UndefinedCluster ClusterType = "UNDEFINED"
5357
)
5458

@@ -90,12 +94,22 @@ func GetClusterType(t Test) ClusterType {
9094
return OcpCluster
9195
case "HYPERSHIFT":
9296
return HypershiftCluster
97+
case "KIND":
98+
return KindCluster
9399
default:
94100
t.T().Logf("Expected environment variable %s contains unexpected value: '%s'", ClusterTypeEnvVar, clusterType)
95101
return UndefinedCluster
96102
}
97103
}
98104

105+
func GetClusterHostname(t Test) string {
106+
hostname, ok := os.LookupEnv(ClusterHostname)
107+
if !ok {
108+
t.T().Fatalf("Expected environment variable %s not found, please define cluster hostname.", ClusterHostname)
109+
}
110+
return hostname
111+
}
112+
99113
func lookupEnvOrDefault(key, value string) string {
100114
if v, ok := os.LookupEnv(key); ok {
101115
return v

support/rbac.go

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,30 @@ func CreateRole(t Test, namespace string, policyRules []rbacv1.PolicyRule) *rbac
4545
return role
4646
}
4747

48+
func CreateClusterRole(t Test, policyRules []rbacv1.PolicyRule) *rbacv1.ClusterRole {
49+
t.T().Helper()
50+
51+
role := &rbacv1.ClusterRole{
52+
TypeMeta: metav1.TypeMeta{
53+
APIVersion: rbacv1.SchemeGroupVersion.String(),
54+
Kind: "ClusterRole",
55+
},
56+
ObjectMeta: metav1.ObjectMeta{
57+
GenerateName: "clusterrole-",
58+
},
59+
Rules: policyRules,
60+
}
61+
role, err := t.Client().Core().RbacV1().ClusterRoles().Create(t.Ctx(), role, metav1.CreateOptions{})
62+
t.Expect(err).NotTo(gomega.HaveOccurred())
63+
t.T().Logf("Created ClusterRole %s/%s successfully", role.Namespace, role.Name)
64+
65+
t.T().Cleanup(func() {
66+
t.Client().Core().RbacV1().ClusterRoles().Delete(t.Ctx(), role.Name, metav1.DeleteOptions{})
67+
})
68+
69+
return role
70+
}
71+
4872
func CreateRoleBinding(t Test, namespace string, serviceAccount *corev1.ServiceAccount, role *rbacv1.Role) *rbacv1.RoleBinding {
4973
t.T().Helper()
5074

@@ -76,3 +100,39 @@ func CreateRoleBinding(t Test, namespace string, serviceAccount *corev1.ServiceA
76100

77101
return rb
78102
}
103+
104+
func CreateClusterRoleBinding(t Test, serviceAccount *corev1.ServiceAccount, role *rbacv1.ClusterRole) *rbacv1.ClusterRoleBinding {
105+
t.T().Helper()
106+
107+
roleBinding := &rbacv1.ClusterRoleBinding{
108+
TypeMeta: metav1.TypeMeta{
109+
APIVersion: rbacv1.SchemeGroupVersion.String(),
110+
Kind: "ClusterRoleBinding",
111+
},
112+
ObjectMeta: metav1.ObjectMeta{
113+
GenerateName: "crb-",
114+
},
115+
RoleRef: rbacv1.RoleRef{
116+
APIGroup: rbacv1.SchemeGroupVersion.Group,
117+
Kind: "ClusterRole",
118+
Name: role.Name,
119+
},
120+
Subjects: []rbacv1.Subject{
121+
{
122+
Kind: "ServiceAccount",
123+
APIGroup: corev1.SchemeGroupVersion.Group,
124+
Name: serviceAccount.Name,
125+
Namespace: serviceAccount.Namespace,
126+
},
127+
},
128+
}
129+
rb, err := t.Client().Core().RbacV1().ClusterRoleBindings().Create(t.Ctx(), roleBinding, metav1.CreateOptions{})
130+
t.Expect(err).NotTo(gomega.HaveOccurred())
131+
t.T().Logf("Created ClusterRoleBinding %s/%s successfully", role.Namespace, role.Name)
132+
133+
t.T().Cleanup(func() {
134+
t.Client().Core().RbacV1().ClusterRoleBindings().Delete(t.Ctx(), rb.Name, metav1.DeleteOptions{})
135+
})
136+
137+
return rb
138+
}

0 commit comments

Comments
 (0)