diff --git a/support/core.go b/support/core.go index 54f25e2..7884488 100644 --- a/support/core.go +++ b/support/core.go @@ -164,3 +164,23 @@ func CreatePersistentVolumeClaim(t Test, namespace string, storageSize string, a return pvc } + +func GetNodes(t Test) []corev1.Node { + t.T().Helper() + nodes, err := t.Client().Core().CoreV1().Nodes().List(t.Ctx(), metav1.ListOptions{}) + t.Expect(err).NotTo(gomega.HaveOccurred()) + return nodes.Items +} + +func GetNodeInternalIP(t Test, node corev1.Node) (IP string) { + t.T().Helper() + + for _, address := range node.Status.Addresses { + if address.Type == "InternalIP" { + IP = address.Address + } + } + t.Expect(IP).Should(gomega.Not(gomega.BeEmpty()), "Node internal IP address not found") + + return +} diff --git a/support/defaults.go b/support/defaults.go index 1beb7e8..f43d4bc 100644 --- a/support/defaults.go +++ b/support/defaults.go @@ -5,7 +5,7 @@ package support // *********************** const ( - CodeFlareSDKVersion = "0.9.0" + CodeFlareSDKVersion = "0.12.0" RayVersion = "2.5.0" - RayImage = "rayproject/ray:2.5.0" + RayImage = "quay.io/project-codeflare/ray:latest-py39-cu118" ) diff --git a/support/environment.go b/support/environment.go index 7d8e6bc..10418f8 100644 --- a/support/environment.go +++ b/support/environment.go @@ -41,6 +41,9 @@ const ( // Type of cluster test is run on ClusterTypeEnvVar = "CLUSTER_TYPE" + + // Hostname of the Kubernetes cluster + ClusterHostname = "CLUSTER_HOSTNAME" ) type ClusterType string @@ -49,6 +52,7 @@ const ( OsdCluster ClusterType = "OSD" OcpCluster ClusterType = "OCP" HypershiftCluster ClusterType = "HYPERSHIFT" + KindCluster ClusterType = "KIND" UndefinedCluster ClusterType = "UNDEFINED" ) @@ -90,12 +94,22 @@ func GetClusterType(t Test) ClusterType { return OcpCluster case "HYPERSHIFT": return HypershiftCluster + case "KIND": + return KindCluster default: t.T().Logf("Expected environment variable %s contains unexpected value: '%s'", ClusterTypeEnvVar, clusterType) return UndefinedCluster } } +func GetClusterHostname(t Test) string { + hostname, ok := os.LookupEnv(ClusterHostname) + if !ok { + t.T().Fatalf("Expected environment variable %s not found, please define cluster hostname.", ClusterHostname) + } + return hostname +} + func lookupEnvOrDefault(key, value string) string { if v, ok := os.LookupEnv(key); ok { return v diff --git a/support/rbac.go b/support/rbac.go index 0963329..2e2aaad 100644 --- a/support/rbac.go +++ b/support/rbac.go @@ -45,6 +45,30 @@ func CreateRole(t Test, namespace string, policyRules []rbacv1.PolicyRule) *rbac return role } +func CreateClusterRole(t Test, policyRules []rbacv1.PolicyRule) *rbacv1.ClusterRole { + t.T().Helper() + + role := &rbacv1.ClusterRole{ + TypeMeta: metav1.TypeMeta{ + APIVersion: rbacv1.SchemeGroupVersion.String(), + Kind: "ClusterRole", + }, + ObjectMeta: metav1.ObjectMeta{ + GenerateName: "clusterrole-", + }, + Rules: policyRules, + } + role, err := t.Client().Core().RbacV1().ClusterRoles().Create(t.Ctx(), role, metav1.CreateOptions{}) + t.Expect(err).NotTo(gomega.HaveOccurred()) + t.T().Logf("Created ClusterRole %s/%s successfully", role.Namespace, role.Name) + + t.T().Cleanup(func() { + t.Client().Core().RbacV1().ClusterRoles().Delete(t.Ctx(), role.Name, metav1.DeleteOptions{}) + }) + + return role +} + func CreateRoleBinding(t Test, namespace string, serviceAccount *corev1.ServiceAccount, role *rbacv1.Role) *rbacv1.RoleBinding { t.T().Helper() @@ -76,3 +100,39 @@ func CreateRoleBinding(t Test, namespace string, serviceAccount *corev1.ServiceA return rb } + +func CreateClusterRoleBinding(t Test, serviceAccount *corev1.ServiceAccount, role *rbacv1.ClusterRole) *rbacv1.ClusterRoleBinding { + t.T().Helper() + + roleBinding := &rbacv1.ClusterRoleBinding{ + TypeMeta: metav1.TypeMeta{ + APIVersion: rbacv1.SchemeGroupVersion.String(), + Kind: "ClusterRoleBinding", + }, + ObjectMeta: metav1.ObjectMeta{ + GenerateName: "crb-", + }, + RoleRef: rbacv1.RoleRef{ + APIGroup: rbacv1.SchemeGroupVersion.Group, + Kind: "ClusterRole", + Name: role.Name, + }, + Subjects: []rbacv1.Subject{ + { + Kind: "ServiceAccount", + APIGroup: corev1.SchemeGroupVersion.Group, + Name: serviceAccount.Name, + Namespace: serviceAccount.Namespace, + }, + }, + } + rb, err := t.Client().Core().RbacV1().ClusterRoleBindings().Create(t.Ctx(), roleBinding, metav1.CreateOptions{}) + t.Expect(err).NotTo(gomega.HaveOccurred()) + t.T().Logf("Created ClusterRoleBinding %s/%s successfully", role.Namespace, role.Name) + + t.T().Cleanup(func() { + t.Client().Core().RbacV1().ClusterRoleBindings().Delete(t.Ctx(), rb.Name, metav1.DeleteOptions{}) + }) + + return rb +}