Skip to content

RayCluster controller follow-up #496

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ RUN go mod download
# Copy the Go sources
COPY main.go main.go
COPY pkg/ pkg/
COPY controllers/ controllers/

# Build
USER root
Expand Down
4 changes: 2 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ import (
machinev1beta1 "github.com/openshift/api/machine/v1beta1"
routev1 "github.com/openshift/api/route/v1"

cfoControllers "github.com/project-codeflare/codeflare-operator/controllers"
"github.com/project-codeflare/codeflare-operator/pkg/config"
"github.com/project-codeflare/codeflare-operator/pkg/controllers"
// Import all Kubernetes client auth plugins (e.g. Azure, GCP, OIDC, etc.)
// to ensure that exec-entrypoint and run can make use of them.
// +kubebuilder:scaffold:imports
Expand Down Expand Up @@ -185,7 +185,7 @@ func main() {

v, err := HasAPIResourceForGVK(kubeClient.DiscoveryClient, rayv1.GroupVersion.WithKind("RayCluster"))
if v && *cfg.KubeRay.RayDashboardOAuthEnabled {
rayClusterController := cfoControllers.RayClusterReconciler{Client: mgr.GetClient(), Scheme: mgr.GetScheme()}
rayClusterController := controllers.RayClusterReconciler{Client: mgr.GetClient(), Scheme: mgr.GetScheme()}
exitOnError(rayClusterController.SetupWithManager(mgr), "Error setting up RayCluster controller")
} else if err != nil {
exitOnError(err, "Could not determine if RayCluster CR present on cluster.")
Expand Down
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
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
File renamed without changes.