@@ -35,31 +35,44 @@ var logger = utils.GetLogger()
35
35
const cookieKey = "ohph7OoGhong"
36
36
37
37
type 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
45
48
}
46
49
47
50
// New returns a Service instance to handle the k8s IngressPath resource given in params.
48
51
// 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 ) {
50
53
service , err := k .GetService (path .SvcNamespace , path .SvcName )
51
54
if err != nil {
52
55
return nil , err
53
56
}
54
57
a := make ([]map [string ]string , 1 , 3 )
55
58
a [0 ] = service .Annotations
56
59
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
+ }
57
67
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 ,
63
76
}, nil
64
77
}
65
78
@@ -104,11 +117,20 @@ func (s *Service) GetBackendName() (name string, err error) {
104
117
}
105
118
return
106
119
}
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
+
107
129
s .path .SvcPortResolved = & svcPort
108
130
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 )
110
132
} 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 )))
112
134
}
113
135
return
114
136
}
0 commit comments