@@ -299,111 +299,6 @@ func (r *NginxController) generateNginxServers() ([]config.Server, error) {
299299
300300 ctx := context .TODO ()
301301
302- // get the bfl service
303- var svc corev1.Service
304- err := r .Get (ctx , types.NamespacedName {Namespace : constants .Namespace , Name : constants .BFLServiceName }, & svc )
305- if err != nil {
306- return nil , fmt .Errorf ("no bfl service found, %v" , err )
307- }
308-
309- latestAppPort := func (portName string ) int {
310- // compute the latest and available app port
311- var latestPort , maxAppPort int32
312-
313- if len (svc .Spec .Ports ) < 1 {
314- return int (constants .AppListenFromPort )
315- } else {
316- maxPort := svc .Spec .Ports [0 ].Port
317- for _ , p := range svc .Spec .Ports {
318- if p .Name == portName {
319- // never used
320- // latestPort = p.Port
321- break
322- }
323- if p .Port > maxPort {
324- maxPort = p .Port
325- }
326- if strings .HasPrefix (p .Name , constants .AppPortNamePrefix ) && p .Port > maxAppPort {
327- maxAppPort = p .Port
328- }
329- }
330- if maxAppPort + 1 > constants .AppListenFromPort && maxAppPort + 1 < maxPort {
331- latestPort = maxAppPort + 1
332- } else if maxAppPort < constants .AppListenFromPort {
333- latestPort = constants .AppListenFromPort
334- } else {
335- latestPort = maxPort + 1
336- }
337- }
338- klog .InfoS ("Figure out the latest port" , "maxAppPort" , maxAppPort , "latestPort" , latestPort )
339-
340- portExists := false
341-
342- for _ , app := range svc .Spec .Ports {
343- if portName == app .Name {
344- app .Port = latestPort
345- app .TargetPort = intstr .FromInt (int (latestPort ))
346- portExists = true
347- break
348- }
349- }
350- if ! portExists {
351- // update svc
352- svcPort := corev1.ServicePort {
353- Name : portName ,
354- Protocol : "TCP" ,
355- Port : latestPort ,
356- TargetPort : intstr .FromInt (int (latestPort )),
357- }
358- svc .Spec .Ports = append (svc .Spec .Ports , svcPort )
359- }
360- return int (latestPort )
361- }
362-
363- // For each applications port server
364- for _ , app := range r .apps {
365- if len (app .Spec .Entrances ) == 0 {
366- klog .Warningf ("invalid app %q, ignore it. app=%s" , app .Spec .Name , utils .PrettyJSON (app .Spec ))
367- continue
368- }
369-
370- for _ , entrance := range app .Spec .Entrances {
371- if entrance .Host == "" {
372- continue
373- }
374- appPortName := fmt .Sprintf ("%s%s" , constants .AppPortNamePrefix , entrance .Name )
375- appPort := latestAppPort (appPortName )
376-
377- s := config.Server {
378- Port : appPort ,
379- Locations : []config.Location {
380- {
381- Prefix : "/" ,
382- ProxyPass : fmt .Sprintf ("http://%s.%s.svc.cluster.local:%d" , entrance .Host , app .Spec .Namespace , entrance .Port ),
383- },
384- },
385- }
386-
387- // server patches
388- if patches , ok := patches [entrance .Name ]; ok {
389- for _ , patch := range patches {
390- _ , err = patch (ctx , r , & s )
391- if err != nil {
392- klog .Errorf ("failed to apply patch for app %s, %v" , app .Spec .Name , err )
393- return nil , err
394- }
395- }
396- }
397-
398- servers = append (servers , s )
399- }
400- }
401- klog .Infof ("Prepared and updating service ports:\n %v" , utils .PrettyJSON (svc .Spec .Ports ))
402- err = r .Update (context .TODO (), & svc )
403- if err != nil {
404- return nil , err
405- }
406-
407302 // For each domain servers
408303
409304 if r .sslConfigData != nil {
0 commit comments