Commit a16103c6 authored by Geoff Simmons's avatar Geoff Simmons

Restore validation of the dataplaneapi sites response.

Fixing the dataplaneapi has resolved this problem. In the process of
debugging, a logger was added to the dataplaneapi client code, which
will now be retained.
parent e42180cb
......@@ -42,6 +42,8 @@ import (
"github.com/go-openapi/strfmt"
models "github.com/haproxytech/models/v2"
"github.com/sirupsen/logrus"
)
var fmts = strfmt.NewFormats()
......@@ -171,6 +173,7 @@ type DataplaneClient struct {
user string
password string
client *http.Client
log *logrus.Logger
}
// NewDataplaneClient returns a client for the dataplane API server
......@@ -178,7 +181,9 @@ type DataplaneClient struct {
//
// host may have the form "addr" or "addr:port", where addr may be a
// host name or IP address.
func NewDataplaneClient(host, pass string) *DataplaneClient {
func NewDataplaneClient(
host, pass string, log *logrus.Logger,
) *DataplaneClient {
return &DataplaneClient{
baseURL: &url.URL{
Scheme: "http",
......@@ -187,6 +192,7 @@ func NewDataplaneClient(host, pass string) *DataplaneClient {
user: dataplaneUser,
password: pass,
client: http.DefaultClient,
log: log,
}
}
......@@ -699,8 +705,10 @@ func (client *DataplaneClient) LoaderStatus() (
if err != nil {
return
}
client.log.Tracef("dataplane sites response body: %s", body)
if verStr := resp.Header.Get(versionHdr); verStr != "" {
client.log.Tracef("dataplane sites version: %s", verStr)
if version, err = strconv.Atoi(verStr); err != nil {
return
}
......@@ -715,11 +723,9 @@ func (client *DataplaneClient) LoaderStatus() (
if err = json.Unmarshal(body, &sb); err != nil {
return
}
// if len(sb.Sites) > 0 {
// if err = sb.Sites.Validate(fmts); err != nil {
// return
// }
// }
if err = sb.Sites.Validate(fmts); err != nil {
return
}
if version == 0 {
version = sb.Version
}
......
......@@ -662,13 +662,14 @@ func (hc *Controller) removeOffldrInstances(
return errs
}
func offldAddr2haproxyInst(addr OffldAddr, dplanePasswd *string) *haproxyInst {
func offldAddr2haproxyInst(
addr OffldAddr, dplanePasswd *string, log *logrus.Logger) *haproxyInst {
var passwd string
if dplanePasswd != nil {
passwd = *dplanePasswd
}
dplaneAddr := addr.IP + ":" + strconv.Itoa(int(addr.DataplanePort))
dplaneClient := NewDataplaneClient(dplaneAddr, passwd)
dplaneClient := NewDataplaneClient(dplaneAddr, passwd, log)
crtDnldrAddr := addr.IP + ":" + strconv.Itoa(int(addr.CrtDnldrPort))
crtDnldrClient := NewCrtDnldrClient(crtDnldrAddr)
inst := &haproxyInst{
......@@ -721,7 +722,8 @@ func (hc *Controller) updateOffldrAddrs(key string, addrs []OffldAddr,
keepInsts = append(keepInsts, inst)
continue
}
newInst := offldAddr2haproxyInst(updateAddrs[addr], passwdPtr)
newInst := offldAddr2haproxyInst(
updateAddrs[addr], passwdPtr, hc.log)
newInsts = append(newInsts, newInst)
}
for addr, inst := range prevAddrs {
......@@ -784,10 +786,10 @@ func (hc *Controller) getOffldStatus(inst *haproxyInst) error {
return nil
}
func mkSvc(addrs []OffldAddr) *offldrSvc {
func mkSvc(addrs []OffldAddr, log *logrus.Logger) *offldrSvc {
svc := &offldrSvc{instances: make([]*haproxyInst, len(addrs))}
for i, addr := range addrs {
instance := offldAddr2haproxyInst(addr, nil)
instance := offldAddr2haproxyInst(addr, nil, log)
svc.instances[i] = instance
// instsGauge.Inc()
}
......@@ -806,7 +808,7 @@ func (hc *Controller) AddOrUpdateOffloader(
var passwdPtr *string
svc, exists := hc.svcs[key]
if !exists {
svc = mkSvc(addrs)
svc = mkSvc(addrs, hc.log)
hc.svcs[key] = svc
// svcsGauge.Inc()
hc.log.Debugf("offloader svc %s: created config", key)
......@@ -852,7 +854,7 @@ func (hc *Controller) Update(
) update.Status {
svc, exists := hc.svcs[svcKey]
if !exists {
svc = mkSvc(addrs)
svc = mkSvc(addrs, hc.log)
hc.svcs[svcKey] = svc
// svcsGauge.Inc()
hc.log.Infof("Added offloader service definition %s", svcKey)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment