From ac4d05eaf9673cbdabbd34d78bf14dc08d8dc75a Mon Sep 17 00:00:00 2001 From: Nick Wood Date: Thu, 30 Nov 2017 03:20:59 -0800 Subject: [PATCH] go-fmt updates and fixed windows dataplane unit test --- dataplane-drivers/driver.go | 8 +- dataplane-drivers/driver_windows.go | 1 + .../intdataplane/int_dataplane_test.go | 2 +- .../windataplane/endpoint_mgr.go | 43 +++---- .../windataplane/ipsets/ipset_defs.go | 4 +- .../windataplane/ipsets/ipsets.go | 15 +-- dataplane-drivers/windataplane/ipsets_mgr.go | 6 +- dataplane-drivers/windataplane/policy_mgr.go | 2 +- .../windataplane/policysets/policyset_defs.go | 7 +- .../windataplane/policysets/policysets.go | 117 ++++++++++-------- .../windataplane/win_dataplane.go | 16 +-- .../windataplane/win_dataplane_test.go | 4 +- logutils/logutils_windows.go | 2 +- 13 files changed, 122 insertions(+), 105 deletions(-) diff --git a/dataplane-drivers/driver.go b/dataplane-drivers/driver.go index 11871a3bd1..28632aee66 100644 --- a/dataplane-drivers/driver.go +++ b/dataplane-drivers/driver.go @@ -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" @@ -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, @@ -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) diff --git a/dataplane-drivers/driver_windows.go b/dataplane-drivers/driver_windows.go index 23d03f38ac..5a64906003 100644 --- a/dataplane-drivers/driver_windows.go +++ b/dataplane-drivers/driver_windows.go @@ -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" diff --git a/dataplane-drivers/intdataplane/int_dataplane_test.go b/dataplane-drivers/intdataplane/int_dataplane_test.go index 43ec848943..3fa1935dda 100644 --- a/dataplane-drivers/intdataplane/int_dataplane_test.go +++ b/dataplane-drivers/intdataplane/int_dataplane_test.go @@ -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" diff --git a/dataplane-drivers/windataplane/endpoint_mgr.go b/dataplane-drivers/windataplane/endpoint_mgr.go index efafd452d9..bbc13618e7 100644 --- a/dataplane-drivers/windataplane/endpoint_mgr.go +++ b/dataplane-drivers/windataplane/endpoint_mgr.go @@ -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 ( @@ -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 @@ -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{}, } } @@ -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 } @@ -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() @@ -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 } @@ -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 } @@ -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 } @@ -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") @@ -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 } diff --git a/dataplane-drivers/windataplane/ipsets/ipset_defs.go b/dataplane-drivers/windataplane/ipsets/ipset_defs.go index 8e6e2c97c6..6134740e5b 100644 --- a/dataplane-drivers/windataplane/ipsets/ipset_defs.go +++ b/dataplane-drivers/windataplane/ipsets/ipset_defs.go @@ -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. diff --git a/dataplane-drivers/windataplane/ipsets/ipsets.go b/dataplane-drivers/windataplane/ipsets/ipsets.go index d05f59d90c..776f25e544 100644 --- a/dataplane-drivers/windataplane/ipsets/ipsets.go +++ b/dataplane-drivers/windataplane/ipsets/ipsets.go @@ -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, }), @@ -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 } @@ -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 { @@ -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") @@ -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 } diff --git a/dataplane-drivers/windataplane/ipsets_mgr.go b/dataplane-drivers/windataplane/ipsets_mgr.go index 4a2f18f6be..3a833726b0 100644 --- a/dataplane-drivers/windataplane/ipsets_mgr.go +++ b/dataplane-drivers/windataplane/ipsets_mgr.go @@ -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 @@ -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: diff --git a/dataplane-drivers/windataplane/policy_mgr.go b/dataplane-drivers/windataplane/policy_mgr.go index e76cd9eb47..7c4f21c46e 100644 --- a/dataplane-drivers/windataplane/policy_mgr.go +++ b/dataplane-drivers/windataplane/policy_mgr.go @@ -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 diff --git a/dataplane-drivers/windataplane/policysets/policyset_defs.go b/dataplane-drivers/windataplane/policysets/policyset_defs.go index ff2da38be4..3364c8731c 100644 --- a/dataplane-drivers/windataplane/policysets/policyset_defs.go +++ b/dataplane-drivers/windataplane/policysets/policyset_defs.go @@ -20,6 +20,7 @@ import ( "errors" hns "github.com/Microsoft/hcsshim" + "github.com/projectcalico/felix/dataplane-drivers/windataplane/set" ) @@ -33,7 +34,7 @@ const ( ) var ( - SkipRule = errors.New("Rule skipped") + SkipRule = errors.New("Rule skipped") MissingSet = errors.New("Missing IPSet") ) @@ -41,7 +42,7 @@ var ( type PolicySetType string const ( - PolicySetTypePolicy PolicySetType = "policy" + PolicySetTypePolicy PolicySetType = "policy" PolicySetTypeProfile PolicySetType = "profile" ) @@ -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 diff --git a/dataplane-drivers/windataplane/policysets/policysets.go b/dataplane-drivers/windataplane/policysets/policysets.go index 6f88a057e5..3269b6b207 100644 --- a/dataplane-drivers/windataplane/policysets/policysets.go +++ b/dataplane-drivers/windataplane/policysets/policysets.go @@ -19,11 +19,12 @@ package policysets import ( "strings" - log "github.com/sirupsen/logrus" hns "github.com/Microsoft/hcsshim" - "github.com/projectcalico/felix/proto" - "github.com/projectcalico/felix/dataplane-drivers/windataplane/set" + log "github.com/sirupsen/logrus" + "github.com/projectcalico/felix/dataplane-drivers/windataplane/ipsets" + "github.com/projectcalico/felix/dataplane-drivers/windataplane/set" + "github.com/projectcalico/felix/proto" ) // PolicySets manages a whole plane of policies/profiles @@ -38,7 +39,7 @@ type PolicySets struct { func NewPolicySets(ipsets []*ipsets.IPSets) *PolicySets { return &PolicySets{ policySetIdToPolicySet: map[string]*policySet{}, - IpSets: ipsets, + IpSets: ipsets, } } @@ -76,9 +77,9 @@ func (s *PolicySets) AddOrReplacePolicySet(setId string, policy interface{}) { // Create the struct and store it off policySet := &policySet{ PolicySetMetadata: setMetadata, - Policy: policy, - Members: set.FromArray(rules), - IpSetIds: policyIpSetIds, + Policy: policy, + Members: set.FromArray(rules), + IpSetIds: policyIpSetIds, } s.policySetIdToPolicySet[setMetadata.SetId] = policySet } @@ -100,11 +101,11 @@ func (s *PolicySets) GetPolicySetRules(setIds []string) (rules []*hns.ACLPolicy) // Rules from the first set will receive the default rule priority currentPriority := rulePriority - for _,setId := range setIds { + for _, setId := range setIds { log.WithField("setId", setId).Debug("Gathering rules for policy set") policySet := s.policySetIdToPolicySet[setId] - if (policySet == nil) { + if policySet == nil { log.WithField("setId", setId).Error("Unable to find Policy set, this set will be skipped") continue } @@ -131,7 +132,6 @@ func (s *PolicySets) GetPolicySetRules(setIds []string) (rules []*hns.ACLPolicy) return } - // ProcessIpSetUpdate locates any Policy set(s) which reference the provided IP set, and causes // those Policy sets to be recomputed (to ensure any rule address conditions are using the latest // addres values from the IP set). A list of the Policy sets which were found and recomputed are @@ -143,11 +143,11 @@ func (s *PolicySets) ProcessIpSetUpdate(ipSetId string) []string { return nil } - log.WithFields(log.Fields{"IPSetId":ipSetId, "Policies":stalePolicies}).Info("Associated policies need to be refreshed") + log.WithFields(log.Fields{"IPSetId": ipSetId, "Policies": stalePolicies}).Info("Associated policies need to be refreshed") for _, policyId := range stalePolicies { policySet := s.policySetIdToPolicySet[policyId] - if (policySet == nil) { - log.WithFields(log.Fields{"IPSetId":ipSetId, "Policy":policyId}).Error("Unable to find Policy set, this set will be skipped") + if policySet == nil { + log.WithFields(log.Fields{"IPSetId": ipSetId, "Policy": policyId}).Error("Unable to find Policy set, this set will be skipped") continue } @@ -163,7 +163,7 @@ func (s *PolicySets) getPoliciesByIpSetId(ipSetId string) (policies []string) { for policySetId, policySet := range s.policySetIdToPolicySet { policySet.IpSetIds.Iter(func(item interface{}) error { id := item.(string) - if (id == ipSetId) { + if id == ipSetId { policies = append(policies, policySetId) } return nil @@ -264,16 +264,24 @@ func (s *PolicySets) protoRuleToHnsRules(policyId string, pRule *proto.Rule, isI ruleCopy := *pRule ruleCopy.SrcNet, filteredAll = filterNets(pRule.SrcNet, ipVersion) - if filteredAll { return nil, SkipRule } + if filteredAll { + return nil, SkipRule + } ruleCopy.NotSrcNet, filteredAll = filterNets(pRule.NotSrcNet, ipVersion) - if filteredAll { return nil, SkipRule } + if filteredAll { + return nil, SkipRule + } ruleCopy.DstNet, filteredAll = filterNets(pRule.DstNet, ipVersion) - if filteredAll { return nil, SkipRule } + if filteredAll { + return nil, SkipRule + } ruleCopy.NotDstNet, filteredAll = filterNets(pRule.NotDstNet, ipVersion) - if filteredAll { return nil, SkipRule } + if filteredAll { + return nil, SkipRule + } // Log with the rule details for context logCxt := log.WithField("rule", ruleCopy) @@ -300,11 +308,11 @@ func (s *PolicySets) protoRuleToHnsRules(policyId string, pRule *proto.Rule, isI // // Source ports // - if (len(ruleCopy.SrcPorts) > 0) { + if len(ruleCopy.SrcPorts) > 0 { // Windows RS3 limitation, single port ports := uint16(ruleCopy.SrcPorts[0].First) - if (isInbound) { + if isInbound { aclPolicy.RemotePort = ports logCxt.WithField("RemotePort", aclPolicy.RemotePort).Debug("Adding Source Ports as RemotePort condition") } else { @@ -316,11 +324,11 @@ func (s *PolicySets) protoRuleToHnsRules(policyId string, pRule *proto.Rule, isI // // Destination Ports // - if (len(ruleCopy.DstPorts) > 0) { + if len(ruleCopy.DstPorts) > 0 { // Windows RS3 limitation, single port (start port) ports := uint16(ruleCopy.DstPorts[0].First) - if (isInbound) { + if isInbound { aclPolicy.LocalPort = ports logCxt.WithField("LocalPort", aclPolicy.LocalPort).Debug("Adding Destination Ports as LocalPort condition") } else { @@ -351,7 +359,7 @@ func (s *PolicySets) protoRuleToHnsRules(policyId string, pRule *proto.Rule, isI srcAddresses := ruleCopy.SrcNet - if (len(ruleCopy.SrcIpSetIds) > 0) { + if len(ruleCopy.SrcIpSetIds) > 0 { ipsetAddresses, err := s.getIPSetAddresses(ruleCopy.SrcIpSetIds) if err != nil { logCxt.Info("SrcIpSetIds could not be resolved, rule will be skipped") @@ -360,8 +368,8 @@ func (s *PolicySets) protoRuleToHnsRules(policyId string, pRule *proto.Rule, isI srcAddresses = append(srcAddresses, ipsetAddresses...) } - if (len(srcAddresses) > 0) { - if (isInbound) { + if len(srcAddresses) > 0 { + if isInbound { remoteAddresses = srcAddresses logCxt.WithField("RemoteAddress", remoteAddresses).Debug("Adding Source Networks/IPsets as RemoteAddress conditions") } else { @@ -375,7 +383,7 @@ func (s *PolicySets) protoRuleToHnsRules(policyId string, pRule *proto.Rule, isI // dstAddresses := ruleCopy.DstNet - if (len(ruleCopy.DstIpSetIds) > 0) { + if len(ruleCopy.DstIpSetIds) > 0 { ipsetAddresses, err := s.getIPSetAddresses(ruleCopy.DstIpSetIds) if err != nil { logCxt.Info("DstIpSetIds could not be resolved, rule will be skipped") @@ -384,8 +392,8 @@ func (s *PolicySets) protoRuleToHnsRules(policyId string, pRule *proto.Rule, isI dstAddresses = append(dstAddresses, ipsetAddresses...) } - if (len(dstAddresses) > 0) { - if (isInbound) { + if len(dstAddresses) > 0 { + if isInbound { localAddresses = dstAddresses logCxt.WithField("LocalAddress", localAddresses).Debug("Adding Destination Networks/IPsets as LocalAddress condition") } else { @@ -398,8 +406,8 @@ func (s *PolicySets) protoRuleToHnsRules(policyId string, pRule *proto.Rule, isI // source or destination condition. The behavior below will be removed in // the next iteration, but for now we have to break up the source and destination // ip address combinations and represent them using multiple rules - for _,localAddr := range localAddresses { - for _,remoteAddr := range remoteAddresses { + for _, localAddr := range localAddresses { + for _, remoteAddr := range remoteAddresses { newPolicy := *aclPolicy newPolicy.LocalAddresses = localAddr newPolicy.RemoteAddresses = remoteAddr @@ -453,7 +461,7 @@ func (s *PolicySets) getIPSetAddresses(setIds []string) ([]string, error) { found = false for _, ipSets := range s.IpSets { ipSet := ipSets.GetIPSetMembers(ipsetId) - if (ipSet == nil) { + if ipSet == nil { continue } addresses = append(addresses, ipSet...) @@ -461,7 +469,7 @@ func (s *PolicySets) getIPSetAddresses(setIds []string) ([]string, error) { break } - if (!found) { + if !found { log.WithField("ipsetId", ipsetId).Info("IPSet could not be found") return nil, MissingSet } @@ -473,13 +481,20 @@ func (s *PolicySets) getIPSetAddresses(setIds []string) ([]string, error) { // protocolNameToNumber converts a protocol name to its numeric representation (returned as string) func protocolNameToNumber(protocolName string) uint16 { switch strings.ToLower(protocolName) { - case "tcp": return 6 - case "udp": return 17 - case "icmp": return 1 - case "icmpv6": return 58 - case "sctp": return 132 - case "udplite": return 136 - default: return 256 // any (as understood by hns) + case "tcp": + return 6 + case "udp": + return 17 + case "icmp": + return 1 + case "icmpv6": + return 58 + case "sctp": + return 132 + case "udplite": + return 136 + default: + return 256 // any (as understood by hns) } } @@ -490,13 +505,13 @@ func (s *PolicySets) NewRule(isInbound bool, priority uint16) *hns.ACLPolicy { direction = hns.In } - return &hns.ACLPolicy { - Type: hns.ACL, - RuleType: hns.Switch, - Action: hns.Block, + return &hns.ACLPolicy{ + Type: hns.ACL, + RuleType: hns.Switch, + Action: hns.Block, Direction: direction, - Protocol: 256, // Any, only required for RS3 - Priority: priority, + Protocol: 256, // Any, only required for RS3 + Priority: priority, } } @@ -508,13 +523,13 @@ func (s *PolicySets) NewHostRule(isInbound bool) *hns.ACLPolicy { direction = hns.In } - return &hns.ACLPolicy { - Type: hns.ACL, - RuleType: hns.Host, - Action: hns.Allow, + return &hns.ACLPolicy{ + Type: hns.ACL, + RuleType: hns.Host, + Action: hns.Allow, Direction: direction, - Priority: 100, - Protocol: 256, // Any + Priority: 100, + Protocol: 256, // Any } } diff --git a/dataplane-drivers/windataplane/win_dataplane.go b/dataplane-drivers/windataplane/win_dataplane.go index 59ef88d87f..9a501397dc 100644 --- a/dataplane-drivers/windataplane/win_dataplane.go +++ b/dataplane-drivers/windataplane/win_dataplane.go @@ -21,11 +21,12 @@ import ( "time" log "github.com/sirupsen/logrus" + + "github.com/projectcalico/felix/dataplane-drivers/windataplane/ipsets" + "github.com/projectcalico/felix/dataplane-drivers/windataplane/policysets" "github.com/projectcalico/felix/jitter" "github.com/projectcalico/felix/proto" "github.com/projectcalico/felix/throttle" - "github.com/projectcalico/felix/dataplane-drivers/windataplane/policysets" - "github.com/projectcalico/felix/dataplane-drivers/windataplane/ipsets" ) const ( @@ -73,7 +74,7 @@ type Config struct { // event before it sends a rule that references that IP set. type WindowsDataplane struct { // the channel which we receive messages from felix - toDataplane chan interface{} + toDataplane chan interface{} // the channel used to send messages from the dataplane to felix fromDataplane chan interface{} // stores all of the managers which will be processing the various updates from felix. @@ -129,10 +130,10 @@ func NewWinDataplaneDriver(config Config) *WindowsDataplane { ipSetsV4 := ipsets.NewIPSets(ipSetsConfigV4) dp := &WindowsDataplane{ - toDataplane: make(chan interface{}, msgPeekLimit), - fromDataplane: make(chan interface{}, 100), - config: config, - applyThrottle: throttle.New(10), + toDataplane: make(chan interface{}, msgPeekLimit), + fromDataplane: make(chan interface{}, 100), + config: config, + applyThrottle: throttle.New(10), } dp.applyThrottle.Refill() // Allow the first apply() immediately. @@ -161,7 +162,6 @@ func (d *WindowsDataplane) SendMessage(msg interface{}) error { return nil } - // Called by Felix.go so that it can receive a channel to listen for message being // sent by this dataplane driver. func (d *WindowsDataplane) RecvMessage() (interface{}, error) { diff --git a/dataplane-drivers/windataplane/win_dataplane_test.go b/dataplane-drivers/windataplane/win_dataplane_test.go index b22031971c..9f03b22e96 100644 --- a/dataplane-drivers/windataplane/win_dataplane_test.go +++ b/dataplane-drivers/windataplane/win_dataplane_test.go @@ -15,8 +15,6 @@ package windataplane_test import ( - "net" - . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" @@ -26,7 +24,7 @@ import ( var _ = Describe("Constructor test", func() { var configParams *config.Config - var dpConfig intdataplane.Config + var dpConfig windataplane.Config JustBeforeEach(func() { configParams = config.New() diff --git a/logutils/logutils_windows.go b/logutils/logutils_windows.go index 4d35d8b809..7be12eca19 100644 --- a/logutils/logutils_windows.go +++ b/logutils/logutils_windows.go @@ -164,7 +164,7 @@ func DumpHeapMemoryOnSignal(configParams *config.Config) { // A simple io.Writer for logging to file type FileWriter struct { - file *os.File + file *os.File } func (f *FileWriter) Write(p []byte) (int, error) {