@@ -17,7 +17,6 @@ import (
1717 "context"
1818 "log/slog"
1919
20- parser "github.com/haproxytech/client-native/v6/config-parser"
2120 "github.com/haproxytech/client-native/v6/models"
2221 "github.com/haproxytech/haproxy-unified-gateway/hug/reload"
2322 "github.com/haproxytech/haproxy-unified-gateway/k8s/gate/logging"
@@ -28,11 +27,10 @@ func (c *clientNative) FrontendCreate(frontend models.Frontend) error {
2827 if err != nil {
2928 return err
3029 }
31- f := & models.Frontend {FrontendBase : frontend .FrontendBase }
32- errCreate := configuration .CreateFrontend (f , c .activeTransaction , 0 )
30+ errCreate := configuration .CreateStructuredFrontend (& frontend , c .activeTransaction , 0 )
3331 if errCreate != nil {
3432 // ... maybe it's already existing, so just edit it.
35- if err := configuration .EditFrontend (frontend .Name , & frontend , c .activeTransaction , 0 ); err != nil {
33+ if err := configuration .EditStructuredFrontend (frontend .Name , & frontend , c .activeTransaction , 0 ); err != nil {
3634 c .logger .LogAttrs (context .Background (), slog .LevelError , "failed to edit frontend" ,
3735 logging .LogAttrError (err ),
3836 slog .String ("frontend" , frontend .Name ),
@@ -42,36 +40,6 @@ func (c *clientNative) FrontendCreate(frontend models.Frontend) error {
4240 }
4341 reload .Instance ().SetReload ("Frontend upserted %s" , frontend .Name )
4442
45- // Binds
46- err = c .BindReplaceAll (parser .Frontends , frontend .Name , frontend .Binds )
47- if err != nil {
48- return err
49- }
50-
51- // ACLs
52- err = c .ACLReplaceAll (parser .Frontends , frontend .Name , frontend .ACLList )
53- if err != nil {
54- return err
55- }
56-
57- // Http Requests
58- err = c .HTTPRequestReplaceAll (parser .Frontends , frontend .Name , frontend .HTTPRequestRuleList )
59- if err != nil {
60- return err
61- }
62-
63- // TCP Requests
64- err = c .TCPRequestReplaceAll (parser .Frontends , frontend .Name , frontend .TCPRequestRuleList )
65- if err != nil {
66- return err
67- }
68-
69- // Use backend rules
70- err = c .UseBackendReplaceAll (frontend .Name , frontend .BackendSwitchingRuleList )
71- if err != nil {
72- return err
73- }
74-
7543 return nil
7644}
7745
@@ -90,23 +58,8 @@ func (c *clientNative) FrontendsGet() (models.Frontends, error) {
9058 return nil , err
9159 }
9260 // TODO: complete with children
93- _ , frontends , err := configuration .GetFrontends (c .activeTransaction )
61+ _ , frontends , err := configuration .GetStructuredFrontends (c .activeTransaction )
9462
95- // Binds
96- for _ , frontend := range frontends {
97- _ , binds , err := configuration .GetBinds (string (parser .Frontends ), frontend .Name , c .activeTransaction )
98- if err != nil {
99- return nil , err
100- }
101- if len (binds ) != 0 {
102- frontend .Binds = make (map [string ]models.Bind )
103- }
104- for _ , bind := range binds {
105- if bind != nil {
106- frontend .Binds [bind .Name ] = * bind
107- }
108- }
109- }
11063 return frontends , err
11164}
11265
@@ -115,25 +68,10 @@ func (c *clientNative) FrontendGet(frontendName string) (models.Frontend, error)
11568 if err != nil {
11669 return models.Frontend {}, err
11770 }
118- // TODO: complete with children
119- _ , frontend , err := configuration .GetFrontend (frontendName , c .activeTransaction )
120- if err != nil {
121- return models.Frontend {}, err
122- }
123-
124- // Binds
125- _ , binds , err := configuration .GetBinds (string (parser .Frontends ), frontend .Name , c .activeTransaction )
71+ _ , frontend , err := configuration .GetStructuredFrontend (frontendName , c .activeTransaction )
12672 if err != nil {
12773 return models.Frontend {}, err
12874 }
129- if len (binds ) != 0 {
130- frontend .Binds = make (map [string ]models.Bind )
131- }
132- for _ , bind := range binds {
133- if bind != nil {
134- frontend .Binds [bind .Name ] = * bind
135- }
136- }
13775
13876 return * frontend , err
13977}
@@ -143,8 +81,7 @@ func (c *clientNative) FrontendEdit(frontend models.Frontend) error {
14381 if err != nil {
14482 return err
14583 }
146- f := & models.Frontend {FrontendBase : frontend .FrontendBase }
147- if err := configuration .EditFrontend (frontend .Name , f , c .activeTransaction , 0 ); err != nil {
84+ if err := configuration .EditFrontend (frontend .Name , & frontend , c .activeTransaction , 0 ); err != nil {
14885 c .logger .LogAttrs (context .Background (), slog .LevelError , "failed to edit frontend" ,
14986 logging .LogAttrError (err ),
15087 slog .String ("frontend" , frontend .Name ),
@@ -154,35 +91,5 @@ func (c *clientNative) FrontendEdit(frontend models.Frontend) error {
15491
15592 reload .Instance ().SetReload ("Frontend upserted %s" , frontend .Name )
15693
157- // Binds
158- err = c .BindReplaceAll (parser .Frontends , frontend .Name , frontend .Binds )
159- if err != nil {
160- return err
161- }
162-
163- // ACLs
164- err = c .ACLReplaceAll (parser .Frontends , frontend .Name , frontend .ACLList )
165- if err != nil {
166- return err
167- }
168-
169- // Http Requests
170- err = c .HTTPRequestReplaceAll (parser .Frontends , frontend .Name , frontend .HTTPRequestRuleList )
171- if err != nil {
172- return err
173- }
174-
175- // TCP Requests
176- err = c .TCPRequestReplaceAll (parser .Frontends , frontend .Name , frontend .TCPRequestRuleList )
177- if err != nil {
178- return err
179- }
180-
181- // Use backend rules
182- err = c .UseBackendReplaceAll (frontend .Name , frontend .BackendSwitchingRuleList )
183- if err != nil {
184- return err
185- }
186-
18794 return nil
18895}
0 commit comments