@@ -136,35 +136,69 @@ func ParseRelated(gwObjs []*gatewayv1beta1.Gateway, hrObjs []*gatewayv1beta1.HTT
136136}
137137
138138func parsePoolsFrom (hr * gatewayv1beta1.HTTPRoute , rlt map [string ]interface {}) error {
139+
140+ creatPool := func (ns , n string , rlt map [string ]interface {}) error {
141+ name := strings .Join ([]string {ns , n }, "." )
142+ rlt ["ltm/pool/" + name ] = map [string ]interface {}{
143+ "name" : name ,
144+ "monitor" : "min 1 of tcp" ,
145+ "members" : []interface {}{},
146+
147+ // "minActiveMembers": 0,
148+ // TODO: there's at least one field for PATCH a pool. or we may need to fix that
149+ // {"code":400,"message":"transaction failed:one or more properties must be specified","errorStack":[],"apiError":2}
150+ }
151+ if fmtmbs , err := parseMembersFrom (ns , n ); err != nil {
152+ return err
153+ } else {
154+ rlt ["ltm/pool/" + name ].(map [string ]interface {})["members" ] = fmtmbs
155+ }
156+
157+ if mon , err := parseMonitorFrom (ns , n ); err != nil {
158+ return err
159+ } else {
160+ rlt ["ltm/pool/" + name ].(map [string ]interface {})["monitor" ] = mon
161+ }
162+ return nil
163+ }
164+
139165 for _ , rl := range hr .Spec .Rules {
140166 for _ , br := range rl .BackendRefs {
141167 ns := hr .Namespace
142168 if br .Namespace != nil {
143169 ns = string (* br .Namespace )
144170 }
145- name := strings .Join ([]string {ns , string (br .Name )}, "." )
146- rlt ["ltm/pool/" + name ] = map [string ]interface {}{
147- "name" : name ,
148- "monitor" : "min 1 of http tcp" ,
149- "members" : []interface {}{},
150-
151- // "minActiveMembers": 0,
152- // TODO: there's at least one field for PATCH. or we may need to fix that
153- // {"code":400,"message":"transaction failed:one or more properties must be specified","errorStack":[],"apiError":2}
171+ if err := creatPool (ns , string (br .Name ), rlt ); err != nil {
172+ return err
154173 }
155- if fmtmbs , err := parseMembersFrom (ns , string (br .Name )); err == nil {
156- rlt ["ltm/pool/" + name ].(map [string ]interface {})["members" ] = fmtmbs
157- }
158-
159174 // TODO: parse ARP resources for flannel type network.
160175 }
161176 }
162177
163- // TODO: from ExtensionRef as well.
178+ // pools from ExtensionRef as well.
179+ for _ , rl := range hr .Spec .Rules {
180+ for _ , fl := range rl .Filters {
181+ if fl .Type == gatewayv1beta1 .HTTPRouteFilterExtensionRef && fl .ExtensionRef != nil {
182+ er := fl .ExtensionRef
183+ if er .Group != "v1" || er .Kind != "Service" {
184+ return fmt .Errorf ("resource %s of '%s' not supported" , er .Name , utils .Keyname (string (er .Group ), string (er .Kind )))
185+ } else {
186+ if err := creatPool (hr .Namespace , string (er .Name ), rlt ); err != nil {
187+ return err
188+ }
189+ }
190+ }
191+ }
192+ }
164193
165194 return nil
166195}
167196
197+ // TODO: find the way to set monitor
198+ func parseMonitorFrom (svcNamespace , svcName string ) (string , error ) {
199+ return "min 1 of tcp" , nil
200+ }
201+
168202func parseMembersFrom (svcNamespace , svcName string ) ([]interface {}, error ) {
169203 svc := ActiveSIGs .GetService (utils .Keyname (svcNamespace , svcName ))
170204 eps := ActiveSIGs .GetEndpoints (utils .Keyname (svcNamespace , svcName ))
0 commit comments