Skip to content

Commit

Permalink
move from juju/errors to pkg/errors
Browse files Browse the repository at this point in the history
  • Loading branch information
luthermonson committed Nov 16, 2020
1 parent aedcbad commit 4378130
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 23 deletions.
32 changes: 16 additions & 16 deletions backend/hostgw/hostgw_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,16 @@ package hostgw

import (
"fmt"
"github.com/coreos/flannel/pkg/routing"
"sync"
"time"

"github.com/Microsoft/hcsshim"
"github.com/coreos/flannel/backend"
"github.com/coreos/flannel/pkg/ip"
"github.com/coreos/flannel/pkg/routing"
"github.com/coreos/flannel/subnet"
log "github.com/golang/glog"
"github.com/juju/errors"
"github.com/pkg/errors"
"golang.org/x/net/context"
"k8s.io/apimachinery/pkg/util/json"
"k8s.io/apimachinery/pkg/util/wait"
Expand Down Expand Up @@ -61,7 +61,7 @@ func (be *HostgwBackend) RegisterNetwork(ctx context.Context, wg *sync.WaitGroup
}{}
if len(config.Backend) > 0 {
if err := json.Unmarshal(config.Backend, &cfg); err != nil {
return nil, errors.Annotate(err, "error decoding windows host-gw backend config")
return nil, errors.Wrap(err, "error decoding windows host-gw backend config")
}
}
if len(cfg.Name) == 0 {
Expand Down Expand Up @@ -101,7 +101,7 @@ func (be *HostgwBackend) RegisterNetwork(ctx context.Context, wg *sync.WaitGroup
return nil, err

default:
return nil, errors.Annotate(err, "failed to acquire lease")
return nil, errors.Wrap(err, "failed to acquire lease")
}

// 3. Check if the network exists and has the expected settings
Expand Down Expand Up @@ -129,7 +129,7 @@ func (be *HostgwBackend) RegisterNetwork(ctx context.Context, wg *sync.WaitGroup
if createNewNetwork {
if existingNetwork != nil {
if _, err := existingNetwork.Delete(); err != nil {
return nil, errors.Annotatef(err, "failed to delete existing HNSNetwork %s", networkName)
return nil, errors.Wrapf(err, "failed to delete existing HNSNetwork %s", networkName)
}
log.Infof("Deleted stale HNSNetwork %s", networkName)
}
Expand All @@ -147,13 +147,13 @@ func (be *HostgwBackend) RegisterNetwork(ctx context.Context, wg *sync.WaitGroup
}
jsonRequest, err := json.Marshal(expectedNetwork)
if err != nil {
return nil, errors.Annotatef(err, "failed to marshal %+v", expectedNetwork)
return nil, errors.Wrapf(err, "failed to marshal %+v", expectedNetwork)
}

log.Infof("Attempting to create HNSNetwork %s", string(jsonRequest))
newNetwork, err := hcsshim.HNSNetworkRequest("POST", "", string(jsonRequest))
if err != nil {
return nil, errors.Annotatef(err, "failed to create HNSNetwork %s", networkName)
return nil, errors.Wrapf(err, "failed to create HNSNetwork %s", networkName)
}

// Wait for the network to populate Management IP
Expand All @@ -163,22 +163,22 @@ func (be *HostgwBackend) RegisterNetwork(ctx context.Context, wg *sync.WaitGroup
return newNetwork != nil && len(newNetwork.ManagementIP) != 0, nil
})
if waitErr == wait.ErrWaitTimeout {
return nil, errors.Annotatef(waitErr, "timeout, failed to get management IP from HNSNetwork %s", networkName)
return nil, errors.Wrapf(waitErr, "timeout, failed to get management IP from HNSNetwork %s", networkName)
}

// Wait for the interface with the management IP
log.Infof("Waiting to get net interface for HNSNetwork %s (%s)", networkName, newNetwork.ManagementIP)
managementIP, err := ip.ParseIP4(newNetwork.ManagementIP)
if err != nil {
return nil, errors.Annotatef(err, "Failed to parse management ip (%s)", newNetwork.ManagementIP)
return nil, errors.Wrapf(err, "Failed to parse management ip (%s)", newNetwork.ManagementIP)
}

waitErr = wait.Poll(500*time.Millisecond, 5*time.Second, func() (done bool, err error) {
_, lastErr = ip.GetInterfaceByIP(managementIP.ToIP())
return lastErr == nil, nil
})
if waitErr == wait.ErrWaitTimeout {
return nil, errors.Annotatef(lastErr, "timeout, failed to get net interface for HNSNetwork %s (%s)", networkName, newNetwork.ManagementIP)
return nil, errors.Wrapf(lastErr, "timeout, failed to get net interface for HNSNetwork %s (%s)", networkName, newNetwork.ManagementIP)
}

log.Infof("Created HNSNetwork %s", networkName)
Expand All @@ -199,7 +199,7 @@ func (be *HostgwBackend) RegisterNetwork(ctx context.Context, wg *sync.WaitGroup
if createNewBridgeEndpoint {
if existingBridgeEndpoint != nil {
if _, err = existingBridgeEndpoint.Delete(); err != nil {
return nil, errors.Annotatef(err, "failed to delete existing bridge HNSEndpoint %s", bridgeEndpointName)
return nil, errors.Wrapf(err, "failed to delete existing bridge HNSEndpoint %s", bridgeEndpointName)
}
log.Infof("Deleted stale bridge HNSEndpoint %s", bridgeEndpointName)
}
Expand All @@ -212,7 +212,7 @@ func (be *HostgwBackend) RegisterNetwork(ctx context.Context, wg *sync.WaitGroup

log.Infof("Attempting to create bridge HNSEndpoint %+v", expectedBridgeEndpoint)
if expectedBridgeEndpoint, err = expectedBridgeEndpoint.Create(); err != nil {
return nil, errors.Annotatef(err, "failed to create bridge HNSEndpoint %s", bridgeEndpointName)
return nil, errors.Wrapf(err, "failed to create bridge HNSEndpoint %s", bridgeEndpointName)
}

log.Infof("Created bridge HNSEndpoint %s", bridgeEndpointName)
Expand All @@ -225,20 +225,20 @@ func (be *HostgwBackend) RegisterNetwork(ctx context.Context, wg *sync.WaitGroup
return lastErr == nil, nil
})
if waitErr == wait.ErrWaitTimeout {
return nil, errors.Annotatef(lastErr, "failed to hot attach bridge HNSEndpoint %s to host compartment", bridgeEndpointName)
return nil, errors.Wrapf(lastErr, "failed to hot attach bridge HNSEndpoint %s to host compartment", bridgeEndpointName)
}
log.Infof("Attached bridge endpoint %s to host successfully", bridgeEndpointName)

// 7. Enable forwarding on the host interface and endpoint
for _, interfaceIpAddress := range []string{expectedNetwork.ManagementIP, expectedBridgeEndpoint.IPAddress.String()} {
ipv4, err := ip.ParseIP4(interfaceIpAddress)
if err != nil {
return nil, errors.Annotatef(err, "Failed to parse expected net interface ip (%s)", interfaceIpAddress)
return nil, errors.Wrapf(err, "Failed to parse expected net interface ip (%s)", interfaceIpAddress)
}

netInterface, err := ip.GetInterfaceByIP(ipv4.ToIP())
if err != nil {
return nil, errors.Annotatef(err, "failed to find interface for IP Address %s", interfaceIpAddress)
return nil, errors.Wrapf(err, "failed to find interface for IP Address %s", interfaceIpAddress)
}
log.Infof("Found %+v interface with IP %s", netInterface, interfaceIpAddress)

Expand All @@ -249,7 +249,7 @@ func (be *HostgwBackend) RegisterNetwork(ctx context.Context, wg *sync.WaitGroup
}

if err := ip.EnableForwardingForInterface(netInterface); err != nil {
return nil, errors.Annotatef(err, "failed to enable forwarding on %s index %d", netInterface.Name, netInterface.Index)
return nil, errors.Wrapf(err, "failed to enable forwarding on %s index %d", netInterface.Name, netInterface.Index)
}
log.Infof("Enabled forwarding on %s index %d", netInterface.Name, netInterface.Index)
}
Expand Down
15 changes: 8 additions & 7 deletions backend/vxlan/device_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,13 @@ package vxlan

import (
"encoding/json"
"time"

"github.com/Microsoft/hcsshim/hcn"
"github.com/coreos/flannel/pkg/ip"
log "github.com/golang/glog"
"github.com/juju/errors"
"github.com/pkg/errors"
"k8s.io/apimachinery/pkg/util/wait"
"time"
)

type vxlanDeviceAttrs struct {
Expand Down Expand Up @@ -107,15 +108,15 @@ func ensureNetwork(expectedNetwork *hcn.HostComputeNetwork, expectedAddressPrefi
if createNetwork {
if existingNetwork != nil {
if err := existingNetwork.Delete(); err != nil {
return nil, errors.Annotatef(err, "failed to delete existing HostComputeNetwork %s", networkName)
return nil, errors.Wrapf(err, "failed to delete existing HostComputeNetwork %s", networkName)
}
log.Infof("Deleted stale HostComputeNetwork %s", networkName)
}

log.Infof("Attempting to create HostComputeNetwork %v", expectedNetwork)
newNetwork, err := expectedNetwork.Create()
if err != nil {
return nil, errors.Annotatef(err, "failed to create HostComputeNetwork %s", networkName)
return nil, errors.Wrapf(err, "failed to create HostComputeNetwork %s", networkName)
}

var waitErr, lastErr error
Expand All @@ -126,23 +127,23 @@ func ensureNetwork(expectedNetwork *hcn.HostComputeNetwork, expectedAddressPrefi
return newNetwork != nil && len(getManagementIP(newNetwork)) != 0, nil
})
if waitErr == wait.ErrWaitTimeout {
return nil, errors.Annotatef(lastErr, "timeout, failed to get management IP from HostComputeNetwork %s", networkName)
return nil, errors.Wrapf(lastErr, "timeout, failed to get management IP from HostComputeNetwork %s", networkName)
}

managementIP := getManagementIP(newNetwork)
// Wait for the interface with the management IP
log.Infof("Waiting to get net interface for HostComputeNetwork %s (%s)", networkName, managementIP)
managementIPv4, err := ip.ParseIP4(managementIP)
if err != nil {
return nil, errors.Annotatef(err, "Failed to parse management ip (%s)", managementIP)
return nil, errors.Wrapf(err, "Failed to parse management ip (%s)", managementIP)
}

waitErr = wait.Poll(500*time.Millisecond, 5*time.Second, func() (done bool, err error) {
_, lastErr = ip.GetInterfaceByIP(managementIPv4.ToIP())
return lastErr == nil, nil
})
if waitErr == wait.ErrWaitTimeout {
return nil, errors.Annotatef(lastErr, "timeout, failed to get net interface for HostComputeNetwork %s (%s)", networkName, managementIP)
return nil, errors.Wrapf(lastErr, "timeout, failed to get net interface for HostComputeNetwork %s (%s)", networkName, managementIP)
}

log.Infof("Created HostComputeNetwork %s", networkName)
Expand Down

0 comments on commit 4378130

Please sign in to comment.