fix: undo pr 24532 (#24639)

Co-authored-by: Qiu Jian <qiujian@yunionyun.com>
This commit is contained in:
Jian Qiu
2026-04-08 16:25:35 +08:00
committed by GitHub
parent 88e226a154
commit 9f046bafad

View File

@@ -100,7 +100,7 @@ func (b *LoadbalancerCorpus) GenHaproxyConfigs(dir string, opts *AgentParams) (*
s += strings.Join(cidrs, "\n")
s += "\n"
p := filepath.Join(dir, "acl-"+lbacl.Id)
err := ioutil.WriteFile(p, []byte(s), agentutils.FileModeFile)
err := os.WriteFile(p, []byte(s), agentutils.FileModeFile)
if err != nil {
return nil, err
}
@@ -161,7 +161,7 @@ func (b *LoadbalancerCorpus) GenHaproxyConfigs(dir string, opts *AgentParams) (*
}
fn := fmt.Sprintf("%s.%s", lb.Id, agentutils.HaproxyCfgExt)
p := filepath.Join(dir, fn)
err := ioutil.WriteFile(p, d, agentutils.FileModeFile)
err := os.WriteFile(p, d, agentutils.FileModeFile)
if err != nil {
return nil, err
}
@@ -171,13 +171,6 @@ func (b *LoadbalancerCorpus) GenHaproxyConfigs(dir string, opts *AgentParams) (*
}
func (b *LoadbalancerCorpus) genHaproxyConfigCommon(lb *Loadbalancer, listener *LoadbalancerListener, opts *AgentParams) (map[string]interface{}, error) {
if listener == nil {
return nil, errors.Error("genHaproxyConfigCommon: listener is nil")
}
if lb == nil {
return nil, errors.Errorf("listener %s(%s): loadbalancer is nil (corpus join incomplete?)",
listener.Name, listener.Id)
}
data := map[string]interface{}{
"comment": fmt.Sprintf("%s(%s)", listener.Name, listener.Id),
"id": listener.Id,
@@ -254,9 +247,6 @@ func (b *LoadbalancerCorpus) genHaproxyConfigCommon(lb *Loadbalancer, listener *
}
func (b *LoadbalancerCorpus) genHaproxyConfigBackend(data map[string]interface{}, lb *Loadbalancer, listener *LoadbalancerListener, backendGroup *LoadbalancerBackendGroup) error {
if backendGroup == nil {
return errors.Error("genHaproxyConfigBackend: backend group is nil")
}
var mode string
var balanceAlgorithm string
var httpCheck, httpCheckExpect string
@@ -322,10 +312,6 @@ func (b *LoadbalancerCorpus) genHaproxyConfigBackend(data map[string]interface{}
}
serverLines := []string{}
for _, backend := range backendGroup.Backends {
if backend == nil {
log.Warningf("haproxy: skip nil backend in backend group %s(%s)", backendGroup.Name, backendGroup.Id)
continue
}
address, port := backend.GetAddressPort()
serverLine := fmt.Sprintf("server %s %s:%d", backend.Id, address, port)
@@ -378,10 +364,6 @@ func (b *LoadbalancerCorpus) genHaproxyConfigBackend(data map[string]interface{}
}
serverLines = append(serverLines, serverLine)
}
if len(serverLines) == 0 {
return errors.Errorf("backend group %s(%s): no usable backends (all nil or empty list)",
backendGroup.Name, backendGroup.Id)
}
data["servers"] = serverLines
}
if listener.HealthCheckTimeout > 0 {
@@ -537,10 +519,6 @@ func (b *LoadbalancerCorpus) genHaproxyConfigHttp(buf *bytes.Buffer, listener *L
continue
}
backendGroup := lb.BackendGroups[rule.BackendGroupId]
if backendGroup == nil {
return errors.Errorf("listener %s(%s) rule %s(%s): backend group %s not in corpus",
listener.Name, listener.Id, rule.Name, rule.Id, rule.BackendGroupId)
}
backendData := map[string]interface{}{
"comment": fmt.Sprintf("rule %s(%s) backendGroup %s(%s)",
rule.Name, rule.Id,
@@ -558,10 +536,6 @@ func (b *LoadbalancerCorpus) genHaproxyConfigHttp(buf *bytes.Buffer, listener *L
// default backend group
if listener.Redirect == computeapi.LB_REDIRECT_OFF && listener.BackendGroupId != "" {
backendGroup := lb.BackendGroups[listener.BackendGroupId]
if backendGroup == nil {
return errors.Errorf("listener %s(%s): default backend group %s not in corpus",
listener.Name, listener.Id, listener.BackendGroupId)
}
backendData := map[string]interface{}{
"comment": fmt.Sprintf("listener %s(%s) default backendGroup %s(%s)",
listener.Name, listener.Id,
@@ -595,10 +569,6 @@ func (b *LoadbalancerCorpus) genHaproxyConfigTcp(buf *bytes.Buffer, listener *Lo
}
if listener.BackendGroupId != "" {
backendGroup := lb.BackendGroups[listener.BackendGroupId]
if backendGroup == nil {
return errors.Errorf("tcp listener %s(%s): backend group %s not in corpus",
listener.Name, listener.Id, listener.BackendGroupId)
}
backendData := map[string]interface{}{
"comment": fmt.Sprintf("listener %s(%s) backendGroup %s(%s)",
listener.Name, listener.Id,