@@ -12,12 +12,11 @@ import (
1212	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 
1313	applymetav1 "k8s.io/client-go/applyconfigurations/meta/v1" 
1414	netv1 "k8s.io/client-go/applyconfigurations/networking/v1" 
15+ 	networking "k8s.io/client-go/kubernetes/typed/networking/v1" 
1516
1617	"github.com/dyrector-io/dyrectorio/golang/internal/domain" 
1718	"github.com/dyrector-io/dyrectorio/golang/internal/util" 
1819	"github.com/dyrector-io/dyrectorio/golang/pkg/crane/config" 
19- 
20- 	networking "k8s.io/client-go/kubernetes/typed/networking/v1" 
2120)
2221
2322// facade object for ingress management 
@@ -28,21 +27,26 @@ type ingress struct {
2827	status     string 
2928}
3029
30+ type  routingOptions  struct  {
31+ 	ingressHost     string 
32+ 	ingressPath     string 
33+ 	uploadLimit     string 
34+ 	proxyHeaders    []string 
35+ 	corsHeaders     []string 
36+ 	portList        []int32 
37+ 	port            uint16 
38+ 	proxyBuffering  bool 
39+ 	stripPrefix     bool 
40+ 	tls             bool 
41+ }
42+ 
3143type  DeployIngressOptions  struct  {
3244	annotations    map [string ]string 
3345	labels         map [string ]string 
3446	containerName  string 
35- 	ingressName    string 
36- 	ingressHost    string 
37- 	ingressPath    string 
38- 	uploadLimit    string 
47+ 	name           string 
3948	namespace      string 
40- 	customHeaders  []string 
41- 	portList       []int32 
42- 	port           uint16 
43- 	stripPrefix    bool 
44- 	proxyHeaders   bool 
45- 	tls            bool 
49+ 	routing        routingOptions 
4650}
4751
4852func  newIngress (ctx  context.Context , client  * Client ) * ingress  {
@@ -59,29 +63,31 @@ func (ing *ingress) deployIngress(options *DeployIngressOptions) error {
5963		log .Error ().Err (err ).Stack ().Msg ("Error with ingress client" )
6064	}
6165
62- 	if  options .port  ==  0  &&  len (options .portList ) ==  0  {
66+ 	routing  :=  options .routing 
67+ 
68+ 	if  routing .port  ==  0  &&  len (routing .portList ) ==  0  {
6369		return  errors .New ("empty ports, nothing to expose" )
6470	}
6571
66- 	routedPort  :=  options .port 
72+ 	routedPort  :=  routing .port 
6773	if  routedPort  ==  0  {
68- 		routedPort  =  uint16 (options .portList [0 ]) //#nosec G115 
74+ 		routedPort  =  uint16 (routing .portList [0 ]) //#nosec G115 
6975	}
7076
7177	ingressDomain  :=  domain .GetHostRule (
7278		& domain.HostRouting {
73- 			Subdomain :      options .ingressName ,
74- 			RootDomain :     options .ingressHost ,
79+ 			Subdomain :      options .name ,
80+ 			RootDomain :     routing .ingressHost ,
7581			ContainerName :  options .containerName ,
7682			Prefix :         options .namespace ,
7783			DomainFallback : ing .appConfig .RootDomain ,
7884		})
7985
8086	ingressPath  :=  "/" 
81- 	if  options .ingressPath  !=  ""  {
82- 		ingressPath  =  options .ingressPath 
87+ 	if  routing .ingressPath  !=  ""  {
88+ 		ingressPath  =  routing .ingressPath 
8389		// prefix stripping works in combination with annotations 
84- 		if  options .stripPrefix  {
90+ 		if  routing .stripPrefix  {
8591			split  :=  strings .Split (ingressPath , "/" )
8692
8793			split  =  append (split , "?(.*)" )
@@ -105,12 +111,12 @@ func (ing *ingress) deployIngress(options *DeployIngressOptions) error {
105111							),
106112						),
107113				)))
108- 	tlsConf  :=  getTLSConfig (ingressDomain , options .containerName , options .tls )
114+ 	tlsConf  :=  getTLSConfig (ingressDomain , options .containerName , options .routing . tls )
109115	if  tlsConf  !=  nil  {
110116		spec .WithTLS (tlsConf )
111117	}
112118
113- 	annot  :=  getIngressAnnotations (options )
119+ 	annot  :=  getIngressAnnotations (options . namespace ,  options . containerName ,  & options . routing )
114120	maps .Copy (annot , options .annotations )
115121
116122	labels  :=  map [string ]string {}
@@ -153,9 +159,7 @@ func getTLSConfig(ingressPath, containerName string, enabled bool) *netv1.Ingres
153159	return  nil 
154160}
155161
156- func  getIngressAnnotations (opts  * DeployIngressOptions ) map [string ]string  {
157- 	corsHeaders  :=  []string {}
158- 
162+ func  getIngressAnnotations (namespace , name  string , opts  * routingOptions ) map [string ]string  {
159163	annotations  :=  map [string ]string {
160164		"kubernetes.io/ingress.class" : "nginx" ,
161165	}
@@ -165,23 +169,18 @@ func getIngressAnnotations(opts *DeployIngressOptions) map[string]string {
165169		annotations ["cert-manager.io/cluster-issuer" ] =  "letsencrypt-prod" 
166170	}
167171
168- 	// Add Custom Headers to the CORS Allow Header annotation if presents 
169- 	if   len ( opts . customHeaders )  >   0  { 
170- 		corsHeaders  =  opts .customHeaders 
172+ 	if   len ( opts . corsHeaders )  >   0  { 
173+ 		 annotations [ "nginx.ingress.kubernetes.io/enable-cors" ]  =   "true" 
174+ 		annotations [ "nginx.ingress.kubernetes.io/cors-allow-headers" ]  =  strings . Join ( opts .proxyHeaders ,  ", " ) 
171175	}
172176
173- 	if  opts .proxyHeaders  {
174- 		extraHeaders  :=  []string {"X-Forwarded-For" , "X-Forwarded-Host" , "X-Forwarded-Server" , "X-Real-IP" , "X-Requested-With" }
175- 		corsHeaders  =  append (corsHeaders , extraHeaders ... )
176- 
177- 		annotations ["nginx.ingress.kubernetes.io/enable-cors" ] =  "true" 
177+ 	if  opts .proxyBuffering  {
178178		annotations ["nginx.ingress.kubernetes.io/proxy-buffering" ] =  "on" 
179179		annotations ["nginx.ingress.kubernetes.io/proxy-buffer-size" ] =  "256k" 
180180	}
181181
182- 	// Add header string to cors-allow-headers if presents any value 
183- 	if  len (corsHeaders ) >  0  {
184- 		annotations ["nginx.ingress.kubernetes.io/cors-allow-headers" ] =  strings .Join (corsHeaders , ", " )
182+ 	if  len (opts .proxyHeaders ) >  0  {
183+ 		annotations ["nginx.ingress.kubernetes.io/proxy-set-headers" ] =  util .JoinV ("/" , namespace , name )
185184	}
186185
187186	if  opts .uploadLimit  !=  ""  {
0 commit comments