@@ -395,6 +395,23 @@ func (r *CodeServerReconciler) reconcileService(ctx context.Context, codeServer
395395		return  fmt .Errorf ("failed to create controller reference: %w" , err )
396396	}
397397
398+ 	ports  :=  []* corev1apply.ServicePortApplyConfiguration {
399+ 		corev1apply .ServicePort ().
400+ 			WithName ("http" ).
401+ 			WithProtocol (corev1 .ProtocolTCP ).
402+ 			WithPort (codeServer .Spec .ContainerPort ).
403+ 			WithTargetPort (intstr .FromInt32 (codeServer .Spec .ContainerPort )),
404+ 	}
405+ 
406+ 	for  _ , port  :=  range  codeServer .Spec .PublicProxyPorts  {
407+ 		ports  =  append (ports , corev1apply .ServicePort ().
408+ 			WithName (fmt .Sprintf ("http-%d" , port )).
409+ 			WithProtocol (corev1 .ProtocolTCP ).
410+ 			WithPort (port ).
411+ 			WithTargetPort (intstr .FromInt32 (port )),
412+ 		)
413+ 	}
414+ 
398415	service  :=  corev1apply .Service (codeServer .Name , codeServer .Namespace ).
399416		WithLabels (map [string ]string {
400417			"app.kubernetes.io/name" :       CodeServer ,
@@ -404,11 +421,7 @@ func (r *CodeServerReconciler) reconcileService(ctx context.Context, codeServer
404421		WithOwnerReferences (owner ).
405422		WithSpec (corev1apply .ServiceSpec ().
406423			WithType (corev1 .ServiceTypeClusterIP ).
407- 			WithPorts (corev1apply .ServicePort ().
408- 				WithName ("http" ).
409- 				WithProtocol (corev1 .ProtocolTCP ).
410- 				WithPort (codeServer .Spec .ContainerPort ).
411- 				WithTargetPort (intstr .FromInt32 (codeServer .Spec .ContainerPort )),
424+ 			WithPorts (ports ... ,
412425			).
413426			WithSelector (map [string ]string {
414427				"app.kubernetes.io/name" :       CodeServer ,
@@ -464,33 +477,56 @@ func (r *CodeServerReconciler) reconcileIngress(ctx context.Context, codeServer
464477	}
465478	host  :=  fmt .Sprintf ("%s.%s" , codeServer .Name , url .String ())
466479
480+ 	paths  :=  []* networkingv1apply.HTTPIngressPathApplyConfiguration {networkingv1apply .HTTPIngressPath ().
481+ 		WithPath ("/" ).
482+ 		WithPathType (networkingv1 .PathTypePrefix ).
483+ 		WithBackend (networkingv1apply .IngressBackend ().
484+ 			WithService (networkingv1apply .IngressServiceBackend ().
485+ 				WithName (codeServer .Name ).
486+ 				WithPort (networkingv1apply .ServiceBackendPort ().
487+ 					WithName ("http" ),
488+ 				),
489+ 			),
490+ 		),
491+ 	}
492+ 
493+ 	for  _ , port  :=  range  codeServer .Spec .PublicProxyPorts  {
494+ 		paths  =  append (paths , networkingv1apply .HTTPIngressPath ().
495+ 			WithPath (fmt .Sprintf ("/proxy/%d" , port )).
496+ 			WithPathType (networkingv1 .PathTypePrefix ).
497+ 			WithBackend (networkingv1apply .IngressBackend ().
498+ 				WithService (networkingv1apply .IngressServiceBackend ().
499+ 					WithName (codeServer .Name ).
500+ 					WithPort (networkingv1apply .ServiceBackendPort ().
501+ 						WithName (fmt .Sprintf ("http-%d" , port )),
502+ 					),
503+ 				),
504+ 			),
505+ 		)
506+ 	}
507+ 
508+ 	spec  :=  networkingv1apply .IngressSpec ().
509+ 		WithRules (networkingv1apply .IngressRule ().
510+ 			WithHost (host ).
511+ 			WithHTTP (networkingv1apply .HTTPIngressRuleValue ().
512+ 				WithPaths (
513+ 					paths ... ,
514+ 				),
515+ 			),
516+ 		)
517+ 
518+ 	if  codeServer .Spec .IngressClassName  !=  ""  {
519+ 		spec  =  spec .WithIngressClassName (codeServer .Spec .IngressClassName )
520+ 	}
521+ 
467522	ingress  :=  networkingv1apply .Ingress (codeServer .Name , codeServer .Namespace ).
468523		WithLabels (map [string ]string {
469524			"app.kubernetes.io/name" :       CodeServer ,
470525			"app.kubernetes.io/instance" :   codeServer .Name ,
471526			"app.kubernetes.io/created-by" : CodeServerManager ,
472527		}).
473528		WithOwnerReferences (owner ).
474- 		WithSpec (networkingv1apply .IngressSpec ().
475- 			WithIngressClassName (codeServer .Spec .IngressClassName ).
476- 			WithRules (networkingv1apply .IngressRule ().
477- 				WithHost (host ).
478- 				WithHTTP (networkingv1apply .HTTPIngressRuleValue ().
479- 					WithPaths (networkingv1apply .HTTPIngressPath ().
480- 						WithPath ("/" ).
481- 						WithPathType (networkingv1 .PathTypePrefix ).
482- 						WithBackend (networkingv1apply .IngressBackend ().
483- 							WithService (networkingv1apply .IngressServiceBackend ().
484- 								WithName (codeServer .Name ).
485- 								WithPort (networkingv1apply .ServiceBackendPort ().
486- 									WithName ("http" ),
487- 								),
488- 							),
489- 						),
490- 					),
491- 				),
492- 			),
493- 		)
529+ 		WithSpec (spec )
494530
495531	obj , err  :=  runtime .DefaultUnstructuredConverter .ToUnstructured (ingress )
496532	if  err  !=  nil  {
0 commit comments