Skip to content

Commit e364597

Browse files
Addressing comments on ingressDomain
1 parent 128d5ef commit e364597

File tree

2 files changed

+14
-24
lines changed

2 files changed

+14
-24
lines changed

pkg/controllers/raycluster_controller.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,8 @@ func (r *RayClusterReconciler) Reconcile(ctx context.Context, req ctrl.Request)
102102
}
103103

104104
isLocalInteractive := annotationBoolVal(logger, &cluster, "sdk.codeflare.dev/local_interactive")
105-
isOpenShift, ingressHost := getClusterType(logger, r.kubeClient, &cluster)
106-
ingressDomain := getIngressDomain(&cluster)
105+
ingressDomain := cluster.ObjectMeta.Annotations["sdk.codeflare.dev/ingress_domain"]
106+
isOpenShift, ingressHost := getClusterType(logger, r.kubeClient, &cluster, ingressDomain)
107107

108108
if cluster.ObjectMeta.DeletionTimestamp.IsZero() {
109109
if !controllerutil.ContainsFinalizer(&cluster, oAuthFinalizer) {
@@ -167,7 +167,7 @@ func (r *RayClusterReconciler) Reconcile(ctx context.Context, req ctrl.Request)
167167

168168
if isLocalInteractive && ingressDomain != "" {
169169
logger.Info("Creating RayClient Route")
170-
_, err := r.routeClient.Routes(cluster.Namespace).Apply(ctx, createRayClientRoute(&cluster), metav1.ApplyOptions{FieldManager: controllerName, Force: true})
170+
_, err := r.routeClient.Routes(cluster.Namespace).Apply(ctx, createRayClientRoute(&cluster, ingressDomain), metav1.ApplyOptions{FieldManager: controllerName, Force: true})
171171
if err != nil {
172172
logger.Error(err, "Failed to update RayClient Route")
173173
}
@@ -182,7 +182,7 @@ func (r *RayClusterReconciler) Reconcile(ctx context.Context, req ctrl.Request)
182182
}
183183
if isLocalInteractive && ingressDomain != "" {
184184
logger.Info("Creating RayClient Ingress")
185-
_, err := r.kubeClient.NetworkingV1().Ingresses(cluster.Namespace).Apply(ctx, createRayClientIngress(&cluster), metav1.ApplyOptions{FieldManager: controllerName, Force: true})
185+
_, err := r.kubeClient.NetworkingV1().Ingresses(cluster.Namespace).Apply(ctx, createRayClientIngress(&cluster, ingressDomain), metav1.ApplyOptions{FieldManager: controllerName, Force: true})
186186
if err != nil {
187187
logger.Error(err, "Failed to update RayClient Ingress")
188188
}

pkg/controllers/support.go

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,11 @@ func serviceNameFromCluster(cluster *rayv1.RayCluster) string {
2727
return cluster.Name + "-head-svc"
2828
}
2929

30-
func createRayClientRoute(cluster *rayv1.RayCluster) *routeapply.RouteApplyConfiguration {
31-
ingress_domain := cluster.ObjectMeta.Annotations["sdk.codeflare.dev/ingress_domain"]
30+
func createRayClientRoute(cluster *rayv1.RayCluster, ingressDomain string) *routeapply.RouteApplyConfiguration {
3231
return routeapply.Route(rayClientNameFromCluster(cluster), cluster.Namespace).
3332
WithLabels(map[string]string{"ray.io/cluster-name": cluster.Name}).
3433
WithSpec(routeapply.RouteSpec().
35-
WithHost(rayClientNameFromCluster(cluster) + "-" + cluster.Namespace + "." + ingress_domain).
34+
WithHost(rayClientNameFromCluster(cluster) + "-" + cluster.Namespace + "." + ingressDomain).
3635
WithTo(routeapply.RouteTargetReference().WithKind("Service").WithName(serviceNameFromCluster(cluster)).WithWeight(100)).
3736
WithPort(routeapply.RoutePort().WithTargetPort(intstr.FromString("client"))).
3837
WithTLS(routeapply.TLSConfig().WithTermination("passthrough")),
@@ -43,8 +42,7 @@ func createRayClientRoute(cluster *rayv1.RayCluster) *routeapply.RouteApplyConfi
4342
}
4443

4544
// Create an Ingress object for the RayCluster
46-
func createRayClientIngress(cluster *rayv1.RayCluster) *networkingv1ac.IngressApplyConfiguration {
47-
ingress_domain := cluster.ObjectMeta.Annotations["sdk.codeflare.dev/ingress_domain"]
45+
func createRayClientIngress(cluster *rayv1.RayCluster, ingressDomain string) *networkingv1ac.IngressApplyConfiguration {
4846
return networkingv1ac.Ingress(rayClientNameFromCluster(cluster), cluster.Namespace).
4947
WithLabels(map[string]string{"ray.io/cluster-name": cluster.Name}).
5048
WithAnnotations(map[string]string{
@@ -60,7 +58,7 @@ func createRayClientIngress(cluster *rayv1.RayCluster) *networkingv1ac.IngressAp
6058
WithSpec(networkingv1ac.IngressSpec().
6159
WithIngressClassName("nginx").
6260
WithRules(networkingv1ac.IngressRule().
63-
WithHost(rayClientNameFromCluster(cluster) + "-" + cluster.Namespace + "." + ingress_domain).
61+
WithHost(rayClientNameFromCluster(cluster) + "-" + cluster.Namespace + "." + ingressDomain).
6462
WithHTTP(networkingv1ac.HTTPIngressRuleValue().
6563
WithPaths(networkingv1ac.HTTPIngressPath().
6664
WithPath("/").
@@ -90,7 +88,7 @@ func createIngressApplyConfiguration(cluster *rayv1.RayCluster, ingressHost stri
9088
WithUID(types.UID(cluster.UID))).
9189
WithSpec(networkingv1ac.IngressSpec().
9290
WithRules(networkingv1ac.IngressRule().
93-
WithHost(ingressHost). // kind host name or ingress_domain
91+
WithHost(ingressHost). // KinD hostname or ingressDomain
9492
WithHTTP(networkingv1ac.HTTPIngressRuleValue().
9593
WithPaths(networkingv1ac.HTTPIngressPath().
9694
WithPath("/").
@@ -129,9 +127,8 @@ func getDiscoveryClient(config *rest.Config) (*discovery.DiscoveryClient, error)
129127

130128
// Check where we are running. We are trying to distinguish here whether
131129
// this is vanilla kubernetes cluster or Openshift
132-
func getClusterType(logger logr.Logger, clientset *kubernetes.Clientset, cluster *rayv1.RayCluster) (bool, string) {
130+
func getClusterType(logger logr.Logger, clientset *kubernetes.Clientset, cluster *rayv1.RayCluster, ingressDomain string) (bool, string) {
133131
// The discovery package is used to discover APIs supported by a Kubernetes API server.
134-
ingress_domain := cluster.ObjectMeta.Annotations["sdk.codeflare.dev/ingress_domain"]
135132
config, err := ctrl.GetConfig()
136133
if err == nil && config != nil {
137134
dclient, err := getDiscoveryClient(config)
@@ -148,21 +145,21 @@ func getClusterType(logger logr.Logger, clientset *kubernetes.Clientset, cluster
148145
}
149146
}
150147
onKind, _ := isOnKindCluster(clientset)
151-
if onKind && ingress_domain == "" {
148+
if onKind && ingressDomain == "" {
152149
logger.Info("We detected being on a KinD cluster!")
153150
return false, "kind"
154151
} else {
155152
logger.Info("We detected being on Vanilla Kubernetes!")
156-
return false, fmt.Sprintf("ray-dashboard-%s-%s.%s", cluster.Name, cluster.Namespace, ingress_domain)
153+
return false, fmt.Sprintf("ray-dashboard-%s-%s.%s", cluster.Name, cluster.Namespace, ingressDomain)
157154
}
158155
}
159156
} else {
160157
logger.Info("Cannot retrieve a DiscoveryClient, assuming we're on Vanilla Kubernetes")
161-
return false, fmt.Sprintf("ray-dashboard-%s-%s.%s", cluster.Name, cluster.Namespace, ingress_domain)
158+
return false, fmt.Sprintf("ray-dashboard-%s-%s.%s", cluster.Name, cluster.Namespace, ingressDomain)
162159
}
163160
} else {
164161
logger.Info("Cannot retrieve config, assuming we're on Vanilla Kubernetes")
165-
return false, fmt.Sprintf("ray-dashboard-%s-%s.%s", cluster.Name, cluster.Namespace, ingress_domain)
162+
return false, fmt.Sprintf("ray-dashboard-%s-%s.%s", cluster.Name, cluster.Namespace, ingressDomain)
166163
}
167164
}
168165

@@ -185,10 +182,3 @@ func annotationBoolVal(logger logr.Logger, cluster *rayv1.RayCluster, annotation
185182
}
186183
return boolVal
187184
}
188-
189-
func getIngressDomain(cluster *rayv1.RayCluster) string {
190-
if ingressDomain, exists := cluster.ObjectMeta.Annotations["sdk.codeflare.dev/ingress_domain"]; exists {
191-
return ingressDomain
192-
}
193-
return ""
194-
}

0 commit comments

Comments
 (0)