@@ -147,11 +147,21 @@ func main() {
147
147
})
148
148
exitOnError (err , "unable to start manager" )
149
149
150
- exitOnError ( controllers . SetupRayClusterWebhookWithManager ( mgr , cfg . KubeRay ), "error setting up RayCluster webhook" )
150
+ OpenShift := isOpenShift ( ctx , kubeClient . DiscoveryClient )
151
151
152
- ok , err := HasAPIResourceForGVK (kubeClient .DiscoveryClient , rayv1 .GroupVersion .WithKind ("RayCluster" ))
152
+ if OpenShift {
153
+ // TODO: setup the RayCluster webhook on vanilla Kubernetes
154
+ exitOnError (controllers .SetupRayClusterWebhookWithManager (mgr , cfg .KubeRay ), "error setting up RayCluster webhook" )
155
+ }
156
+
157
+ ok , err := hasAPIResourceForGVK (kubeClient .DiscoveryClient , rayv1 .GroupVersion .WithKind ("RayCluster" ))
153
158
if ok {
154
- rayClusterController := controllers.RayClusterReconciler {Client : mgr .GetClient (), Scheme : mgr .GetScheme (), Config : cfg .KubeRay }
159
+ rayClusterController := controllers.RayClusterReconciler {
160
+ Client : mgr .GetClient (),
161
+ Scheme : mgr .GetScheme (),
162
+ Config : cfg .KubeRay ,
163
+ IsOpenShift : OpenShift ,
164
+ }
155
165
exitOnError (rayClusterController .SetupWithManager (mgr ), "Error setting up RayCluster controller" )
156
166
} else if err != nil {
157
167
exitOnError (err , "Could not determine if RayCluster CR present on cluster." )
@@ -207,7 +217,7 @@ func createConfigMap(ctx context.Context, client kubernetes.Interface, ns, name
207
217
return err
208
218
}
209
219
210
- func HasAPIResourceForGVK (dc discovery.DiscoveryInterface , gvk schema.GroupVersionKind ) (bool , error ) {
220
+ func hasAPIResourceForGVK (dc discovery.DiscoveryInterface , gvk schema.GroupVersionKind ) (bool , error ) {
211
221
gv , kind := gvk .ToAPIVersionAndKind ()
212
222
if resources , err := dc .ServerResourcesForGroupVersion (gv ); err != nil {
213
223
if apierrors .IsNotFound (err ) {
@@ -247,3 +257,20 @@ func exitOnError(err error, msg string) {
247
257
os .Exit (1 )
248
258
}
249
259
}
260
+
261
+ func isOpenShift (ctx context.Context , dc discovery.DiscoveryInterface ) bool {
262
+ logger := ctrl .LoggerFrom (ctx )
263
+ apiGroupList , err := dc .ServerGroups ()
264
+ if err != nil {
265
+ logger .Info ("Error while querying ServerGroups, assuming we're on Vanilla Kubernetes" )
266
+ return false
267
+ }
268
+ for i := 0 ; i < len (apiGroupList .Groups ); i ++ {
269
+ if strings .HasSuffix (apiGroupList .Groups [i ].Name , ".openshift.io" ) {
270
+ logger .Info ("We detected being on OpenShift!" )
271
+ return true
272
+ }
273
+ }
274
+ logger .Info ("We detected being on Vanilla Kubernetes!" )
275
+ return false
276
+ }
0 commit comments