@@ -21,6 +21,7 @@ import (
2121
2222 rayv1 "github.com/ray-project/kuberay/ray-operator/apis/ray/v1"
2323
24+ "github.com/project-codeflare/codeflare-operator/pkg/config"
2425 corev1 "k8s.io/api/core/v1"
2526 "k8s.io/apimachinery/pkg/runtime"
2627 ctrl "sigs.k8s.io/controller-runtime"
@@ -34,89 +35,97 @@ var rayclusterlog = logf.Log.WithName("raycluster-resource")
3435func (r * RayClusterDefaulter ) SetupWebhookWithManager (mgr ctrl.Manager ) error {
3536 return ctrl .NewWebhookManagedBy (mgr ).
3637 For (& rayv1.RayCluster {}).
37- WithDefaulter (& RayClusterDefaulter {}).
38+ WithDefaulter (& RayClusterDefaulter {
39+ Config : r .Config ,
40+ rayDashboardOauthEnabled : r .isRayDashboardOAuthEnabledWebhook (),
41+ }).
3842 Complete ()
3943}
4044
4145//+kubebuilder:webhook:path=/mutate-ray-io-v1-raycluster,mutating=true,failurePolicy=fail,sideEffects=None,groups=ray.io,resources=rayclusters,verbs=create;update,versions=v1,name=mraycluster.kb.io,admissionReviewVersions=v1
4246
43- type RayClusterDefaulter struct {}
47+ type RayClusterDefaulter struct {
48+ Config * config.KubeRayConfiguration
49+ rayDashboardOauthEnabled bool
50+ }
4451
4552var _ webhook.CustomDefaulter = & RayClusterDefaulter {}
4653
4754// Default implements webhook.Defaulter so a webhook will be registered for the type
4855func (r * RayClusterDefaulter ) Default (ctx context.Context , obj runtime.Object ) error {
4956 raycluster := obj .(* rayv1.RayCluster )
5057
51- rayclusterlog .Info ("default" , "name" , raycluster .Name )
52- // Check and add OAuth proxy if it does not exist.
53- alreadyExists := false
54- for _ , container := range raycluster .Spec .HeadGroupSpec .Template .Spec .Containers {
55- if container .Name == "oauth-proxy" {
56- rayclusterlog .Info ("OAuth sidecar already exists, no patch needed" )
57- alreadyExists = true
58- break // exits the for loop
58+ if r .rayDashboardOauthEnabled {
59+ rayclusterlog .Info ("default" , "name" , raycluster .Name )
60+ // Check and add OAuth proxy if it does not exist.
61+ alreadyExists := false
62+ for _ , container := range raycluster .Spec .HeadGroupSpec .Template .Spec .Containers {
63+ if container .Name == "oauth-proxy" {
64+ rayclusterlog .Info ("OAuth sidecar already exists, no patch needed" )
65+ alreadyExists = true
66+ break // exits the for loop
67+ }
5968 }
60- }
6169
62- if ! alreadyExists {
63- rayclusterlog .Info ("Adding OAuth sidecar container" )
64- // definition of the new container
65- newOAuthSidecar := corev1.Container {
66- Name : "oauth-proxy" ,
67- Image : "registry.redhat.io/openshift4/ose-oauth-proxy@sha256:1ea6a01bf3e63cdcf125c6064cbd4a4a270deaf0f157b3eabb78f60556840366" ,
68- Ports : []corev1.ContainerPort {
69- {ContainerPort : 8443 , Name : "oauth-proxy" },
70- },
71- Args : []string {
72- "--https-address=:8443" ,
73- "--provider=openshift" ,
74- "--openshift-service-account=" + raycluster .Name + "-oauth-proxy" ,
75- "--upstream=http://localhost:8265" ,
76- "--tls-cert=/etc/tls/private/tls.crt" ,
77- "--tls-key=/etc/tls/private/tls.key" ,
78- "--cookie-secret=$(COOKIE_SECRET)" ,
79- "--openshift-delegate-urls={\" /\" :{\" resource\" :\" pods\" ,\" namespace\" :\" default\" ,\" verb\" :\" get\" }}" ,
80- },
81- Env : []corev1.EnvVar {
82- {
83- Name : "COOKIE_SECRET" ,
84- ValueFrom : & corev1.EnvVarSource {
85- SecretKeyRef : & corev1.SecretKeySelector {
86- LocalObjectReference : corev1.LocalObjectReference {
87- Name : raycluster .Name + "-oauth-config" ,
70+ if ! alreadyExists {
71+ rayclusterlog .Info ("Adding OAuth sidecar container" )
72+ // definition of the new container
73+ newOAuthSidecar := corev1.Container {
74+ Name : "oauth-proxy" ,
75+ Image : "registry.redhat.io/openshift4/ose-oauth-proxy@sha256:1ea6a01bf3e63cdcf125c6064cbd4a4a270deaf0f157b3eabb78f60556840366" ,
76+ Ports : []corev1.ContainerPort {
77+ {ContainerPort : 8443 , Name : "oauth-proxy" },
78+ },
79+ Args : []string {
80+ "--https-address=:8443" ,
81+ "--provider=openshift" ,
82+ "--openshift-service-account=" + raycluster .Name + "-oauth-proxy" ,
83+ "--upstream=http://localhost:8265" ,
84+ "--tls-cert=/etc/tls/private/tls.crt" ,
85+ "--tls-key=/etc/tls/private/tls.key" ,
86+ "--cookie-secret=$(COOKIE_SECRET)" ,
87+ "--openshift-delegate-urls={\" /\" :{\" resource\" :\" pods\" ,\" namespace\" :\" default\" ,\" verb\" :\" get\" }}" ,
88+ },
89+ Env : []corev1.EnvVar {
90+ {
91+ Name : "COOKIE_SECRET" ,
92+ ValueFrom : & corev1.EnvVarSource {
93+ SecretKeyRef : & corev1.SecretKeySelector {
94+ LocalObjectReference : corev1.LocalObjectReference {
95+ Name : raycluster .Name + "-oauth-config" ,
96+ },
97+ Key : "cookie_secret" ,
8898 },
89- Key : "cookie_secret" ,
9099 },
91100 },
92101 },
93- },
94- VolumeMounts : []corev1. VolumeMount {
95- {
96- Name : "proxy- tls-secret " ,
97- MountPath : "/etc/tls/private" ,
98- ReadOnly : true ,
102+ VolumeMounts : []corev1. VolumeMount {
103+ {
104+ Name : "proxy-tls-secret" ,
105+ MountPath : "/etc/ tls/private " ,
106+ ReadOnly : true ,
107+ } ,
99108 },
100- },
101- }
109+ }
102110
103- // Adding the new OAuth sidecar container
104- raycluster .Spec .HeadGroupSpec .Template .Spec .Containers = append (raycluster .Spec .HeadGroupSpec .Template .Spec .Containers , newOAuthSidecar )
111+ // Adding the new OAuth sidecar container
112+ raycluster .Spec .HeadGroupSpec .Template .Spec .Containers = append (raycluster .Spec .HeadGroupSpec .Template .Spec .Containers , newOAuthSidecar )
105113
106- tlsSecretVolume := corev1.Volume {
107- Name : "proxy-tls-secret" ,
108- VolumeSource : corev1.VolumeSource {
109- Secret : & corev1.SecretVolumeSource {
110- SecretName : raycluster .Name + "-proxy-tls-secret" ,
114+ tlsSecretVolume := corev1.Volume {
115+ Name : "proxy-tls-secret" ,
116+ VolumeSource : corev1.VolumeSource {
117+ Secret : & corev1.SecretVolumeSource {
118+ SecretName : raycluster .Name + "-proxy-tls-secret" ,
119+ },
111120 },
112- },
113- }
121+ }
114122
115- raycluster .Spec .HeadGroupSpec .Template .Spec .Volumes = append (raycluster .Spec .HeadGroupSpec .Template .Spec .Volumes , tlsSecretVolume )
123+ raycluster .Spec .HeadGroupSpec .Template .Spec .Volumes = append (raycluster .Spec .HeadGroupSpec .Template .Spec .Volumes , tlsSecretVolume )
116124
117- // Ensure the service account is set
118- if raycluster .Spec .HeadGroupSpec .Template .Spec .ServiceAccountName == "" {
119- raycluster .Spec .HeadGroupSpec .Template .Spec .ServiceAccountName = raycluster .Name + "-oauth-proxy"
125+ // Ensure the service account is set
126+ if raycluster .Spec .HeadGroupSpec .Template .Spec .ServiceAccountName == "" {
127+ raycluster .Spec .HeadGroupSpec .Template .Spec .ServiceAccountName = raycluster .Name + "-oauth-proxy"
128+ }
120129 }
121130 }
122131 return nil
0 commit comments