@@ -35,31 +35,44 @@ var logger = utils.GetLogger()
3535const cookieKey = "ohph7OoGhong"
3636
3737type Service struct {
38- path * store.IngressPath
39- resource * store.Service
40- backend * models.Backend
41- certs certs.Certificates
42- annotations []map [string ]string
43- modeTCP bool
44- newBackend bool
38+ path * store.IngressPath
39+ resource * store.Service
40+ backend * models.Backend
41+ certs certs.Certificates
42+ annotations []map [string ]string
43+ modeTCP bool
44+ newBackend bool
45+ standalone bool
46+ ingressName string
47+ ingressNamespace string
4548}
4649
4750// New returns a Service instance to handle the k8s IngressPath resource given in params.
4851// An error will be returned if there is no k8s Service resource corresponding to the service description in IngressPath.
49- func New (k store.K8s , path * store.IngressPath , certs certs.Certificates , tcpService bool , annList ... map [string ]string ) (* Service , error ) {
52+ func New (k store.K8s , path * store.IngressPath , certs certs.Certificates , tcpService bool , ingressNamespace , ingressName string , annList ... map [string ]string ) (* Service , error ) {
5053 service , err := k .GetService (path .SvcNamespace , path .SvcName )
5154 if err != nil {
5255 return nil , err
5356 }
5457 a := make ([]map [string ]string , 1 , 3 )
5558 a [0 ] = service .Annotations
5659 a = append (a , annList ... )
60+ var standalone bool
61+ for _ , anns := range a {
62+ standalone = len (anns ) != 0 && anns ["standalone-backend" ] == "true"
63+ if standalone {
64+ break
65+ }
66+ }
5767 return & Service {
58- path : path ,
59- resource : service ,
60- certs : certs ,
61- annotations : a ,
62- modeTCP : tcpService ,
68+ path : path ,
69+ resource : service ,
70+ certs : certs ,
71+ annotations : a ,
72+ modeTCP : tcpService ,
73+ standalone : standalone ,
74+ ingressName : ingressName ,
75+ ingressNamespace : ingressNamespace ,
6376 }, nil
6477}
6578
@@ -104,11 +117,20 @@ func (s *Service) GetBackendName() (name string, err error) {
104117 }
105118 return
106119 }
120+ resourceNamespace := s .resource .Namespace
121+ resourceName := s .resource .Name
122+ prefix := ""
123+ if s .standalone && s .ingressName != "" {
124+ resourceName = s .ingressName
125+ resourceNamespace = s .ingressNamespace
126+ prefix = "ing_"
127+ }
128+
107129 s .path .SvcPortResolved = & svcPort
108130 if svcPort .Name != "" {
109- name = fmt .Sprintf ("%s_%s_%s" , s . resource . Namespace , s . resource . Name , svcPort .Name )
131+ name = fmt .Sprintf ("%s% s_%s_%s" , prefix , resourceNamespace , resourceName , svcPort .Name )
110132 } else {
111- name = fmt .Sprintf ("%s_%s_%s" , s . resource . Namespace , s . resource . Name , strconv .Itoa (int (svcPort .Port )))
133+ name = fmt .Sprintf ("%s% s_%s_%s" , prefix , resourceNamespace , resourceName , strconv .Itoa (int (svcPort .Port )))
112134 }
113135 return
114136}
0 commit comments