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