Skip to content

Commit

Permalink
Scope RayCluster finalizer into ray.openshift.ai
Browse files Browse the repository at this point in the history
  • Loading branch information
astefanutti authored and openshift-merge-bot[bot] committed Apr 3, 2024
1 parent 5e5f5b3 commit 2f100af
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 23 deletions.
44 changes: 22 additions & 22 deletions pkg/controllers/raycluster_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,26 +53,26 @@ type RayClusterReconciler struct {
}

const (
requeueTime = 10
controllerName = "codeflare-raycluster-controller"
CodeflareOAuthFinalizer = "openshift.ai/oauth-finalizer"
OAuthServicePort = 443
OAuthServicePortName = "oauth-proxy"
logRequeueing = "requeueing"
requeueTime = 10
controllerName = "codeflare-raycluster-controller"
oAuthFinalizer = "ray.openshift.ai/oauth-finalizer"
oAuthServicePort = 443
oAuthServicePortName = "oauth-proxy"
logRequeueing = "requeueing"
)

var (
deletePolicy = metav1.DeletePropagationForeground
deleteOptions = client.DeleteOptions{PropagationPolicy: &deletePolicy}
)

//+kubebuilder:rbac:groups=ray.io,resources=rayclusters,verbs=get;list;watch;create;update;patch;delete
//+kubebuilder:rbac:groups=ray.io,resources=rayclusters/status,verbs=get;update;patch
//+kubebuilder:rbac:groups=ray.io,resources=rayclusters/finalizers,verbs=update
//+kubebuilder:rbac:groups=route.openshift.io,resources=routes,verbs=patch;delete;get
//+kubebuilder:rbac:groups=core,resources=secrets,verbs=get;create;patch;delete;get
//+kubebuilder:rbac:groups=core,resources=services,verbs=patch;delete;get
//+kubebuilder:rbac:groups=core,resources=serviceaccounts,verbs=patch;delete;get
// +kubebuilder:rbac:groups=ray.io,resources=rayclusters,verbs=get;list;watch;create;update;patch;delete
// +kubebuilder:rbac:groups=ray.io,resources=rayclusters/status,verbs=get;update;patch
// +kubebuilder:rbac:groups=ray.io,resources=rayclusters/finalizers,verbs=update
// +kubebuilder:rbac:groups=route.openshift.io,resources=routes,verbs=patch;delete;get
// +kubebuilder:rbac:groups=core,resources=secrets,verbs=get;create;patch;delete;get
// +kubebuilder:rbac:groups=core,resources=services,verbs=patch;delete;get
// +kubebuilder:rbac:groups=core,resources=serviceaccounts,verbs=patch;delete;get

// Reconcile is part of the main kubernetes reconciliation loop which aims to
// move the current state of the cluster closer to the desired state.
Expand All @@ -97,16 +97,16 @@ func (r *RayClusterReconciler) Reconcile(ctx context.Context, req ctrl.Request)
}

if cluster.ObjectMeta.DeletionTimestamp.IsZero() {
if !controllerutil.ContainsFinalizer(&cluster, CodeflareOAuthFinalizer) {
logger.Info("Add a finalizer", "finalizer", CodeflareOAuthFinalizer)
controllerutil.AddFinalizer(&cluster, CodeflareOAuthFinalizer)
if !controllerutil.ContainsFinalizer(&cluster, oAuthFinalizer) {
logger.Info("Add a finalizer", "finalizer", oAuthFinalizer)
controllerutil.AddFinalizer(&cluster, oAuthFinalizer)
if err := r.Update(ctx, &cluster); err != nil {
// this log is info level since errors are not fatal and are expected
logger.Info("WARN: Failed to update RayCluster with finalizer", "error", err.Error(), logRequeueing, true)
return ctrl.Result{RequeueAfter: requeueTime}, err
}
}
} else if controllerutil.ContainsFinalizer(&cluster, CodeflareOAuthFinalizer) {
} else if controllerutil.ContainsFinalizer(&cluster, oAuthFinalizer) {
err := client.IgnoreNotFound(r.Client.Delete(
ctx,
&rbacv1.ClusterRoleBinding{
Expand All @@ -120,7 +120,7 @@ func (r *RayClusterReconciler) Reconcile(ctx context.Context, req ctrl.Request)
logger.Error(err, "Failed to remove OAuth ClusterRoleBinding.", logRequeueing, true)
return ctrl.Result{RequeueAfter: requeueTime}, err
}
controllerutil.RemoveFinalizer(&cluster, CodeflareOAuthFinalizer)
controllerutil.RemoveFinalizer(&cluster, oAuthFinalizer)
if err := r.Update(ctx, &cluster); err != nil {
logger.Error(err, "Failed to remove finalizer from RayCluster", logRequeueing, true)
return ctrl.Result{RequeueAfter: requeueTime}, err
Expand Down Expand Up @@ -208,7 +208,7 @@ func desiredClusterRoute(cluster *rayv1.RayCluster) *routeapply.RouteApplyConfig
WithLabels(map[string]string{"ray.io/cluster-name": cluster.Name}).
WithSpec(routeapply.RouteSpec().
WithTo(routeapply.RouteTargetReference().WithKind("Service").WithName(oauthServiceNameFromCluster(cluster))).
WithPort(routeapply.RoutePort().WithTargetPort(intstr.FromString((OAuthServicePortName)))).
WithPort(routeapply.RoutePort().WithTargetPort(intstr.FromString((oAuthServicePortName)))).
WithTLS(routeapply.TLSConfig().
WithInsecureEdgeTerminationPolicy(routev1.InsecureEdgeTerminationPolicyRedirect).
WithTermination(routev1.TLSTerminationReencrypt),
Expand All @@ -235,9 +235,9 @@ func desiredOAuthService(cluster *rayv1.RayCluster) *coreapply.ServiceApplyConfi
coreapply.ServiceSpec().
WithPorts(
coreapply.ServicePort().
WithName(OAuthServicePortName).
WithPort(OAuthServicePort).
WithTargetPort(intstr.FromString(OAuthServicePortName)).
WithName(oAuthServicePortName).
WithPort(oAuthServicePort).
WithTargetPort(intstr.FromString(oAuthServicePortName)).
WithProtocol(corev1.ProtocolTCP),
).
WithSelector(map[string]string{"ray.io/cluster": cluster.Name, "ray.io/node-type": "head"}),
Expand Down
2 changes: 1 addition & 1 deletion pkg/controllers/raycluster_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ var _ = Describe("RayCluster controller", func() {
Eventually(func() bool {
err := k8sClient.Get(ctx, typeNamespaceName, &foundRayCluster)
Expect(err).To(Not(HaveOccurred()))
return stringInList(foundRayCluster.Finalizers, CodeflareOAuthFinalizer)
return stringInList(foundRayCluster.Finalizers, oAuthFinalizer)
}, SpecTimeout(time.Second*10)).Should(Equal(true))
})

Expand Down

0 comments on commit 2f100af

Please sign in to comment.