Skip to content

Commit b942bca

Browse files
Add ingressDomain to configmap to work with local and workflow e2e tests
1 parent 7520fbf commit b942bca

File tree

5 files changed

+24
-34
lines changed

5 files changed

+24
-34
lines changed

config/e2e/config.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ data:
66
config.yaml: |
77
kuberay:
88
rayDashboardOAuthEnabled: false
9+
ingressDomain: "kind"

main.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ func main() {
115115
},
116116
KubeRay: &config.KubeRayConfiguration{
117117
RayDashboardOAuthEnabled: pointer.Bool(true),
118+
IngressDomain: "kind",
118119
},
119120
}
120121

pkg/config/config.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ type CodeFlareOperatorConfiguration struct {
3333

3434
type KubeRayConfiguration struct {
3535
RayDashboardOAuthEnabled *bool `json:"rayDashboardOAuthEnabled,omitempty"`
36+
37+
IngressDomain string `json:"ingressDomain,omitempty"`
3638
}
3739

3840
type ControllerManager struct {

pkg/controllers/raycluster_controller.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -184,21 +184,21 @@ func (r *RayClusterReconciler) Reconcile(ctx context.Context, req ctrl.Request)
184184
}
185185

186186
} else if cluster.Status.State != "suspended" && !r.isRayDashboardOAuthEnabled() && !r.IsOpenShift {
187-
ingressDomain := "" // TODO: ingressDomain should be retrieved by the CFO and used here to fix local_interactive. Jira: https://issues.redhat.com/browse/RHOAIENG-5330
187+
logger.Info("We detected being on Vanilla Kubernetes!")
188188
logger.Info("Creating Dashboard Ingress")
189-
_, err := r.kubeClient.NetworkingV1().Ingresses(cluster.Namespace).Apply(ctx, desiredClusterIngress(&cluster, getIngressHost(ctx, r.kubeClient, &cluster, ingressDomain)), metav1.ApplyOptions{FieldManager: controllerName, Force: true})
189+
dashboardName := dashboardNameFromCluster(&cluster)
190+
_, err := r.kubeClient.NetworkingV1().Ingresses(cluster.Namespace).Apply(ctx, desiredClusterIngress(&cluster, r.getIngressHost(ctx, r.kubeClient, &cluster, dashboardName)), metav1.ApplyOptions{FieldManager: controllerName, Force: true})
190191
if err != nil {
191192
// This log is info level since errors are not fatal and are expected
192193
logger.Info("WARN: Failed to update Dashboard Ingress", "error", err.Error(), logRequeueing, true)
193194
return ctrl.Result{RequeueAfter: requeueTime}, err
194195
}
195-
if ingressDomain != "" {
196-
logger.Info("Creating RayClient Ingress")
197-
_, err := r.kubeClient.NetworkingV1().Ingresses(cluster.Namespace).Apply(ctx, desiredRayClientIngress(&cluster, ingressDomain), metav1.ApplyOptions{FieldManager: controllerName, Force: true})
198-
if err != nil {
199-
logger.Error(err, "Failed to update RayClient Ingress")
200-
return ctrl.Result{RequeueAfter: requeueTime}, err
201-
}
196+
logger.Info("Creating RayClient Ingress")
197+
rayClientName := rayClientNameFromCluster(&cluster)
198+
_, err = r.kubeClient.NetworkingV1().Ingresses(cluster.Namespace).Apply(ctx, desiredRayClientIngress(&cluster, r.getIngressHost(ctx, r.kubeClient, &cluster, rayClientName)), metav1.ApplyOptions{FieldManager: controllerName, Force: true})
199+
if err != nil {
200+
logger.Error(err, "Failed to update RayClient Ingress")
201+
return ctrl.Result{RequeueAfter: requeueTime}, err
202202
}
203203
}
204204

pkg/controllers/support.go

Lines changed: 11 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88
rayv1 "github.com/ray-project/kuberay/ray-operator/apis/ray/v1"
99

1010
networkingv1 "k8s.io/api/networking/v1"
11-
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1211
"k8s.io/apimachinery/pkg/types"
1312
"k8s.io/apimachinery/pkg/util/intstr"
1413
v1 "k8s.io/client-go/applyconfigurations/meta/v1"
@@ -39,7 +38,7 @@ func desiredRayClientRoute(cluster *rayv1.RayCluster) *routeapply.RouteApplyConf
3938
}
4039

