Skip to content

Commit

Permalink
Merge pull request #11 from cliedeman/fix/update-node-filter
Browse files Browse the repository at this point in the history
Fix update node balancer filtering
  • Loading branch information
displague committed Dec 4, 2018
2 parents 304e45e + 854bdf5 commit 911501f
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 20 deletions.
43 changes: 43 additions & 0 deletions cloud/linode/fake_linode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,49 @@ func (f *fakeAPI) ServeHTTP(w http.ResponseWriter, r *http.Request) {
case "DELETE":
id := filepath.Base(r.URL.Path)
delete(f.nb, id)
case "PUT":
if strings.Contains(r.URL.Path, "configs") {
parts := strings.Split(r.URL.Path[1:], "/")
nbcco := new(linodego.NodeBalancerConfigUpdateOptions)
if err := json.NewDecoder(r.Body).Decode(nbcco); err != nil {
f.t.Fatal(err)
}
nbcid, err := strconv.Atoi(parts[3])
if err != nil {
f.t.Fatal(err)
}
nbid, err := strconv.Atoi(parts[1])
if err != nil {
f.t.Fatal(err)
}
nbcc := linodego.NodeBalancerConfig{
ID: nbcid,
Port: nbcco.Port,
Protocol: nbcco.Protocol,
Algorithm: nbcco.Algorithm,
Stickiness: nbcco.Stickiness,
Check: nbcco.Check,
CheckInterval: nbcco.CheckInterval,
CheckAttempts: nbcco.CheckAttempts,
CheckPath: nbcco.CheckPath,
CheckBody: nbcco.CheckBody,
CheckPassive: *nbcco.CheckPassive,
CheckTimeout: nbcco.CheckTimeout,
CipherSuite: nbcco.CipherSuite,
NodeBalancerID: nbid,
SSLCommonName: "",
SSLFingerprint: "",
SSLCert: nbcco.SSLCert,
SSLKey: nbcco.SSLKey,
}
f.nbc[strconv.Itoa(nbcc.ID)] = &nbcc
resp, err := json.Marshal(nbcc)
if err != nil {
f.t.Fatal(err)
}
_, _ = w.Write(resp)
return
}
}
}

Expand Down
22 changes: 3 additions & 19 deletions cloud/linode/loadbalancers.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,15 +136,7 @@ func (l *loadbalancers) UpdateLoadBalancer(ctx context.Context, clusterName stri
return err
}

nb, err := l.lbByName(ctx, l.client, lbName)
if err != nil {
return err
}
jsonFilter, err := json.Marshal(map[string]string{"nodebalancer_id": strconv.Itoa(nb.ID)})
if err != nil {
return err
}
nbConfigs, err := l.client.ListNodeBalancerConfigs(ctx, lb.ID, linodego.NewListOptions(0, string(jsonFilter)))
nbConfigs, err := l.client.ListNodeBalancerConfigs(ctx, lb.ID, nil)
if err != nil {
return err
}
Expand Down Expand Up @@ -194,18 +186,10 @@ func (l *loadbalancers) UpdateLoadBalancer(ctx context.Context, clusterName stri

_, err = l.client.UpdateNodeBalancerConfig(ctx, lb.ID, nbc.ID, opt.GetUpdateOptions())
if err != nil {
return err
}

jsonFilter, err := json.Marshal(map[string]string{
"nodebalancer_id": strconv.Itoa(nb.ID),
"config_id": strconv.Itoa(nbc.ID),
})
if err != nil {
return err
return fmt.Errorf("Error updating NodeBalancer config: %v", err)
}

nodeList, err := l.client.ListNodeBalancerNodes(ctx, lb.ID, nbc.ID, linodego.NewListOptions(0, string(jsonFilter)))
nodeList, err := l.client.ListNodeBalancerNodes(ctx, lb.ID, nbc.ID, nil)
if err != nil {
return err
}
Expand Down
4 changes: 3 additions & 1 deletion cloud/linode/loadbalancers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -655,7 +655,6 @@ func testEnsureLoadBalancer(t *testing.T, client *linodego.Client) {
if !exists {
t.Fatal("Node balancer not found")
}
fmt.Println(nb.Ingress, "&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&")

testcases := []struct {
name string
Expand Down Expand Up @@ -718,6 +717,9 @@ func testEnsureLoadBalancer(t *testing.T, client *linodego.Client) {
for _, test := range testcases {
t.Run(test.name, func(t *testing.T) {
lbStatus, err := lb.EnsureLoadBalancer(context.TODO(), test.clusterName, test.service, test.nodes)
if err != nil {
t.Fatal(err)
}
if lbStatus.Ingress[0].IP != test.nbIP {
t.Error("unexpected error")
t.Logf("expected: %v", test.nbIP)
Expand Down

0 comments on commit 911501f

Please sign in to comment.