@@ -18,11 +18,11 @@ package handlers
18
18
import (
19
19
"fmt"
20
20
"reflect"
21
+ "time"
21
22
22
23
log "github.com/sirupsen/logrus"
23
24
24
25
"github.com/go-openapi/runtime/middleware"
25
- "github.com/google/renameio"
26
26
client_native "github.com/haproxytech/client-native/v2"
27
27
"github.com/haproxytech/client-native/v2/models"
28
28
@@ -159,84 +159,14 @@ func (h *DeleteClusterHandlerImpl) Handle(params cluster.DeleteClusterParams, pr
159
159
// silently fallback to 1
160
160
version = 1
161
161
}
162
- transaction , err := h .Client .Configuration .StartTransaction (version )
163
- if err != nil {
164
- return h .err500 (err , transaction )
165
- }
166
- // delete backends
167
- _ , backends , err := h .Client .Configuration .GetBackends (transaction .ID )
168
- if err != nil {
169
- return h .err500 (err , transaction )
170
- }
171
- for _ , backend := range backends {
172
- err = h .Client .Configuration .DeleteBackend (backend .Name , transaction .ID , 0 )
173
- if err != nil {
174
- return h .err500 (err , transaction )
175
- }
176
- }
177
- // delete all frontends
178
- _ , frontends , err := h .Client .Configuration .GetFrontends (transaction .ID )
179
- if err != nil {
180
- return h .err500 (err , transaction )
181
- }
182
- for _ , frontend := range frontends {
183
- err = h .Client .Configuration .DeleteFrontend (frontend .Name , transaction .ID , 0 )
184
- if err != nil {
185
- return h .err500 (err , transaction )
186
- }
187
- }
188
162
189
- // now create dummy frontend so haproxy does not complain
190
- err = h .Client .Configuration .CreateFrontend (& models.Frontend {Name : "disabled" }, transaction .ID , 0 )
191
- if err != nil {
192
- return h .err500 (err , transaction )
193
- }
194
- err = h .Client .Configuration .CreateBind ("disabled" , & models.Bind {
195
- Name : "tmp" ,
196
- Address : fmt .Sprintf ("/tmp/dataplaneapi-%s.sock" , h .Config .Name .Load ()),
197
- }, transaction .ID , 0 )
198
- if err != nil {
199
- return h .err500 (err , transaction )
200
- }
201
- // now reset peer-id
202
- if h .Config .HAProxy .NodeIDFile != "" {
203
- err = renameio .WriteFile (h .Config .HAProxy .NodeIDFile , []byte ("localhost" ), 0644 )
204
- if err != nil {
205
- return h .err500 (err , transaction )
206
- }
207
- _ , peerSections , errPeers := h .Client .Configuration .GetPeerSections (transaction .ID )
208
- if errPeers != nil {
209
- return h .err500 (errPeers , transaction )
210
- }
211
- peerFound := false
212
- dataplaneID := h .Config .Cluster .ID .Load ()
213
- for _ , section := range peerSections {
214
- _ , peerEntries , errPeersEntries := h .Client .Configuration .GetPeerEntries (section .Name , transaction .ID )
215
- if errPeersEntries != nil {
216
- return h .err500 (errPeersEntries , transaction )
217
- }
218
- for _ , peer := range peerEntries {
219
- if peer .Name == dataplaneID {
220
- peerFound = true
221
- peer .Name = "localhost"
222
- errPeerEntry := h .Client .Configuration .EditPeerEntry (dataplaneID , section .Name , peer , transaction .ID , 0 )
223
- if errPeerEntry != nil {
224
- return h .err500 (errPeerEntry , transaction )
225
- }
226
- }
227
- }
228
- }
229
- if ! peerFound && dataplaneID != "" {
230
- return h .err500 (fmt .Errorf ("peer [%s] not found in HAProxy config" , dataplaneID ), transaction )
231
- }
232
- }
233
- _ , err = h .Client .Configuration .CommitTransaction (transaction .ID )
234
- if err != nil {
163
+ config := fmt .Sprintf (DummyConfig , time .Now ().Format ("01-02-2006 15:04:05 MST" ), h .Config .Name .Load ())
164
+ if err := configuration .PostRawConfiguration (& config , version , true ); err != nil {
235
165
return h .err500 (err , nil )
236
166
}
167
+
237
168
// we need to restart haproxy
238
- err = h .ReloadAgent .Restart ()
239
- if err != nil {
169
+ if err := h .ReloadAgent .Restart (); err != nil {
240
170
return h .err500 (err , nil )
241
171
}
242
172
}
@@ -344,3 +274,17 @@ func clusterLogTargetsChanged(old []*models.ClusterLogTarget, new []*models.Clus
344
274
}
345
275
return true
346
276
}
277
+
278
+ const DummyConfig = `# NOTE: This configuration file was managed by the Fusion Control Plane.
279
+ # Fusion released the control at %s
280
+
281
+ defaults
282
+ mode http
283
+ timeout connect 5000
284
+ timeout client 30000
285
+ timeout server 10000
286
+
287
+ frontend disabled
288
+ bind /tmp/dataplaneapi-%s.sock name tmp
289
+
290
+ `
0 commit comments