4140
// Create an Ingress object for the RayCluster
42-
func desiredRayClientIngress(cluster *rayv1.RayCluster, ingressDomain string) *networkingv1ac.IngressApplyConfiguration {
41+
func desiredRayClientIngress(cluster *rayv1.RayCluster, ingressHost string) *networkingv1ac.IngressApplyConfiguration {
4342
return networkingv1ac.Ingress(rayClientNameFromCluster(cluster), cluster.Namespace).
4443
WithLabels(map[string]string{"ray.io/cluster-name": cluster.Name}).
4544
WithAnnotations(map[string]string{
@@ -55,7 +54,7 @@ func desiredRayClientIngress(cluster *rayv1.RayCluster, ingressDomain string) *n
5554
WithSpec(networkingv1ac.IngressSpec().
5655
WithIngressClassName("nginx").
5756
WithRules(networkingv1ac.IngressRule().
58-
WithHost(rayClientNameFromCluster(cluster) + "-" + cluster.Namespace + "." + ingressDomain).
57+
WithHost(ingressHost).
5958
WithHTTP(networkingv1ac.HTTPIngressRuleValue().
6059
WithPaths(networkingv1ac.HTTPIngressPath().
6160
WithPath("/").
@@ -85,7 +84,7 @@ func desiredClusterIngress(cluster *rayv1.RayCluster, ingressHost string) *netwo
8584
WithUID(types.UID(cluster.UID))).
8685
WithSpec(networkingv1ac.IngressSpec().
8786
WithRules(networkingv1ac.IngressRule().
88-
WithHost(ingressHost). // KinD hostname or ingressDomain
87+
WithHost(ingressHost). // Full Hostname
8988
WithHTTP(networkingv1ac.HTTPIngressRuleValue().
9089
WithPaths(networkingv1ac.HTTPIngressPath().
9190
WithPath("/").
@@ -104,19 +103,6 @@ func desiredClusterIngress(cluster *rayv1.RayCluster, ingressHost string) *netwo
104103
)
105104
}
106105

107-
// isOnKindCluster checks if the current cluster is a KinD cluster.
108-
// It searches for a node with a label commonly used by KinD clusters.
109-
func isOnKindCluster(clientset *kubernetes.Clientset) (bool, error) {
110-
nodes, err := clientset.CoreV1().Nodes().List(context.TODO(), metav1.ListOptions{
111-
LabelSelector: "kubernetes.io/hostname=kind-control-plane",
112-
})
113-
if err != nil {
114-
return false, err
115-
}
116-
// If we find one or more nodes with the label, assume it's a KinD cluster.
117-
return len(nodes.Items) > 0, nil
118-
}
119-
120106
// getDiscoveryClient returns a discovery client for the current reconciler
121107
func getDiscoveryClient(config *rest.Config) (*discovery.DiscoveryClient, error) {
122108
return discovery.NewDiscoveryClientForConfig(config)
@@ -153,15 +139,15 @@ func isOpenShift(ctx context.Context, clientset *kubernetes.Clientset, cluster *
153139
}
154140

155141
// getIngressHost generates the cluster URL string based on the cluster type, RayCluster, and ingress domain.
156-
func getIngressHost(ctx context.Context, clientset *kubernetes.Clientset, cluster *rayv1.RayCluster, ingressDomain string) string {
157-
logger := ctrl.LoggerFrom(ctx)
158-
onKind, _ := isOnKindCluster(clientset)
159-
if onKind && ingressDomain == "" {
160-
logger.Info("We detected being on a KinD cluster!")
161-
return "kind"
142+
func (r *RayClusterReconciler) getIngressHost(ctx context.Context, clientset *kubernetes.Clientset, cluster *rayv1.RayCluster, ingressNameFromCluster string) string {
143+
ingressDomain := "fake.domain"
144+
if r.Config != nil && r.Config.IngressDomain != "" {
145+
ingressDomain = r.Config.IngressDomain
162146
}
163-
logger.Info("We detected being on Vanilla Kubernetes!")
164-
return fmt.Sprintf("ray-dashboard-%s-%s.%s", cluster.Name, cluster.Namespace, ingressDomain)
147+
if ingressDomain == "kind" {
148+
return ingressDomain
149+
}
150+
return fmt.Sprintf("%s-%s.%s", ingressNameFromCluster, cluster.Namespace, ingressDomain)
165151
}
166152

167153
func (r *RayClusterReconciler) isRayDashboardOAuthEnabled() bool {

0 commit comments

Comments
 (0)