Skip to content

Commit 128d5ef

Browse files
Add OAuth config to reconciler struct
1 parent 7a368c2 commit 128d5ef

File tree

3 files changed

+25
-39
lines changed

3 files changed

+25
-39
lines changed

main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ func main() {
185185

186186
v, err := HasAPIResourceForGVK(kubeClient.DiscoveryClient, rayv1.GroupVersion.WithKind("RayCluster"))
187187
if v {
188-
rayClusterController := controllers.RayClusterReconciler{Client: mgr.GetClient(), Scheme: mgr.GetScheme()}
188+
rayClusterController := controllers.RayClusterReconciler{Client: mgr.GetClient(), Scheme: mgr.GetScheme(), Config: cfg}
189189
exitOnError(rayClusterController.SetupWithManager(mgr), "Error setting up RayCluster controller")
190190
} else if err != nil {
191191
exitOnError(err, "Could not determine if RayCluster CR present on cluster.")

pkg/controllers/raycluster_controller.go

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ type RayClusterReconciler struct {
5252
routeClient *routev1client.RouteV1Client
5353
Scheme *runtime.Scheme
5454
CookieSalt string
55+
Config *config.CodeFlareOperatorConfiguration
5556
}
5657

5758
const (
@@ -60,14 +61,13 @@ const (
6061
oAuthFinalizer = "ray.openshift.ai/oauth-finalizer"
6162
oAuthServicePort = 443
6263
oAuthServicePortName = "oauth-proxy"
63-
regularServicePortName = "dashboard"
64+
ingressServicePortName = "dashboard"
6465
logRequeueing = "requeueing"
6566
)
6667

6768
var (
68-
deletePolicy = metav1.DeletePropagationForeground
69-
deleteOptions = client.DeleteOptions{PropagationPolicy: &deletePolicy}
70-
configInstance *config.CodeFlareOperatorConfiguration
69+
deletePolicy = metav1.DeletePropagationForeground
70+
deleteOptions = client.DeleteOptions{PropagationPolicy: &deletePolicy}
7171
)
7272

7373
// +kubebuilder:rbac:groups=ray.io,resources=rayclusters,verbs=get;list;watch;create;update;patch;delete
@@ -103,7 +103,7 @@ func (r *RayClusterReconciler) Reconcile(ctx context.Context, req ctrl.Request)
103103

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

108108
if cluster.ObjectMeta.DeletionTimestamp.IsZero() {
109109
if !controllerutil.ContainsFinalizer(&cluster, oAuthFinalizer) {
@@ -138,7 +138,7 @@ func (r *RayClusterReconciler) Reconcile(ctx context.Context, req ctrl.Request)
138138
return ctrl.Result{}, nil
139139
}
140140

141-
if cluster.Status.State != "suspended" && isRayDashboardOAuthEnabled() && isOpenShift {
141+
if cluster.Status.State != "suspended" && r.isRayDashboardOAuthEnabled() && isOpenShift {
142142
logger.Info("Creating OAuth Objects")
143143
_, err := r.routeClient.Routes(cluster.Namespace).Apply(ctx, desiredClusterRoute(&cluster), metav1.ApplyOptions{FieldManager: controllerName, Force: true})
144144
if err != nil {
@@ -165,22 +165,15 @@ func (r *RayClusterReconciler) Reconcile(ctx context.Context, req ctrl.Request)
165165
logger.Error(err, "Failed to update OAuth ClusterRoleBinding")
166166
}
167167

168-
} else if cluster.Status.State != "suspended" && !isRayDashboardOAuthEnabled() && isOpenShift {
169-
logger.Info("Creating Dashboard Route")
170-
_, err := r.routeClient.Routes(cluster.Namespace).Apply(ctx, createRoute(&cluster), metav1.ApplyOptions{FieldManager: controllerName, Force: true})
171-
if err != nil {
172-
logger.Error(err, "Failed to update Dashboard Route")
173-
}
174168
if isLocalInteractive && ingressDomain != "" {
175169
logger.Info("Creating RayClient Route")
176170
_, err := r.routeClient.Routes(cluster.Namespace).Apply(ctx, createRayClientRoute(&cluster), metav1.ApplyOptions{FieldManager: controllerName, Force: true})
177171
if err != nil {
178172
logger.Error(err, "Failed to update RayClient Route")
179173
}
180174
}
181-
return ctrl.Result{}, nil
182175

183-
} else if cluster.Status.State != "suspended" && !isRayDashboardOAuthEnabled() && !isOpenShift {
176+
} else if cluster.Status.State != "suspended" && !r.isRayDashboardOAuthEnabled() && !isOpenShift {
184177
logger.Info("Creating Dashboard Ingress")
185178
_, err := r.kubeClient.NetworkingV1().Ingresses(cluster.Namespace).Apply(ctx, createIngressApplyConfiguration(&cluster, ingressHost), metav1.ApplyOptions{FieldManager: controllerName, Force: true})
186179
if err != nil {

pkg/controllers/support.go

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

30-
func createRoute(cluster *rayv1.RayCluster) *routeapply.RouteApplyConfiguration {
31-
return routeapply.Route(dashboardNameFromCluster(cluster), cluster.Namespace).
32-
WithLabels(map[string]string{"ray.io/cluster-name": cluster.Name}).
33-
WithSpec(routeapply.RouteSpec().
34-
WithTo(routeapply.RouteTargetReference().WithKind("Service").WithName(serviceNameFromCluster(cluster))).
35-
WithPort(routeapply.RoutePort().WithTargetPort(intstr.FromString(regularServicePortName))).
36-
WithTLS(routeapply.TLSConfig().
37-
WithTermination("edge")),
38-
).
39-
WithOwnerReferences(
40-
v1.OwnerReference().WithUID(cluster.UID).WithName(cluster.Name).WithKind(cluster.Kind).WithAPIVersion(cluster.APIVersion),
41-
)
42-
}
43-
4430
func createRayClientRoute(cluster *rayv1.RayCluster) *routeapply.RouteApplyConfiguration {
4531
ingress_domain := cluster.ObjectMeta.Annotations["sdk.codeflare.dev/ingress_domain"]
4632
return routeapply.Route(rayClientNameFromCluster(cluster), cluster.Namespace).
@@ -113,7 +99,7 @@ func createIngressApplyConfiguration(cluster *rayv1.RayCluster, ingressHost stri
11399
WithService(networkingv1ac.IngressServiceBackend().
114100
WithName(serviceNameFromCluster(cluster)).
115101
WithPort(networkingv1ac.ServiceBackendPort().
116-
WithName(regularServicePortName),
102+
WithName(ingressServicePortName),
117103
),
118104
),
119105
),
@@ -180,22 +166,29 @@ func getClusterType(logger logr.Logger, clientset *kubernetes.Clientset, cluster
180166
}
181167
}
182168

183-
func isRayDashboardOAuthEnabled() bool {
184-
if configInstance.KubeRay != nil && configInstance.KubeRay.RayDashboardOAuthEnabled != nil {
185-
return *configInstance.KubeRay.RayDashboardOAuthEnabled
169+
func (r *RayClusterReconciler) isRayDashboardOAuthEnabled() bool {
170+
if r.Config != nil && r.Config.KubeRay != nil && r.Config.KubeRay.RayDashboardOAuthEnabled != nil {
171+
return *r.Config.KubeRay.RayDashboardOAuthEnabled
186172
}
187173
return true
188174
}
189175

190176
func annotationBoolVal(logger logr.Logger, cluster *rayv1.RayCluster, annotation string) bool {
191-
val := cluster.ObjectMeta.Annotations[annotation]
177+
val, exists := cluster.ObjectMeta.Annotations[annotation]
178+
if !exists || val == "" {
179+
return false
180+
}
192181
boolVal, err := strconv.ParseBool(val)
193182
if err != nil {
194-
logger.Error(err, "Could not convert", annotation, "value to bool", val)
195-
}
196-
if boolVal {
197-
return true
198-
} else {
183+
logger.Error(err, "Could not convert annotation value to bool", "annotation", annotation, "value", val)
199184
return false
200185
}
186+
return boolVal
187+
}
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 ""
201194
}

0 commit comments

Comments
 (0)