Skip to content

Commit ccc3315

Browse files
Address comments on naming and default values and ctx logger
1 parent 74f1079 commit ccc3315

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

pkg/controllers/raycluster_controller.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ func (r *RayClusterReconciler) Reconcile(ctx context.Context, req ctrl.Request)
101101
return ctrl.Result{}, client.IgnoreNotFound(err)
102102
}
103103

104-
isLocalInteractive := annotationBoolVal(logger, &cluster, "sdk.codeflare.dev/local_interactive")
104+
isLocalInteractive := annotationBoolVal(ctx, &cluster, "sdk.codeflare.dev/local_interactive", false)
105105
ingressDomain := cluster.ObjectMeta.Annotations["sdk.codeflare.dev/ingress_domain"]
106106
isOpenShift, ingressHost := getClusterType(ctx, r.kubeClient, &cluster, ingressDomain)
107107

@@ -172,7 +172,7 @@ func (r *RayClusterReconciler) Reconcile(ctx context.Context, req ctrl.Request)
172172

173173
if isLocalInteractive && ingressDomain != "" {
174174
logger.Info("Creating RayClient Route")
175-
_, err := r.routeClient.Routes(cluster.Namespace).Apply(ctx, createRayClientRoute(&cluster, ingressDomain), metav1.ApplyOptions{FieldManager: controllerName, Force: true})
175+
_, err := r.routeClient.Routes(cluster.Namespace).Apply(ctx, desiredRayClientRoute(&cluster, ingressDomain), metav1.ApplyOptions{FieldManager: controllerName, Force: true})
176176
if err != nil {
177177
logger.Error(err, "Failed to update RayClient Route")
178178
return ctrl.Result{RequeueAfter: requeueTime}, err
@@ -181,15 +181,15 @@ func (r *RayClusterReconciler) Reconcile(ctx context.Context, req ctrl.Request)
181181

182182
} else if cluster.Status.State != "suspended" && !r.isRayDashboardOAuthEnabled() && !isOpenShift {
183183
logger.Info("Creating Dashboard Ingress")
184-
_, err := r.kubeClient.NetworkingV1().Ingresses(cluster.Namespace).Apply(ctx, createIngressApplyConfiguration(&cluster, ingressHost), metav1.ApplyOptions{FieldManager: controllerName, Force: true})
184+
_, err := r.kubeClient.NetworkingV1().Ingresses(cluster.Namespace).Apply(ctx, desiredClusterIngress(&cluster, ingressHost), metav1.ApplyOptions{FieldManager: controllerName, Force: true})
185185
if err != nil {
186186
// This log is info level since errors are not fatal and are expected
187187
logger.Info("WARN: Failed to update Dashboard Ingress", "error", err.Error(), logRequeueing, true)
188188
return ctrl.Result{RequeueAfter: requeueTime}, err
189189
}
190190
if isLocalInteractive && ingressDomain != "" {
191191
logger.Info("Creating RayClient Ingress")
192-
_, err := r.kubeClient.NetworkingV1().Ingresses(cluster.Namespace).Apply(ctx, createRayClientIngress(&cluster, ingressDomain), metav1.ApplyOptions{FieldManager: controllerName, Force: true})
192+
_, err := r.kubeClient.NetworkingV1().Ingresses(cluster.Namespace).Apply(ctx, desiredRayClientIngress(&cluster, ingressDomain), metav1.ApplyOptions{FieldManager: controllerName, Force: true})
193193
if err != nil {
194194
logger.Error(err, "Failed to update RayClient Ingress")
195195
return ctrl.Result{RequeueAfter: requeueTime}, err

pkg/controllers/support.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import (
66
"strconv"
77
"strings"
88

9-
"github.com/go-logr/logr"
109
rayv1 "github.com/ray-project/kuberay/ray-operator/apis/ray/v1"
1110

1211
networkingv1 "k8s.io/api/networking/v1"
@@ -27,7 +26,7 @@ func serviceNameFromCluster(cluster *rayv1.RayCluster) string {
2726
return cluster.Name + "-head-svc"
2827
}
2928

30-
func createRayClientRoute(cluster *rayv1.RayCluster, ingressDomain string) *routeapply.RouteApplyConfiguration {
29+
func desiredRayClientRoute(cluster *rayv1.RayCluster, ingressDomain string) *routeapply.RouteApplyConfiguration {
3130
return routeapply.Route(rayClientNameFromCluster(cluster), cluster.Namespace).
3231
WithLabels(map[string]string{"ray.io/cluster-name": cluster.Name}).
3332
WithSpec(routeapply.RouteSpec().
@@ -42,7 +41,7 @@ func createRayClientRoute(cluster *rayv1.RayCluster, ingressDomain string) *rout
4241
}
4342

4443
// Create an Ingress object for the RayCluster
45-
func createRayClientIngress(cluster *rayv1.RayCluster, ingressDomain string) *networkingv1ac.IngressApplyConfiguration {
44+
func desiredRayClientIngress(cluster *rayv1.RayCluster, ingressDomain string) *networkingv1ac.IngressApplyConfiguration {
4645
return networkingv1ac.Ingress(rayClientNameFromCluster(cluster), cluster.Namespace).
4746
WithLabels(map[string]string{"ray.io/cluster-name": cluster.Name}).
4847
WithAnnotations(map[string]string{
@@ -78,7 +77,7 @@ func createRayClientIngress(cluster *rayv1.RayCluster, ingressDomain string) *ne
7877
}
7978

8079
// Create an Ingress object for the RayCluster
81-
func createIngressApplyConfiguration(cluster *rayv1.RayCluster, ingressHost string) *networkingv1ac.IngressApplyConfiguration {
80+
func desiredClusterIngress(cluster *rayv1.RayCluster, ingressHost string) *networkingv1ac.IngressApplyConfiguration {
8281
return networkingv1ac.Ingress(dashboardNameFromCluster(cluster), cluster.Namespace).
8382
WithLabels(map[string]string{"ray.io/cluster-name": cluster.Name}).
8483
WithOwnerReferences(v1.OwnerReference().
@@ -167,15 +166,16 @@ func (r *RayClusterReconciler) isRayDashboardOAuthEnabled() bool {
167166
return true
168167
}
169168

170-
func annotationBoolVal(logger logr.Logger, cluster *rayv1.RayCluster, annotation string) bool {
169+
func annotationBoolVal(ctx context.Context, cluster *rayv1.RayCluster, annotation string, defaultValue bool) bool {
170+
logger := ctrl.LoggerFrom(ctx)
171171
val, exists := cluster.ObjectMeta.Annotations[annotation]
172172
if !exists || val == "" {
173-
return false
173+
return defaultValue
174174
}
175175
boolVal, err := strconv.ParseBool(val)
176176
if err != nil {
177177
logger.Error(err, "Could not convert annotation value to bool", "annotation", annotation, "value", val)
178-
return false
178+
return defaultValue
179179
}
180180
return boolVal
181181
}

0 commit comments

Comments
 (0)