@@ -38,14 +38,16 @@ const (
38
38
oauthProxyContainerName = "oauth-proxy"
39
39
oauthProxyVolumeName = "proxy-tls-secret"
40
40
initContainerName = "create-cert"
41
+ versionAnnotation = "ray.openshift.ai/version"
41
42
)
42
43
43
44
// log is for logging in this package.
44
45
var rayclusterlog = logf .Log .WithName ("raycluster-resource" )
45
46
46
- func SetupRayClusterWebhookWithManager (mgr ctrl.Manager , cfg * config.KubeRayConfiguration ) error {
47
+ func SetupRayClusterWebhookWithManager (mgr ctrl.Manager , cfg * config.KubeRayConfiguration , operatorVersion string ) error {
47
48
rayClusterWebhookInstance := & rayClusterWebhook {
48
- Config : cfg ,
49
+ Config : cfg ,
50
+ OperatorVersion : operatorVersion ,
49
51
}
50
52
return ctrl .NewWebhookManagedBy (mgr ).
51
53
For (& rayv1.RayCluster {}).
@@ -58,23 +60,33 @@ func SetupRayClusterWebhookWithManager(mgr ctrl.Manager, cfg *config.KubeRayConf
58
60
// +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
59
61
60
62
type rayClusterWebhook struct {
61
- Config * config.KubeRayConfiguration
63
+ Config * config.KubeRayConfiguration
64
+ OperatorVersion string
62
65
}
63
66
64
67
var _ webhook.CustomDefaulter = & rayClusterWebhook {}
65
68
var _ webhook.CustomValidator = & rayClusterWebhook {}
66
69
67
70
// Default implements webhook.Defaulter so a webhook will be registered for the type
68
71
func (w * rayClusterWebhook ) Default (ctx context.Context , obj runtime.Object ) error {
72
+ logger := ctrl .LoggerFrom (ctx )
69
73
rayCluster := obj .(* rayv1.RayCluster )
70
74
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 ())
71
83
if ptr .Deref (w .Config .RayDashboardOAuthEnabled , true ) {
72
84
rayclusterlog .V (2 ).Info ("Adding OAuth sidecar container" )
73
85
rayCluster .Spec .HeadGroupSpec .Template .Spec .Containers = upsert (rayCluster .Spec .HeadGroupSpec .Template .Spec .Containers , oauthProxyContainer (rayCluster ), withContainerName (oauthProxyContainerName ))
74
86
75
87
rayCluster .Spec .HeadGroupSpec .Template .Spec .Volumes = upsert (rayCluster .Spec .HeadGroupSpec .Template .Spec .Volumes , oauthProxyTLSSecretVolume (rayCluster ), withVolumeName (oauthProxyVolumeName ))
76
88
77
- rayCluster .Spec .HeadGroupSpec .Template .Spec .ServiceAccountName = rayCluster . Name + "-oauth-proxy"
89
+ rayCluster .Spec .HeadGroupSpec .Template .Spec .ServiceAccountName = oauthServiceAccountNameFromCluster ( rayCluster )
78
90
}
79
91
80
92
if ptr .Deref (w .Config .MTLSEnabled , true ) {
@@ -218,7 +230,7 @@ func validateIngress(rayCluster *rayv1.RayCluster) field.ErrorList {
218
230
func validateHeadGroupServiceAccountName (rayCluster * rayv1.RayCluster ) field.ErrorList {
219
231
var allErrors field.ErrorList
220
232
221
- if rayCluster .Spec .HeadGroupSpec .Template .Spec .ServiceAccountName != rayCluster . Name + "-oauth-proxy" {
233
+ if rayCluster .Spec .HeadGroupSpec .Template .Spec .ServiceAccountName != oauthServiceAccountNameFromCluster ( rayCluster ) {
222
234
allErrors = append (allErrors , field .Invalid (
223
235
field .NewPath ("spec" , "headGroupSpec" , "template" , "spec" , "serviceAccountName" ),
224
236
rayCluster .Spec .HeadGroupSpec .Template .Spec .ServiceAccountName ,
@@ -241,7 +253,7 @@ func oauthProxyContainer(rayCluster *rayv1.RayCluster) corev1.Container {
241
253
ValueFrom : & corev1.EnvVarSource {
242
254
SecretKeyRef : & corev1.SecretKeySelector {
243
255
LocalObjectReference : corev1.LocalObjectReference {
244
- Name : rayCluster . Name + "-oauth-config" ,
256
+ Name : oauthSecretNameFromCluster ( rayCluster ) ,
245
257
},
246
258
Key : "cookie_secret" ,
247
259
},
@@ -251,7 +263,7 @@ func oauthProxyContainer(rayCluster *rayv1.RayCluster) corev1.Container {
251
263
Args : []string {
252
264
"--https-address=:8443" ,
253
265
"--provider=openshift" ,
254
- "--openshift-service-account=" + rayCluster . Name + "-oauth-proxy" ,
266
+ "--openshift-service-account=" + oauthServiceAccountNameFromCluster ( rayCluster ) ,
255
267
"--upstream=http://localhost:8265" ,
256
268
"--tls-cert=/etc/tls/private/tls.crt" ,
257
269
"--tls-key=/etc/tls/private/tls.key" ,
@@ -273,7 +285,7 @@ func oauthProxyTLSSecretVolume(rayCluster *rayv1.RayCluster) corev1.Volume {
273
285
Name : oauthProxyVolumeName ,
274
286
VolumeSource : corev1.VolumeSource {
275
287
Secret : & corev1.SecretVolumeSource {
276
- SecretName : rayCluster . Name + "-proxy-tls-secret" ,
288
+ SecretName : oauthServiceTLSSecretName ( rayCluster ) ,
277
289
},
278
290
},
279
291
}
@@ -329,7 +341,7 @@ func caVolumes(rayCluster *rayv1.RayCluster) []corev1.Volume {
329
341
Name : "ca-vol" ,
330
342
VolumeSource : corev1.VolumeSource {
331
343
Secret : & corev1.SecretVolumeSource {
332
- SecretName : `ca-secret-` + rayCluster . Name ,
344
+ SecretName : caSecretNameFromCluster ( rayCluster ) ,
333
345
},
334
346
},
335
347
},
@@ -343,9 +355,9 @@ func caVolumes(rayCluster *rayv1.RayCluster) []corev1.Volume {
343
355
}
344
356
345
357
func 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
347
359
// Service name for basic interactive
348
- svcDomain := rayCluster . Name + "-head-svc ." + rayCluster .Namespace + ".svc"
360
+ svcDomain := serviceNameFromCluster ( rayCluster ) + "." + rayCluster .Namespace + ".svc"
349
361
350
362
initContainerHead := corev1.Container {
351
363
Name : "create-cert" ,
0 commit comments