@@ -21,6 +21,7 @@ import (
21
21
22
22
rayv1 "github.com/ray-project/kuberay/ray-operator/apis/ray/v1"
23
23
24
+ "github.com/project-codeflare/codeflare-operator/pkg/config"
24
25
corev1 "k8s.io/api/core/v1"
25
26
"k8s.io/apimachinery/pkg/runtime"
26
27
ctrl "sigs.k8s.io/controller-runtime"
@@ -34,89 +35,97 @@ var rayclusterlog = logf.Log.WithName("raycluster-resource")
34
35
func (r * RayClusterDefaulter ) SetupWebhookWithManager (mgr ctrl.Manager ) error {
35
36
return ctrl .NewWebhookManagedBy (mgr ).
36
37
For (& rayv1.RayCluster {}).
37
- WithDefaulter (& RayClusterDefaulter {}).
38
+ WithDefaulter (& RayClusterDefaulter {
39
+ Config : r .Config ,
40
+ rayDashboardOauthEnabled : r .isRayDashboardOAuthEnabledWebhook (),
41
+ }).
38
42
Complete ()
39
43
}
40
44
41
45
//+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
42
46
43
- type RayClusterDefaulter struct {}
47
+ type RayClusterDefaulter struct {
48
+ Config * config.KubeRayConfiguration
49
+ rayDashboardOauthEnabled bool
50
+ }
44
51
45
52
var _ webhook.CustomDefaulter = & RayClusterDefaulter {}
46
53
47
54
// Default implements webhook.Defaulter so a webhook will be registered for the type
48
55
func (r * RayClusterDefaulter ) Default (ctx context.Context , obj runtime.Object ) error {
49
56
raycluster := obj .(* rayv1.RayCluster )
50
57
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
+ }
59
68
}
60
- }
61
69
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" ,
88
98
},
89
- Key : "cookie_secret" ,
90
99
},
91
100
},
92
101
},
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
+ } ,
99
108
},
100
- },
101
- }
109
+ }
102
110
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 )
105
113
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
+ },
111
120
},
112
- },
113
- }
121
+ }
114
122
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 )
116
124
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
+ }
120
129
}
121
130
}
122
131
return nil
0 commit comments