Skip to content

Commit 76ccd72

Browse files
committed
BUG/MINOR: raw: return full raw config on GET and POST responses
Also adds Configuration-Checksum and Cluster-Version response headers.
1 parent 2896f49 commit 76ccd72

File tree

6 files changed

+267
-9
lines changed

6 files changed

+267
-9
lines changed

embedded_spec.go

Lines changed: 68 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ require (
2222
github.com/go-openapi/validate v0.22.1
2323
github.com/google/renameio v1.0.1
2424
github.com/google/uuid v1.3.1
25-
github.com/haproxytech/client-native/v5 v5.0.1-0.20230906085426-63ef2dfd0818
25+
github.com/haproxytech/client-native/v5 v5.0.1-0.20230906104259-300451457fc6
2626
github.com/haproxytech/config-parser/v5 v5.0.1-0.20230821131853-5878ad7f5340
2727
github.com/jessevdk/go-flags v1.5.0
2828
github.com/json-iterator/go v1.1.12

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,8 @@ github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+
132132
github.com/google/uuid v1.3.1 h1:KjJaJ9iWZ3jOFZIf1Lqf4laDRCasjl0BCmnEGxkdLb4=
133133
github.com/google/uuid v1.3.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
134134
github.com/gorilla/mux v1.8.0/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So=
135-
github.com/haproxytech/client-native/v5 v5.0.1-0.20230906085426-63ef2dfd0818 h1:BpjVE8HW7ugKy8cvEx2GCCN/muGGmIDU4vewpndF+98=
136-
github.com/haproxytech/client-native/v5 v5.0.1-0.20230906085426-63ef2dfd0818/go.mod h1:Iri39GLoJjesuqvovItlnWdUw4K2p/39YKoyRQ6ZW4Q=
135+
github.com/haproxytech/client-native/v5 v5.0.1-0.20230906104259-300451457fc6 h1:WPAl1+D5zlhFtF6bX4uiwTkp7f9T6hxaMhvd0/Ms3kw=
136+
github.com/haproxytech/client-native/v5 v5.0.1-0.20230906104259-300451457fc6/go.mod h1:Iri39GLoJjesuqvovItlnWdUw4K2p/39YKoyRQ6ZW4Q=
137137
github.com/haproxytech/config-parser/v5 v5.0.1-0.20230821131853-5878ad7f5340 h1:VtRnT4x7Cds0TxZCqDYFTyCnFMyJJA5FC+uRum+CUD4=
138138
github.com/haproxytech/config-parser/v5 v5.0.1-0.20230821131853-5878ad7f5340/go.mod h1:cGtFso7oMTY1GIixWv9JG7pKSdyyacpWqNE7XPx6+mU=
139139
github.com/haproxytech/go-logger v1.1.0 h1:HgGtYaI1ApkvbQdsm7f9AzQQoxTB7w37criTflh7IQE=

handlers/raw.go

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,16 @@ func (h *GetRawConfigurationHandlerImpl) Handle(params configuration.GetHAProxyC
5858
return configuration.NewGetConfigurationVersionDefault(int(*e.Code)).WithPayload(e)
5959
}
6060

61-
v, data, err := cfg.GetRawConfiguration(t, v)
61+
v, clusterVersion, md5Hash, data, err := cfg.GetRawConfigurationWithClusterData(t, v)
6262
if err != nil {
6363
e := misc.HandleError(err)
6464
return configuration.NewGetHAProxyConfigurationDefault(int(*e.Code)).WithPayload(e)
6565
}
66-
return configuration.NewGetHAProxyConfigurationOK().WithPayload(&configuration.GetHAProxyConfigurationOKBody{Version: v, Data: &data})
66+
cVersion := ""
67+
if clusterVersion != 0 {
68+
cVersion = strconv.FormatInt(clusterVersion, 10)
69+
}
70+
return configuration.NewGetHAProxyConfigurationOK().WithPayload(&configuration.GetHAProxyConfigurationOKBody{Version: v, Data: &data}).WithClusterVersion(cVersion).WithConfigurationChecksum(md5Hash)
6771
}
6872

6973
// Handle executing the request and returning a response
@@ -115,9 +119,19 @@ func (h *PostRawConfigurationHandlerImpl) Handle(params configuration.PostHAProx
115119
return configuration.NewPostHAProxyConfigurationDefault(int(*e.Code)).WithPayload(e)
116120
}
117121

122+
_, clusterVersion, md5Hash, data, err := cfg.GetRawConfigurationWithClusterData("", 0)
123+
if err != nil {
124+
e := misc.HandleError(err)
125+
return configuration.NewPostHAProxyConfigurationDefault(int(*e.Code)).WithPayload(e)
126+
}
127+
128+
cVersion := ""
129+
if clusterVersion != 0 {
130+
cVersion = strconv.FormatInt(clusterVersion, 10)
131+
}
118132
if onlyValidate {
119133
// return here without reloading, since config is only validated.
120-
return configuration.NewPostHAProxyConfigurationAccepted().WithPayload(params.Data)
134+
return configuration.NewPostHAProxyConfigurationAccepted().WithPayload(data).WithClusterVersion(cVersion).WithConfigurationChecksum(md5Hash)
121135
}
122136
if skipReload {
123137
if params.XRuntimeActions != nil {
@@ -126,7 +140,7 @@ func (h *PostRawConfigurationHandlerImpl) Handle(params configuration.PostHAProx
126140
return configuration.NewPostHAProxyConfigurationDefault(int(*e.Code)).WithPayload(e)
127141
}
128142
}
129-
return configuration.NewPostHAProxyConfigurationCreated().WithPayload(params.Data)
143+
return configuration.NewPostHAProxyConfigurationCreated().WithPayload(data).WithClusterVersion(cVersion).WithConfigurationChecksum(md5Hash)
130144
}
131145
if forceReload {
132146
var callbackNeeded bool
@@ -145,7 +159,7 @@ func (h *PostRawConfigurationHandlerImpl) Handle(params configuration.PostHAProx
145159
e := misc.HandleError(err)
146160
return configuration.NewPostHAProxyConfigurationDefault(int(*e.Code)).WithPayload(e)
147161
}
148-
return configuration.NewPostHAProxyConfigurationCreated().WithPayload(params.Data)
162+
return configuration.NewPostHAProxyConfigurationCreated().WithPayload(data).WithClusterVersion(cVersion).WithConfigurationChecksum(md5Hash)
149163
}
150164
callbackNeeded, reconfigureFunc, err := cn.ReconfigureRuntime(h.Client, runtimeAPIsOld)
151165
if err != nil {
@@ -160,7 +174,7 @@ func (h *PostRawConfigurationHandlerImpl) Handle(params configuration.PostHAProx
160174
rID = h.ReloadAgent.Reload()
161175
}
162176

163-
return configuration.NewPostHAProxyConfigurationAccepted().WithReloadID(rID).WithPayload(params.Data)
177+
return configuration.NewPostHAProxyConfigurationAccepted().WithReloadID(rID).WithPayload(data).WithClusterVersion(cVersion).WithConfigurationChecksum(md5Hash)
164178
}
165179

166180
func executeRuntimeActions(actionsStr string, client client_native.HAProxyClient) error {

operations/configuration/get_h_a_proxy_configuration_responses.go

Lines changed: 44 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)