@@ -262,7 +262,7 @@ 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 , kubeRayNamespaces ), metav1.ApplyOptions {FieldManager : controllerName , Force : true })
265
+ _ , err = r .kubeClient .NetworkingV1 ().NetworkPolicies (cluster .Namespace ).Apply (ctx , desiredNetworkPolicy (cluster , r . Config , kubeRayNamespaces ), metav1.ApplyOptions {FieldManager : controllerName , Force : true })
266
266
if err != nil {
267
267
logger .Error (err , "Failed to update NetworkPolicy" )
268
268
}
@@ -460,7 +460,13 @@ func generateCACertificate() ([]byte, []byte, error) {
460
460
return privateKeyPem , certPem , nil
461
461
}
462
462
463
- func desiredNetworkPolicy (cluster * rayv1.RayCluster , kubeRayNamespaces []string ) * networkingv1ac.NetworkPolicyApplyConfiguration {
463
+ func desiredNetworkPolicy (cluster * rayv1.RayCluster , cfg * config.KubeRayConfiguration , kubeRayNamespaces []string ) * networkingv1ac.NetworkPolicyApplyConfiguration {
464
+ allSecuredPorts := []* networkingv1ac.NetworkPolicyPortApplyConfiguration {
465
+ networkingv1ac .NetworkPolicyPort ().WithProtocol (corev1 .ProtocolTCP ).WithPort (intstr .FromInt (8443 )),
466
+ }
467
+ if ptr .Deref (cfg .MTLSEnabled , true ) {
468
+ allSecuredPorts = append (allSecuredPorts , networkingv1ac .NetworkPolicyPort ().WithProtocol (corev1 .ProtocolTCP ).WithPort (intstr .FromInt (10001 )))
469
+ }
464
470
return networkingv1ac .NetworkPolicy (cluster .Name , cluster .Namespace ).
465
471
WithLabels (map [string ]string {"ray.io/cluster-name" : cluster .Name }).
466
472
WithSpec (networkingv1ac .NetworkPolicySpec ().
@@ -501,8 +507,7 @@ func desiredNetworkPolicy(cluster *rayv1.RayCluster, kubeRayNamespaces []string)
501
507
),
502
508
networkingv1ac .NetworkPolicyIngressRule ().
503
509
WithPorts (
504
- networkingv1ac .NetworkPolicyPort ().WithProtocol (corev1 .ProtocolTCP ).WithPort (intstr .FromInt (8443 )),
505
- networkingv1ac .NetworkPolicyPort ().WithProtocol (corev1 .ProtocolTCP ).WithPort (intstr .FromInt (10001 )),
510
+ allSecuredPorts ... ,
506
511
),
507
512
),
508
513
).
0 commit comments