@@ -38,14 +38,16 @@ const (
3838 oauthProxyContainerName = "oauth-proxy"
3939 oauthProxyVolumeName = "proxy-tls-secret"
4040 initContainerName = "create-cert"
41+ versionAnnotation = "ray.openshift.ai/version"
4142)
4243
4344// log is for logging in this package.
4445var rayclusterlog = logf .Log .WithName ("raycluster-resource" )
4546
46- func SetupRayClusterWebhookWithManager (mgr ctrl.Manager , cfg * config.KubeRayConfiguration ) error {
47+ func SetupRayClusterWebhookWithManager (mgr ctrl.Manager , cfg * config.KubeRayConfiguration , operatorVersion string ) error {
4748 rayClusterWebhookInstance := & rayClusterWebhook {
48- Config : cfg ,
49+ Config : cfg ,
50+ OperatorVersion : operatorVersion ,
4951 }
5052 return ctrl .NewWebhookManagedBy (mgr ).
5153 For (& rayv1.RayCluster {}).
@@ -58,23 +60,33 @@ func SetupRayClusterWebhookWithManager(mgr ctrl.Manager, cfg *config.KubeRayConf
5860// +kubebuilder:webhook:path=/validate-ray-io-v1-raycluster,mutating=false,failurePolicy=fail,sideEffects=None,groups=ray.io,resources=rayclusters,verbs=create;update,versions=v1,name=vraycluster.ray.openshift.ai,admissionReviewVersions=v1
5961
6062type rayClusterWebhook struct {
61- Config * config.KubeRayConfiguration
63+ Config * config.KubeRayConfiguration
64+ OperatorVersion string
6265}
6366
6467var _ webhook.CustomDefaulter = & rayClusterWebhook {}
6568var _ webhook.CustomValidator = & rayClusterWebhook {}
6669
6770// Default implements webhook.Defaulter so a webhook will be registered for the type
6871func (w * rayClusterWebhook ) Default (ctx context.Context , obj runtime.Object ) error {
72+ logger := ctrl .LoggerFrom (ctx )
6973 rayCluster := obj .(* rayv1.RayCluster )
7074
75+ // add annotation to use new names
76+ annotations := rayCluster .GetAnnotations ()
77+ if annotations == nil {
78+ annotations = make (map [string ]string )
79+ }
80+ annotations [versionAnnotation ] = w .OperatorVersion
81+ rayCluster .SetAnnotations (annotations )
82+ logger .Info ("Ray Cluster annotations" , "annotations" , rayCluster .GetAnnotations ())
7183 if ptr .Deref (w .Config .RayDashboardOAuthEnabled , true ) {
7284 rayclusterlog .V (2 ).Info ("Adding OAuth sidecar container" )
7385 rayCluster .Spec .HeadGroupSpec .Template .Spec .Containers = upsert (rayCluster .Spec .HeadGroupSpec .Template .Spec .Containers , oauthProxyContainer (rayCluster ), withContainerName (oauthProxyContainerName ))
7486
7587 rayCluster .Spec .HeadGroupSpec .Template .Spec .Volumes = upsert (rayCluster .Spec .HeadGroupSpec .Template .Spec .Volumes , oauthProxyTLSSecretVolume (rayCluster ), withVolumeName (oauthProxyVolumeName ))
7688
77- rayCluster .Spec .HeadGroupSpec .Template .Spec .ServiceAccountName = rayCluster . Name + "-oauth-proxy"
89+ rayCluster .Spec .HeadGroupSpec .Template .Spec .ServiceAccountName = oauthServiceAccountNameFromCluster ( rayCluster )
7890 }
7991
8092 if ptr .Deref (w .Config .MTLSEnabled , true ) {
@@ -218,7 +230,7 @@ func validateIngress(rayCluster *rayv1.RayCluster) field.ErrorList {
218230func validateHeadGroupServiceAccountName (rayCluster * rayv1.RayCluster ) field.ErrorList {
219231 var allErrors field.ErrorList
220232
221- if rayCluster .Spec .HeadGroupSpec .Template .Spec .ServiceAccountName != rayCluster . Name + "-oauth-proxy" {
233+ if rayCluster .Spec .HeadGroupSpec .Template .Spec .ServiceAccountName != oauthServiceAccountNameFromCluster ( rayCluster ) {
222234 allErrors = append (allErrors , field .Invalid (
223235 field .NewPath ("spec" , "headGroupSpec" , "template" , "spec" , "serviceAccountName" ),
224236 rayCluster .Spec .HeadGroupSpec .Template .Spec .ServiceAccountName ,
@@ -241,7 +253,7 @@ func oauthProxyContainer(rayCluster *rayv1.RayCluster) corev1.Container {
241253 ValueFrom : & corev1.EnvVarSource {
242254 SecretKeyRef : & corev1.SecretKeySelector {
243255 LocalObjectReference : corev1.LocalObjectReference {
244- Name : rayCluster . Name + "-oauth-config" ,
256+ Name : oauthSecretNameFromCluster ( rayCluster ) ,
245257 },
246258 Key : "cookie_secret" ,
247259 },
@@ -251,7 +263,7 @@ func oauthProxyContainer(rayCluster *rayv1.RayCluster) corev1.Container {
251263 Args : []string {
252264 "--https-address=:8443" ,
253265 "--provider=openshift" ,
254- "--openshift-service-account=" + rayCluster . Name + "-oauth-proxy" ,
266+ "--openshift-service-account=" + oauthServiceAccountNameFromCluster ( rayCluster ) ,
255267 "--upstream=http://localhost:8265" ,
256268 "--tls-cert=/etc/tls/private/tls.crt" ,
257269 "--tls-key=/etc/tls/private/tls.key" ,
@@ -273,7 +285,7 @@ func oauthProxyTLSSecretVolume(rayCluster *rayv1.RayCluster) corev1.Volume {
273285 Name : oauthProxyVolumeName ,
274286 VolumeSource : corev1.VolumeSource {
275287 Secret : & corev1.SecretVolumeSource {
276- SecretName : rayCluster . Name + "-proxy-tls-secret" ,
288+ SecretName : oauthServiceTLSSecretName ( rayCluster ) ,
277289 },
278290 },
279291 }
@@ -329,7 +341,7 @@ func caVolumes(rayCluster *rayv1.RayCluster) []corev1.Volume {
329341 Name : "ca-vol" ,
330342 VolumeSource : corev1.VolumeSource {
331343 Secret : & corev1.SecretVolumeSource {
332- SecretName : `ca-secret-` + rayCluster . Name ,
344+ SecretName : caSecretNameFromCluster ( rayCluster ) ,
333345 },
334346 },
335347 },
@@ -343,9 +355,9 @@ func caVolumes(rayCluster *rayv1.RayCluster) []corev1.Volume {
343355}
344356
345357func rayHeadInitContainer (rayCluster * rayv1.RayCluster , config * config.KubeRayConfiguration ) corev1.Container {
346- rayClientRoute := "rayclient-" + rayCluster . Name + "-" + rayCluster .Namespace + "." + config .IngressDomain
358+ rayClientRoute := rayClientNameFromCluster ( rayCluster ) + "-" + rayCluster .Namespace + "." + config .IngressDomain
347359 // Service name for basic interactive
348- svcDomain := rayCluster . Name + "-head-svc ." + rayCluster .Namespace + ".svc"
360+ svcDomain := serviceNameFromCluster ( rayCluster ) + "." + rayCluster .Namespace + ".svc"
349361
350362 initContainerHead := corev1.Container {
351363 Name : "create-cert" ,
0 commit comments