Skip to content

Commit

Permalink
go-fmt updates and fixed windows dataplane unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
nwoodmsft committed Dec 5, 2017
1 parent 0a096f4 commit ac4d05e
Show file tree
Hide file tree
Showing 13 changed files with 122 additions and 105 deletions.
8 changes: 4 additions & 4 deletions dataplane-drivers/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ import (

"github.com/projectcalico/felix/config"
"github.com/projectcalico/felix/dataplane-drivers/extdataplane"
"github.com/projectcalico/felix/ifacemonitor"
"github.com/projectcalico/felix/dataplane-drivers/intdataplane"
"github.com/projectcalico/felix/ifacemonitor"
"github.com/projectcalico/felix/ipsets"
"github.com/projectcalico/felix/logutils"
"github.com/projectcalico/felix/rules"
Expand Down Expand Up @@ -92,7 +92,7 @@ func StartDataplaneDriver(configParams *config.Config, healthAggregator *health.
},
IPIPMTU: configParams.IpInIpMtu,
IptablesRefreshInterval: configParams.IptablesRefreshInterval,
RouteRefreshInterval: configParams.RouteRefreshInterval,
RouteRefreshInterval: configParams.RouteRefreshInterval,
IPSetsRefreshInterval: configParams.IpsetsRefreshInterval,
IptablesPostWriteCheckInterval: configParams.IptablesPostWriteCheckIntervalSecs,
IptablesInsertMode: configParams.ChainInsertMode,
Expand All @@ -106,8 +106,8 @@ func StartDataplaneDriver(configParams *config.Config, healthAggregator *health.

NetlinkTimeout: configParams.NetlinkTimeoutSecs,

PostInSyncCallback: func() { logutils.DumpHeapMemoryProfile(configParams) },
HealthAggregator: healthAggregator,
PostInSyncCallback: func() { logutils.DumpHeapMemoryProfile(configParams) },
HealthAggregator: healthAggregator,
DebugSimulateDataplaneHangAfter: configParams.DebugSimulateDataplaneHangAfter,
}
intDP := intdataplane.NewIntDataplaneDriver(dpConfig)
Expand Down
1 change: 1 addition & 0 deletions dataplane-drivers/driver_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"os/exec"

log "github.com/sirupsen/logrus"

"github.com/projectcalico/felix/config"
"github.com/projectcalico/felix/dataplane-drivers/windataplane"
"github.com/projectcalico/libcalico-go/lib/health"
Expand Down
2 changes: 1 addition & 1 deletion dataplane-drivers/intdataplane/int_dataplane_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ import (
. "github.com/onsi/gomega"

"github.com/projectcalico/felix/config"
"github.com/projectcalico/felix/ifacemonitor"
"github.com/projectcalico/felix/dataplane-drivers/intdataplane"
"github.com/projectcalico/felix/ifacemonitor"
"github.com/projectcalico/felix/ipsets"
"github.com/projectcalico/felix/rules"
"github.com/projectcalico/libcalico-go/lib/health"
Expand Down
43 changes: 22 additions & 21 deletions dataplane-drivers/windataplane/endpoint_mgr.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,17 @@
package windataplane

import (
"errors"
"os"
"strings"
"sync"
"time"
"errors"
"os"

log "github.com/sirupsen/logrus"
hns "github.com/Microsoft/hcsshim"
"github.com/projectcalico/felix/proto"
log "github.com/sirupsen/logrus"

"github.com/projectcalico/felix/dataplane-drivers/windataplane/policysets"
"github.com/projectcalico/felix/proto"
)

const (
Expand All @@ -46,7 +47,7 @@ const (

var (
ErrorUnknownEndpoint = errors.New("Endpoint could not be found")
ErrorUpdateFailed = errors.New("Endpoint update failed")
ErrorUpdateFailed = errors.New("Endpoint update failed")
)

// endpointManager processes WorkloadEndpoint* updates from the datastore. Updates are
Expand Down Expand Up @@ -81,11 +82,11 @@ func newEndpointManager(policysets policysets.PolicySetsDataplane) *endpointMana
}

return &endpointManager{
hnsNetworkName: networkName,
hnsNetworkName: networkName,
policysetsDataplane: policysets,
addressToEndpointId: make(map[string]string),
activeWlEndpoints: map[proto.WorkloadEndpointID]*proto.WorkloadEndpoint{},
pendingWlEpUpdates: map[proto.WorkloadEndpointID]*proto.WorkloadEndpoint{},
activeWlEndpoints: map[proto.WorkloadEndpointID]*proto.WorkloadEndpoint{},
pendingWlEpUpdates: map[proto.WorkloadEndpointID]*proto.WorkloadEndpoint{},
}
}

Expand All @@ -109,7 +110,7 @@ func (m *endpointManager) OnUpdate(msg interface{}) {
// last refresh or if a forceRefresh is requested (may happen if the endpointManager determines that
// a required endpoint id is not present in the cache).
func (m *endpointManager) RefreshHnsEndpointCache(forceRefresh bool) error {
if (!forceRefresh && (time.Since(m.lastCacheUpdate) < cacheTimeout)) {
if !forceRefresh && (time.Since(m.lastCacheUpdate) < cacheTimeout) {
return nil
}

Expand All @@ -129,12 +130,12 @@ func (m *endpointManager) RefreshHnsEndpointCache(forceRefresh bool) error {
for _, endpoint := range endpoints {
if strings.ToLower(endpoint.VirtualNetworkName) == strings.ToLower(m.hnsNetworkName) {
ip := endpoint.IPAddress.String() + ipv4AddrSuffix
log.WithFields(log.Fields{"IPAddress":ip,"EndpointId":endpoint.Id}).Debug("Adding HNS Endpoint Id entry to cache")
log.WithFields(log.Fields{"IPAddress": ip, "EndpointId": endpoint.Id}).Debug("Adding HNS Endpoint Id entry to cache")
m.addressToEndpointId[ip] = endpoint.Id
}
}

log.Infof("Cache refresh is complete. %v endpoints were cached", len(m.addressToEndpointId))
log.Infof("Cache refresh is complete. %v endpoints were cached", len(m.addressToEndpointId))
m.lastCacheUpdate = time.Now()

m.endpointLock.Unlock()
Expand Down Expand Up @@ -171,11 +172,11 @@ func (m *endpointManager) ProcessIpSetUpdate(ipSetId string) {
}
}

Policies:
Policies:
for _, policyName := range activePolicyNames {
for _, updatedPolicy := range updatedPolicies {
if policyName == updatedPolicy {
log.WithFields(log.Fields{"policyName":policyName, "endpointId":endpointId}).Info("Endpoint is being marked for policy refresh")
log.WithFields(log.Fields{"policyName": policyName, "endpointId": endpointId}).Info("Endpoint is being marked for policy refresh")
m.pendingWlEpUpdates[endpointId] = workload
break Policies
}
Expand All @@ -202,17 +203,17 @@ func (m *endpointManager) CompleteDeferredWork() error {
var endpointId string

// A non-nil workload indicates this is a pending add or update operation
if (workload != nil) {
if workload != nil {
for _, ip := range workload.Ipv4Nets {
var err error
logCxt.WithField("ip", ip).Debug("Resolving workload ip to hns endpoint Id")
endpointId, err = m.getHnsEndpointId(ip)
if (err == nil && endpointId != "") {
if err == nil && endpointId != "" {
// Resolution was successful
break
}
}
if (endpointId == "") {
if endpointId == "" {
// Failed to find the associated hns endpoint id
return ErrorUnknownEndpoint
}
Expand All @@ -231,7 +232,7 @@ func (m *endpointManager) CompleteDeferredWork() error {
}

err := m.applyRules(id, endpointId, policyNames)
if (err != nil) {
if err != nil {
// Failed to apply, this will be rescheduled and retried
return err
}
Expand All @@ -253,11 +254,11 @@ func (m *endpointManager) CompleteDeferredWork() error {
// applyRules gathers all of the rules for the specified policies and sends them to hns
// as an endpoint policy update (this actually applies the rules to the dataplane).
func (m *endpointManager) applyRules(workloadId proto.WorkloadEndpointID, endpointId string, policyNames []string) error {
logCxt := log.WithFields(log.Fields{"id":workloadId, "endpointId":endpointId})
logCxt := log.WithFields(log.Fields{"id": workloadId, "endpointId": endpointId})
logCxt.WithField("policies", policyNames).Info("Applying endpoint rules")

var rules []*hns.ACLPolicy
if (len(policyNames) > 0) {
if len(policyNames) > 0 {
rules = m.policysetsDataplane.GetPolicySetRules(policyNames)
for _, rule := range rules {
logCxt.WithField("rule", rule).Debug("Complete set of rules to be applied")
Expand Down Expand Up @@ -289,8 +290,8 @@ func (m *endpointManager) getHnsEndpointId(ip string) (string, error) {
m.endpointLock.RLock()
id, ok := m.addressToEndpointId[ip]
m.endpointLock.RUnlock()
if (ok) {
log.WithFields(log.Fields{"ip":ip, "id":id}).Info("Resolved hns endpoint id")
if ok {
log.WithFields(log.Fields{"ip": ip, "id": id}).Info("Resolved hns endpoint id")
return id, nil
}

Expand Down
4 changes: 2 additions & 2 deletions dataplane-drivers/windataplane/ipsets/ipset_defs.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ import (

// IPSetMetadata contains the metadata for a particular IP set, such as its name and type.
type IPSetMetadata struct {
SetID string
Type IPSetType
SetID string
Type IPSetType
}

// IPSetsDataplane is interface for managing a plane of ipSet objects.
Expand Down
15 changes: 8 additions & 7 deletions dataplane-drivers/windataplane/ipsets/ipsets.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,21 @@ import (
"strings"

log "github.com/sirupsen/logrus"

"github.com/projectcalico/felix/dataplane-drivers/windataplane/set"
)

// IPSets manages a whole plane of IP sets, i.e. all the IPv4 sets, or all the IPv6 IP sets.
type IPSets struct {
IPVersionConfig *IPVersionConfig
ipSetIDToIPSet map[string]*ipSet
logCxt *log.Entry
ipSetIDToIPSet map[string]*ipSet
logCxt *log.Entry
}

func NewIPSets(ipVersionConfig *IPVersionConfig) *IPSets {
return &IPSets{
IPVersionConfig: ipVersionConfig,
ipSetIDToIPSet: map[string]*ipSet{},
ipSetIDToIPSet: map[string]*ipSet{},
logCxt: log.WithFields(log.Fields{
"family": ipVersionConfig.Family,
}),
Expand All @@ -52,7 +53,7 @@ func (s *IPSets) AddOrReplaceIPSet(setMetadata IPSetMetadata, members []string)
setID := setMetadata.SetID
ipSet := &ipSet{
IPSetMetadata: setMetadata,
Members: filteredMembers,
Members: filteredMembers,
}
s.ipSetIDToIPSet[setID] = ipSet
}
Expand All @@ -75,7 +76,7 @@ func (s *IPSets) AddMembers(setID string, newMembers []string) {
return
}
s.logCxt.WithFields(log.Fields{
"setID": setID,
"setID": setID,
"filteredMembers": filteredMembers,
}).Info("Adding new members to IP set")
filteredMembers.Iter(func(m interface{}) error {
Expand All @@ -96,7 +97,7 @@ func (s *IPSets) RemoveMembers(setID string, removedMembers []string) {
return
}
s.logCxt.WithFields(log.Fields{
"setID": setID,
"setID": setID,
"filteredMembers": filteredMembers,
}).Info("Removing members from IP set")

Expand All @@ -111,7 +112,7 @@ func (s *IPSets) GetIPSetMembers(setID string) []string {
var retVal []string

ipSet := s.ipSetIDToIPSet[setID]
if (ipSet == nil) {
if ipSet == nil {
return nil
}

Expand Down
6 changes: 3 additions & 3 deletions dataplane-drivers/windataplane/ipsets_mgr.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ package windataplane
import (
log "github.com/sirupsen/logrus"

"github.com/projectcalico/felix/proto"
"github.com/projectcalico/felix/dataplane-drivers/windataplane/ipsets"
"github.com/projectcalico/felix/proto"
)

// ipSetsManager simply passes through IP set updates from the datastore to the ipsets.IPSets
Expand All @@ -46,8 +46,8 @@ func (m *ipSetsManager) OnUpdate(msg interface{}) {
case *proto.IPSetUpdate:
log.WithField("ipSetId", msg.Id).Info("Processing IPSetUpdate")
metadata := ipsets.IPSetMetadata{
Type: ipsets.IPSetTypeHashIP,
SetID: msg.Id,
Type: ipsets.IPSetTypeHashIP,
SetID: msg.Id,
}
m.ipsetsDataplane.AddOrReplaceIPSet(metadata, msg.Members)
case *proto.IPSetRemove:
Expand Down
2 changes: 1 addition & 1 deletion dataplane-drivers/windataplane/policy_mgr.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ package windataplane
import (
log "github.com/sirupsen/logrus"

"github.com/projectcalico/felix/proto"
"github.com/projectcalico/felix/dataplane-drivers/windataplane/policysets"
"github.com/projectcalico/felix/proto"
)

// policyManager simply passes through Policy and Profile updates from the datastore to the
Expand Down
7 changes: 4 additions & 3 deletions dataplane-drivers/windataplane/policysets/policyset_defs.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"errors"

hns "github.com/Microsoft/hcsshim"

"github.com/projectcalico/felix/dataplane-drivers/windataplane/set"
)

Expand All @@ -33,15 +34,15 @@ const (
)

var (
SkipRule = errors.New("Rule skipped")
SkipRule = errors.New("Rule skipped")
MissingSet = errors.New("Missing IPSet")
)

// PolicySetType constants for the different kinds of Policy set.
type PolicySetType string

const (
PolicySetTypePolicy PolicySetType = "policy"
PolicySetTypePolicy PolicySetType = "policy"
PolicySetTypeProfile PolicySetType = "profile"
)

Expand All @@ -52,7 +53,7 @@ func (t PolicySetType) SetType() string {
// PolicySetMetadata contains the metadata for a particular Policy set, such as its name and type.
type PolicySetMetadata struct {
SetId string
Type PolicySetType
Type PolicySetType
}

// PolicySetsDataplane is a interface for managing a plane of policySet objects
Expand Down
Loading

0 comments on commit ac4d05e

Please sign in to comment.