@@ -262,7 +262,12 @@ func (r *RayClusterReconciler) Reconcile(ctx context.Context, req ctrl.Request)
262
262
kubeRayNamespaces = []string {dsci .Spec .ApplicationsNamespace }
263
263
}
264
264
265
- _ , err = r .kubeClient .NetworkingV1 ().NetworkPolicies (cluster .Namespace ).Apply (ctx , desiredNetworkPolicy (cluster , r .Config , kubeRayNamespaces ), metav1.ApplyOptions {FieldManager : controllerName , Force : true })
265
+ _ , err = r .kubeClient .NetworkingV1 ().NetworkPolicies (cluster .Namespace ).Apply (ctx , desiredHeadNetworkPolicy (cluster , r .Config , kubeRayNamespaces ), metav1.ApplyOptions {FieldManager : controllerName , Force : true })
266
+ if err != nil {
267
+ logger .Error (err , "Failed to update NetworkPolicy" )
268
+ }
269
+
270
+ _ , err = r .kubeClient .NetworkingV1 ().NetworkPolicies (cluster .Namespace ).Apply (ctx , desiredWorkersNetworkPolicy (cluster ), metav1.ApplyOptions {FieldManager : controllerName , Force : true })
266
271
if err != nil {
267
272
logger .Error (err , "Failed to update NetworkPolicy" )
268
273
}
@@ -459,24 +464,41 @@ func generateCACertificate() ([]byte, []byte, error) {
459
464
460
465
return privateKeyPem , certPem , nil
461
466
}
462
-
463
- func desiredNetworkPolicy (cluster * rayv1.RayCluster , cfg * config.KubeRayConfiguration , kubeRayNamespaces []string ) * networkingv1ac.NetworkPolicyApplyConfiguration {
467
+ func desiredWorkersNetworkPolicy (cluster * rayv1.RayCluster ) * networkingv1ac.NetworkPolicyApplyConfiguration {
468
+ return networkingv1ac .NetworkPolicy (cluster .Name + "-workers" , cluster .Namespace ).
469
+ WithLabels (map [string ]string {"ray.io/cluster-name" : cluster .Name }).
470
+ WithSpec (networkingv1ac .NetworkPolicySpec ().
471
+ WithPodSelector (metav1ac .LabelSelector ().WithMatchLabels (map [string ]string {"ray.io/cluster" : cluster .Name , "ray.io/node-type" : "worker" })).
472
+ WithIngress (
473
+ networkingv1ac .NetworkPolicyIngressRule ().
474
+ WithFrom (
475
+ networkingv1ac .NetworkPolicyPeer ().WithPodSelector (metav1ac .LabelSelector ().WithMatchLabels (map [string ]string {"ray.io/cluster" : cluster .Name })),
476
+ ),
477
+ ),
478
+ ).
479
+ WithOwnerReferences (
480
+ metav1ac .OwnerReference ().WithUID (cluster .UID ).WithName (cluster .Name ).WithKind (cluster .Kind ).WithAPIVersion (cluster .APIVersion ),
481
+ )
482
+ }
483
+ func desiredHeadNetworkPolicy (cluster * rayv1.RayCluster , cfg * config.KubeRayConfiguration , kubeRayNamespaces []string ) * networkingv1ac.NetworkPolicyApplyConfiguration {
464
484
allSecuredPorts := []* networkingv1ac.NetworkPolicyPortApplyConfiguration {
465
485
networkingv1ac .NetworkPolicyPort ().WithProtocol (corev1 .ProtocolTCP ).WithPort (intstr .FromInt (8443 )),
466
486
}
467
487
if ptr .Deref (cfg .MTLSEnabled , true ) {
468
488
allSecuredPorts = append (allSecuredPorts , networkingv1ac .NetworkPolicyPort ().WithProtocol (corev1 .ProtocolTCP ).WithPort (intstr .FromInt (10001 )))
469
489
}
470
- return networkingv1ac .NetworkPolicy (cluster .Name , cluster .Namespace ).
490
+ return networkingv1ac .NetworkPolicy (cluster .Name + "-head" , cluster .Namespace ).
471
491
WithLabels (map [string ]string {"ray.io/cluster-name" : cluster .Name }).
472
492
WithSpec (networkingv1ac .NetworkPolicySpec ().
473
493
WithPodSelector (metav1ac .LabelSelector ().WithMatchLabels (map [string ]string {"ray.io/cluster" : cluster .Name , "ray.io/node-type" : "head" })).
474
494
WithIngress (
495
+ networkingv1ac .NetworkPolicyIngressRule ().
496
+ WithFrom (
497
+ networkingv1ac .NetworkPolicyPeer ().WithPodSelector (metav1ac .LabelSelector ().WithMatchLabels (map [string ]string {"ray.io/cluster" : cluster .Name })),
498
+ ),
475
499
networkingv1ac .NetworkPolicyIngressRule ().
476
500
WithPorts (
477
- networkingv1ac .NetworkPolicyPort ().WithProtocol (corev1 .ProtocolTCP ).WithPort (intstr .FromInt (6379 )),
478
501
networkingv1ac .NetworkPolicyPort ().WithProtocol (corev1 .ProtocolTCP ).WithPort (intstr .FromInt (10001 )),
479
- networkingv1ac .NetworkPolicyPort ().WithProtocol (corev1 .ProtocolTCP ).WithPort (intstr .FromInt (8080 )),
480
502
networkingv1ac .NetworkPolicyPort ().WithProtocol (corev1 .ProtocolTCP ).WithPort (intstr .FromInt (8265 )),
481
503
).WithFrom (
482
504
networkingv1ac .NetworkPolicyPeer ().WithPodSelector (metav1ac .LabelSelector ()),
0 commit comments