Skip to content

Commit 9ea041f

Browse files
address comments from PR review
Signed-off-by: Kevin <[email protected]>
1 parent 4f0c9c1 commit 9ea041f

File tree

3 files changed

+23
-25
lines changed

3 files changed

+23
-25
lines changed

controllers/raycluster_controller.go

+14-22
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ import (
2929
"k8s.io/apimachinery/pkg/api/errors"
3030
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
3131
"k8s.io/apimachinery/pkg/runtime"
32-
"k8s.io/apimachinery/pkg/types"
3332
"k8s.io/apimachinery/pkg/util/intstr"
3433
coreapply "k8s.io/client-go/applyconfigurations/core/v1"
3534
v1 "k8s.io/client-go/applyconfigurations/meta/v1"
@@ -56,12 +55,9 @@ type RayClusterReconciler struct {
5655
const (
5756
requeueTime = 10
5857
controllerName = "codeflare-raycluster-controller"
59-
oauthAnnotation = "codeflare.dev/oauth=true"
60-
CodeflareOAuthFinalizer = "codeflare.dev/oauth-finalizer"
58+
CodeflareOAuthFinalizer = "openshift.ai/oauth-finalizer"
6159
OAuthServicePort = 443
6260
OAuthServicePortName = "oauth-proxy"
63-
strTrue = "true"
64-
strFalse = "false"
6561
logRequeueing = "requeueing"
6662
)
6763

@@ -106,24 +102,30 @@ func (r *RayClusterReconciler) Reconcile(ctx context.Context, req ctrl.Request)
106102
controllerutil.AddFinalizer(&cluster, CodeflareOAuthFinalizer)
107103
if err := r.Update(ctx, &cluster); err != nil {
108104
// this log is info level since errors are not fatal and are expected
109-
logger.Info("WARN: Failed to update RayCluster with finalizer", "error", err.Error(), logRequeueing, strTrue)
105+
logger.Info("WARN: Failed to update RayCluster with finalizer", "error", err.Error(), logRequeueing, true)
110106
return ctrl.Result{RequeueAfter: requeueTime}, err
111107
}
112108
}
113109
} else if controllerutil.ContainsFinalizer(&cluster, CodeflareOAuthFinalizer) {
114-
err := r.deleteIfNotExist(
115-
ctx, types.NamespacedName{Namespace: cluster.Namespace, Name: crbNameFromCluster(&cluster)}, &rbacv1.ClusterRoleBinding{},
116-
)
110+
err := client.IgnoreNotFound(r.Client.Delete(
111+
ctx,
112+
&rbacv1.ClusterRoleBinding{
113+
ObjectMeta: metav1.ObjectMeta{
114+
Name: crbNameFromCluster(&cluster),
115+
},
116+
},
117+
&deleteOptions,
118+
))
117119
if err != nil {
118-
logger.Error(err, "Failed to remove OAuth ClusterRoleBinding.", logRequeueing, strTrue)
120+
logger.Error(err, "Failed to remove OAuth ClusterRoleBinding.", logRequeueing, true)
119121
return ctrl.Result{RequeueAfter: requeueTime}, err
120122
}
121123
controllerutil.RemoveFinalizer(&cluster, CodeflareOAuthFinalizer)
122124
if err := r.Update(ctx, &cluster); err != nil {
123-
logger.Error(err, "Failed to remove finalizer from RayCluster", logRequeueing, strTrue)
125+
logger.Error(err, "Failed to remove finalizer from RayCluster", logRequeueing, true)
124126
return ctrl.Result{RequeueAfter: requeueTime}, err
125127
}
126-
logger.Info("Successfully removed finalizer.", logRequeueing, strFalse)
128+
logger.Info("Successfully removed finalizer.", logRequeueing, false)
127129
return ctrl.Result{}, nil
128130
}
129131

@@ -159,16 +161,6 @@ func crbNameFromCluster(cluster *rayv1.RayCluster) string {
159161
return cluster.Name + "-" + cluster.Namespace + "-auth" // NOTE: potential naming conflicts ie {name: foo, ns: bar-baz} and {name: foo-bar, ns: baz}
160162
}
161163

162-
func (r *RayClusterReconciler) deleteIfNotExist(ctx context.Context, namespacedName types.NamespacedName, obj client.Object) error {
163-
err := r.Client.Get(ctx, namespacedName, obj)
164-
if err != nil && errors.IsNotFound(err) {
165-
return nil
166-
} else if err != nil {
167-
return err
168-
}
169-
return r.Client.Delete(ctx, obj, &deleteOptions)
170-
}
171-
172164
func desiredOAuthClusterRoleBinding(cluster *rayv1.RayCluster) *rbacapply.ClusterRoleBindingApplyConfiguration {
173165
return rbacapply.ClusterRoleBinding(
174166
crbNameFromCluster(cluster)).

main.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,9 @@ func main() {
134134
MaxScaleoutAllowed: 5,
135135
},
136136
},
137-
RayClusterOAuth: pointer.Bool(true),
137+
KubeRay: &config.KubeRayConfiguration{
138+
RayDashboardOAuthEnabled: pointer.Bool(true),
139+
},
138140
}
139141

140142
kubeConfig, err := ctrl.GetConfig()
@@ -182,7 +184,7 @@ func main() {
182184
}
183185

184186
v, err := HasAPIResourceForGVK(kubeClient.DiscoveryClient, rayv1.GroupVersion.WithKind("RayCluster"))
185-
if v && *cfg.RayClusterOAuth {
187+
if v && *cfg.KubeRay.RayDashboardOAuthEnabled {
186188
rayClusterController := cfoControllers.RayClusterReconciler{Client: mgr.GetClient(), Scheme: mgr.GetScheme()}
187189
exitOnError(rayClusterController.SetupWithManager(mgr), "Error setting up RayCluster controller")
188190
} else if err != nil {

pkg/config/config.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,11 @@ type CodeFlareOperatorConfiguration struct {
3737
// The InstaScale controller configuration
3838
InstaScale *InstaScaleConfiguration `json:"instascale,omitempty"`
3939

40-
RayClusterOAuth *bool `json:"rayClusterOAuth,omitempty"`
40+
KubeRay *KubeRayConfiguration `json:"kuberay,omitempty"`
41+
}
42+
43+
type KubeRayConfiguration struct {
44+
RayDashboardOAuthEnabled *bool `json:"rayDashboardOAuthEnabled,omitempty"`
4145
}
4246

4347
type InstaScaleConfiguration struct {

0 commit comments

Comments
 (0)