@@ -26,6 +26,8 @@ import (
26
26
ctrl "sigs.k8s.io/controller-runtime"
27
27
logf "sigs.k8s.io/controller-runtime/pkg/log"
28
28
"sigs.k8s.io/controller-runtime/pkg/webhook"
29
+
30
+ "github.com/project-codeflare/codeflare-operator/pkg/config"
29
31
)
30
32
31
33
// log is for logging in this package.
@@ -34,89 +36,97 @@ var rayclusterlog = logf.Log.WithName("raycluster-resource")
34
36
func (r * RayClusterDefaulter ) SetupWebhookWithManager (mgr ctrl.Manager ) error {
35
37
return ctrl .NewWebhookManagedBy (mgr ).
36
38
For (& rayv1.RayCluster {}).
37
- WithDefaulter (& RayClusterDefaulter {}).
39
+ WithDefaulter (& RayClusterDefaulter {
40
+ Config : r .Config ,
41
+ rayDashboardOauthEnabled : r .isRayDashboardOAuthEnabledWebhook (),
42
+ }).
38
43
Complete ()
39
44
}
40
45
41
46
//+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
47
43
- type RayClusterDefaulter struct {}
48
+ type RayClusterDefaulter struct {
49
+ Config * config.KubeRayConfiguration
50
+ rayDashboardOauthEnabled bool
51
+ }
44
52
45
53
var _ webhook.CustomDefaulter = & RayClusterDefaulter {}
46
54
47
55
// Default implements webhook.Defaulter so a webhook will be registered for the type
48
56
func (r * RayClusterDefaulter ) Default (ctx context.Context , obj runtime.Object ) error {
49
57
raycluster := obj .(* rayv1.RayCluster )
50
58
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
59
+ if r .rayDashboardOauthEnabled {
60
+ rayclusterlog .Info ("default" , "name" , raycluster .Name )
61
+ // Check and add OAuth proxy if it does not exist.
62
+ alreadyExists := false
63
+ for _ , container := range raycluster .Spec .HeadGroupSpec .Template .Spec .Containers {
64
+ if container .Name == "oauth-proxy" {
65
+ rayclusterlog .Info ("OAuth sidecar already exists, no patch needed" )
66
+ alreadyExists = true
67
+ break // exits the for loop
68
+ }
59
69
}
60
- }
61
70
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" ,
71
+ if ! alreadyExists {
72
+ rayclusterlog .Info ("Adding OAuth sidecar container" )
73
+ // definition of the new container
74
+ newOAuthSidecar := corev1.Container {
75
+ Name : "oauth-proxy" ,
76
+ Image : "registry.redhat.io/openshift4/ose-oauth-proxy@sha256:1ea6a01bf3e63cdcf125c6064cbd4a4a270deaf0f157b3eabb78f60556840366" ,
77
+ Ports : []corev1.ContainerPort {
78
+ {ContainerPort : 8443 , Name : "oauth-proxy" },
79
+ },
80
+ Args : []string {
81
+ "--https-address=:8443" ,
82
+ "--provider=openshift" ,
83
+ "--openshift-service-account=" + raycluster .Name + "-oauth-proxy" ,
84
+ "--upstream=http://localhost:8265" ,
85
+ "--tls-cert=/etc/tls/private/tls.crt" ,
86
+ "--tls-key=/etc/tls/private/tls.key" ,
87
+ "--cookie-secret=$(COOKIE_SECRET)" ,
88
+ "--openshift-delegate-urls={\" /\" :{\" resource\" :\" pods\" ,\" namespace\" :\" default\" ,\" verb\" :\" get\" }}" ,
89
+ },
90
+ Env : []corev1.EnvVar {
91
+ {
92
+ Name : "COOKIE_SECRET" ,
93
+ ValueFrom : & corev1.EnvVarSource {
94
+ SecretKeyRef : & corev1.SecretKeySelector {
95
+ LocalObjectReference : corev1.LocalObjectReference {
96
+ Name : raycluster .Name + "-oauth-config" ,
97
+ },
98
+ Key : "cookie_secret" ,
88
99
},
89
- Key : "cookie_secret" ,
90
100
},
91
101
},
92
102
},
93
- },
94
- VolumeMounts : []corev1. VolumeMount {
95
- {
96
- Name : "proxy- tls-secret " ,
97
- MountPath : "/etc/tls/private" ,
98
- ReadOnly : true ,
103
+ VolumeMounts : []corev1. VolumeMount {
104
+ {
105
+ Name : "proxy-tls-secret" ,
106
+ MountPath : "/etc/ tls/private " ,
107
+ ReadOnly : true ,
108
+ } ,
99
109
},
100
- },
101
- }
110
+ }
102
111
103
- // Adding the new OAuth sidecar container
104
- raycluster .Spec .HeadGroupSpec .Template .Spec .Containers = append (raycluster .Spec .HeadGroupSpec .Template .Spec .Containers , newOAuthSidecar )
112
+ // Adding the new OAuth sidecar container
113
+ raycluster .Spec .HeadGroupSpec .Template .Spec .Containers = append (raycluster .Spec .HeadGroupSpec .Template .Spec .Containers , newOAuthSidecar )
105
114
106
- tlsSecretVolume := corev1.Volume {
107
- Name : "proxy-tls-secret" ,
108
- VolumeSource : corev1.VolumeSource {
109
- Secret : & corev1.SecretVolumeSource {
110
- SecretName : raycluster .Name + "-proxy-tls-secret" ,
115
+ tlsSecretVolume := corev1.Volume {
116
+ Name : "proxy-tls-secret" ,
117
+ VolumeSource : corev1.VolumeSource {
118
+ Secret : & corev1.SecretVolumeSource {
119
+ SecretName : raycluster .Name + "-proxy-tls-secret" ,
120
+ },
111
121
},
112
- },
113
- }
122
+ }
114
123
115
- raycluster .Spec .HeadGroupSpec .Template .Spec .Volumes = append (raycluster .Spec .HeadGroupSpec .Template .Spec .Volumes , tlsSecretVolume )
124
+ raycluster .Spec .HeadGroupSpec .Template .Spec .Volumes = append (raycluster .Spec .HeadGroupSpec .Template .Spec .Volumes , tlsSecretVolume )
116
125
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"
126
+ // Ensure the service account is set
127
+ if raycluster .Spec .HeadGroupSpec .Template .Spec .ServiceAccountName == "" {
128
+ raycluster .Spec .HeadGroupSpec .Template .Spec .ServiceAccountName = raycluster .Name + "-oauth-proxy"
129
+ }
120
130
}
121
131
}
122
132
return nil
0 commit comments