Skip to content

Commit

Permalink
Fix improper controller-runtime cache configuration
Browse files Browse the repository at this point in the history
When AppWrappers are enabled, it is not correct to configure
the controller-runtime cache with a filter that only allows
services, secrets, etc with the RayCluster label to be cached.
This breaks any AppWrapper that contains one of these resource kinds.
  • Loading branch information
dgrove-oss authored and openshift-merge-bot[bot] committed Dec 16, 2024
1 parent c028863 commit 9c96f44
Showing 1 changed file with 26 additions and 28 deletions.
54 changes: 26 additions & 28 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,36 +171,34 @@ func main() {
kubeConfig.QPS = ptr.Deref(cfg.ClientConnection.QPS, rest.DefaultQPS)
setupLog.V(2).Info("REST client", "qps", kubeConfig.QPS, "burst", kubeConfig.Burst)

selector, err := labels.Parse(controllers.RayClusterNameLabel)
exitOnError(err, "unable to parse label selector")

cacheOpts := cache.Options{
ByObject: map[client.Object]cache.ByObject{
&corev1.Secret{}: {
Label: selector,
},
&corev1.Service{}: {
Label: selector,
},
&corev1.ServiceAccount{}: {
Label: selector,
},
&networkingv1.Ingress{}: {
Label: selector,
},
&networkingv1.NetworkPolicy{}: {
Label: selector,
},
&rbacv1.ClusterRoleBinding{}: {
Label: selector,
},
},
}

if isOpenShift(ctx, kubeClient.DiscoveryClient) {
cacheOpts.ByObject[&routev1.Route{}] = cache.ByObject{
cacheOpts := cache.Options{}
if cfg.AppWrapper == nil || !ptr.Deref(cfg.AppWrapper.Enabled, false) {
selector, err := labels.Parse(controllers.RayClusterNameLabel)
exitOnError(err, "unable to parse label selector")
cacheOpts.ByObject = make(map[client.Object]cache.ByObject, 7)
cacheOpts.ByObject[&corev1.Secret{}] = cache.ByObject{
Label: selector,
}
cacheOpts.ByObject[&corev1.Service{}] = cache.ByObject{
Label: selector,
}
cacheOpts.ByObject[&corev1.ServiceAccount{}] = cache.ByObject{
Label: selector,
}
cacheOpts.ByObject[&networkingv1.Ingress{}] = cache.ByObject{
Label: selector,
}
cacheOpts.ByObject[&networkingv1.NetworkPolicy{}] = cache.ByObject{
Label: selector,
}
cacheOpts.ByObject[&rbacv1.ClusterRoleBinding{}] = cache.ByObject{
Label: selector,
}
if isOpenShift(ctx, kubeClient.DiscoveryClient) {
cacheOpts.ByObject[&routev1.Route{}] = cache.ByObject{
Label: selector,
}
}
}

mgr, err := ctrl.NewManager(kubeConfig, ctrl.Options{
Expand Down

0 comments on commit 9c96f44

Please sign in to comment.