Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade golang to 1.22.3 #705

Merged
merged 1 commit into from
Nov 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .ci/Dockerfile.depend
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ RUN apt-get update \
&& DEBIAN_FRONTEND=noninteractive apt-get install -y -qq \
apt-utils wget cmake curl git

ENV GOVERSION=1.21.3
ENV GOVERSION=1.22.3
ENV GOROOT="/root/.go"
ENV GOPATH="/root/go"
ENV PATH=$GOROOT/bin:$PATH
Expand All @@ -22,7 +22,7 @@ RUN mkdir -p "${GOROOT}" &&\
RUN wget -nv "https://dl.google.com/go/go${GOVERSION}.linux-amd64.tar.gz" -O "/tmp/go.tar.gz" && \
tar -C "${GOROOT}" --strip-components=1 -xzf "/tmp/go.tar.gz" && \
rm -f "/tmp/go.tar.gz" && \
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.54.2
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.61.0

# Get modules used by the source code
COPY . /vpp-dataplane
Expand Down
84 changes: 80 additions & 4 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,30 @@
run:
timeout: 5m
linters-settings:
errcheck:
check-type-assertions: true
goconst:
min-len: 2
min-occurrences: 3
gocritic:
enabled-tags:
- diagnostic
- experimental
- opinionated
- performance
- style
govet:
shadow:
# Whether to be strict about shadowing; can be noisy.
# Default: false
strict: true
nolintlint:
require-explanation: true
require-specific: true
linters:
# Disable all linters.
# Default: false
# disable-all: true
# Enable specific linter
# https://golangci-lint.run/usage/linters/#enabled-by-default
enable:
- errcheck
- gofmt
Expand All @@ -12,6 +36,58 @@ linters:
- staticcheck
- typecheck
- unused
# Run only fast linters from enabled linters set (first run won't be fast)
# Default: false
fast: true
run:
# The default concurrency value is the number of available CPU.
concurrency: 4
# Timeout for analysis, e.g. 30s, 5m.
# Default: 1m
timeout: 5m
# Include test files or not.
# Default: true
tests: false
# Which dirs to skip: issues from them won't be reported.
# Can use regexp here: `generated.*`, regexp is applied on full path,
# including the path prefix if one is set.
# Default value is empty list,
# but default dirs are skipped independently of this option's value (see skip-dirs-use-default).
# "/" will be replaced by current OS file path separator to properly work on Windows.
# skip-dirs:
# - src/external_libs
# - autogenerated_by_my_lib
# Enables skipping of directories:
# - vendor$, third_party$, testdata$, examples$, Godeps$, builtin$
# Default: true
# skip-dirs-use-default: false
# Which files to skip: they will be analyzed, but issues from them won't be reported.
# Default value is empty list,
# but there is no need to include all autogenerated files,
# we confidently recognize autogenerated files.
# If it's not please let us know.
# "/" will be replaced by current OS file path separator to properly work on Windows.
# skip-files:
# - ".*\\.my\\.go$"
# - lib/bad.go
# If set we pass it to "go list -mod={option}". From "go help modules":
# If invoked with -mod=readonly, the go command is disallowed from the implicit
# automatic updating of go.mod described above. Instead, it fails when any changes
# to go.mod are needed. This setting is most useful to check that go.mod does
# not need updates, such as in a continuous integration and testing system.
# If invoked with -mod=vendor, the go command assumes that the vendor
# directory holds the correct copies of dependencies and ignores
# the dependency descriptions in go.mod.
#
# Allowed values: readonly|vendor|mod
# By default, it isn't set.
# modules-download-mode: readonly
# Allow multiple parallel golangci-lint instances running.
# If false (default) - golangci-lint acquires file lock on start.
allow-parallel-runners: false
output:
format: tab
sort-results: true
formats:
- format: tab
path: stderr
sort-results: true

12 changes: 10 additions & 2 deletions calico-vpp-agent/cni/cni_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -550,10 +550,18 @@ func (s *Server) ServeCNI(t *tomb.Tomb) error {
case common.NetsSynced:
netsSynced <- true
case common.NetAddedOrUpdated:
netDef := event.New.(*watchers.NetworkDefinition)
netDef, ok := event.New.(*watchers.NetworkDefinition)
if !ok {
s.log.Errorf("event.New is not a *watchers.NetworkDefinition %v", event.New)
continue
}
s.networkDefinitions.Store(netDef.Name, netDef)
case common.NetDeleted:
netDef := event.Old.(*watchers.NetworkDefinition)
netDef, ok := event.Old.(*watchers.NetworkDefinition)
if !ok {
s.log.Errorf("event.Old is not a *watchers.NetworkDefinition %v", event.Old)
continue
}
s.networkDefinitions.Delete(netDef.Name)
}
}
Expand Down
60 changes: 48 additions & 12 deletions calico-vpp-agent/connectivity/connectivity_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,35 +153,59 @@ func (s *ConnectivityServer) ServeConnectivity(t *tomb.Tomb) error {
/* Note: we will only receive events we ask for when registering the chan */
switch evt.Type {
case common.NetAddedOrUpdated:
new := evt.New.(*watchers.NetworkDefinition)
new, ok := evt.New.(*watchers.NetworkDefinition)
if !ok {
s.log.Errorf("evt.New is not a *watchers.NetworkDefinition %v", evt.New)
}
s.networks[new.Vni] = *new
case common.NetDeleted:
old := evt.Old.(*watchers.NetworkDefinition)
old, ok := evt.Old.(*watchers.NetworkDefinition)
if !ok {
s.log.Errorf("evt.Old is not a *watchers.NetworkDefinition %v", evt.Old)
}
delete(s.networks, old.Vni)
case common.ConnectivityAdded:
new := evt.New.(*common.NodeConnectivity)
new, ok := evt.New.(*common.NodeConnectivity)
if !ok {
s.log.Errorf("evt.New is not a *common.NodeConnectivity %v", evt.New)
}
err := s.UpdateIPConnectivity(new, false /* isWithdraw */)
if err != nil {
s.log.Errorf("Error while adding connectivity %s", err)
}
case common.ConnectivityDeleted:
old := evt.Old.(*common.NodeConnectivity)
old, ok := evt.Old.(*common.NodeConnectivity)
if !ok {
s.log.Errorf("evt.Old is not a *common.NodeConnectivity %v", evt.Old)
}
err := s.UpdateIPConnectivity(old, true /* isWithdraw */)
if err != nil {
s.log.Errorf("Error while deleting connectivity %s", err)
}
case common.WireguardPublicKeyChanged:
old, _ := evt.Old.(*common.NodeWireguardPublicKey)
new, _ := evt.New.(*common.NodeWireguardPublicKey)
old, ok := evt.Old.(*common.NodeWireguardPublicKey)
if !ok {
s.log.Errorf("evt.Old is not a *common.NodeWireguardPublicKey %v", evt.Old)
}
new, ok := evt.New.(*common.NodeWireguardPublicKey)
if !ok {
s.log.Errorf("evt.New is not a *common.NodeWireguardPublicKey %v", evt.New)
}
s.providers[WIREGUARD].(*WireguardProvider).nodesToWGPublicKey[new.Name] = new.WireguardPublicKey
change := common.GetStringChangeType(old.WireguardPublicKey, new.WireguardPublicKey)
if change != common.ChangeSame {
s.log.Infof("connectivity(upd) WireguardPublicKey Changed (%s) %s->%s", old.Name, old.WireguardPublicKey, new.WireguardPublicKey)
s.updateAllIPConnectivity()
}
case common.PeerNodeStateChanged:
old, _ := evt.Old.(*common.LocalNodeSpec)
new, _ := evt.New.(*common.LocalNodeSpec)
old, ok := evt.Old.(*common.LocalNodeSpec)
if !ok {
s.log.Errorf("evt.Old is not a *common.LocalNodeSpec %v", evt.Old)
}
new, ok := evt.New.(*common.LocalNodeSpec)
if !ok {
s.log.Errorf("evt.New is not a *common.LocalNodeSpec %v", evt.New)
}
if old != nil {
if old.IPv4Address != nil {
delete(s.nodeByAddr, old.IPv4Address.IP.String())
Expand All @@ -199,8 +223,14 @@ func (s *ConnectivityServer) ServeConnectivity(t *tomb.Tomb) error {
}
}
case common.FelixConfChanged:
old, _ := evt.Old.(*felixConfig.Config)
new, _ := evt.New.(*felixConfig.Config)
old, ok := evt.Old.(*felixConfig.Config)
if !ok {
s.log.Errorf("evt.Old is not a *felixConfig.Config %v", evt.Old)
}
new, ok := evt.New.(*felixConfig.Config)
if !ok {
s.log.Errorf("evt.Old is not a *felixConfig.Config %v", evt.New)
}
if new == nil || old == nil {
/* First/last update, do nothing more */
continue
Expand All @@ -217,13 +247,19 @@ func (s *ConnectivityServer) ServeConnectivity(t *tomb.Tomb) error {
s.log.Infof("connectivity(upd) ipamConf Changed")
s.updateAllIPConnectivity()
case common.SRv6PolicyAdded:
new := evt.New.(*common.NodeConnectivity)
new, ok := evt.New.(*common.NodeConnectivity)
if !ok {
s.log.Errorf("evt.New is not a *common.NodeConnectivity %v", evt.New)
}
err := s.UpdateSRv6Policy(new, false /* isWithdraw */)
if err != nil {
s.log.Errorf("Error while adding SRv6 Policy %s", err)
}
case common.SRv6PolicyDeleted:
old := evt.Old.(*common.NodeConnectivity)
old, ok := evt.Old.(*common.NodeConnectivity)
if !ok {
s.log.Errorf("evt.Old is not a *common.NodeConnectivity %v", evt.Old)
}
err := s.UpdateSRv6Policy(old, true /* isWithdraw */)
if err != nil {
s.log.Errorf("Error while deleting SRv6 Policy %s", err)
Expand Down
5 changes: 4 additions & 1 deletion calico-vpp-agent/connectivity/srv6.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,10 @@ func (p *SRv6Provider) AddConnectivity(cn *common.NodeConnectivity) (err error)
} else if p.isSRv6TunnelInfoFromBGP(cn) && cn.Custom != nil { // getting SRv6 tunnel data from BGP

// storing info in nodePolices
policyData := cn.Custom.(*common.SRv6Tunnel)
policyData, ok := cn.Custom.(*common.SRv6Tunnel)
if !ok {
return fmt.Errorf("cn.Custom is not a (*common.SRv6Tunnel) %v", cn.Custom)
}
nodeip = policyData.Dst.String()
if p.nodePolices[policyData.Dst.String()] == nil {
p.nodePolices[policyData.Dst.String()] = &NodeToPolicies{
Expand Down
30 changes: 24 additions & 6 deletions calico-vpp-agent/policy/policy_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -336,13 +336,22 @@ func (s *Server) handlePolicyServerEvents(evt common.CalicoVppEvent) error {
/* Note: we will only receive events we ask for when registering the chan */
switch evt.Type {
case common.NetAddedOrUpdated:
netDef := evt.New.(*watchers.NetworkDefinition)
netDef, ok := evt.New.(*watchers.NetworkDefinition)
if !ok {
return fmt.Errorf("evt.New is not a (*watchers.NetworkDefinition) %v", evt.New)
}
s.networkDefinitions[netDef.Name] = netDef
case common.NetDeleted:
netDef := evt.Old.(*watchers.NetworkDefinition)
netDef, ok := evt.Old.(*watchers.NetworkDefinition)
if !ok {
return fmt.Errorf("evt.Old is not a (*watchers.NetworkDefinition) %v", evt.Old)
}
delete(s.networkDefinitions, netDef.Name)
case common.PodAdded:
podSpec := evt.New.(*storage.LocalPodSpec)
podSpec, ok := evt.New.(*storage.LocalPodSpec)
if !ok {
return fmt.Errorf("evt.New is not a (*storage.LocalPodSpec) %v", evt.New)
}
swIfIndex := podSpec.TunTapSwIfIndex
if swIfIndex == vpplink.InvalidID {
swIfIndex = podSpec.MemifSwIfIndex
Expand All @@ -354,7 +363,10 @@ func (s *Server) handlePolicyServerEvents(evt common.CalicoVppEvent) error {
Network: podSpec.NetworkName,
}, swIfIndex, podSpec.InterfaceName, podSpec.GetContainerIps())
case common.PodDeleted:
podSpec := evt.Old.(*storage.LocalPodSpec)
podSpec, ok := evt.Old.(*storage.LocalPodSpec)
if !ok {
return fmt.Errorf("evt.Old is not a (*storage.LocalPodSpec) %v", evt.Old)
}
if podSpec != nil {
s.WorkloadRemoved(&WorkloadEndpointID{
OrchestratorID: podSpec.OrchestratorID,
Expand All @@ -364,7 +376,10 @@ func (s *Server) handlePolicyServerEvents(evt common.CalicoVppEvent) error {
}, podSpec.GetContainerIps())
}
case common.TunnelAdded:
swIfIndex := evt.New.(uint32)
swIfIndex, ok := evt.New.(uint32)
if !ok {
return fmt.Errorf("evt.New not a uint32 %v", evt.New)
}

s.tunnelSwIfIndexesLock.Lock()
s.tunnelSwIfIndexes[swIfIndex] = true
Expand All @@ -388,7 +403,10 @@ func (s *Server) handlePolicyServerEvents(evt common.CalicoVppEvent) error {
case common.TunnelDeleted:
var pending bool

swIfIndex := evt.Old.(uint32)
swIfIndex, ok := evt.Old.(uint32)
if !ok {
return fmt.Errorf("evt.Old not a uint32 %v", evt.Old)
}

s.tunnelSwIfIndexesLock.Lock()
delete(s.tunnelSwIfIndexes, swIfIndex)
Expand Down
23 changes: 19 additions & 4 deletions calico-vpp-agent/prometheus/prometheus.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package prometheus

import (
"context"
"fmt"
"net/http"
"strconv"
"strings"
Expand Down Expand Up @@ -145,7 +146,10 @@ func (s *Server) exportMetricsForStat(names []string, sta adapter.StatEntry, ifN
}
s.lock.Lock()
if sta.Type == adapter.SimpleCounterVector {
values := sta.Data.(adapter.SimpleCounterStat)
values, ok := sta.Data.(adapter.SimpleCounterStat)
if !ok {
return fmt.Errorf("sta.Data is not a (adapter.SimpleCounterStat), %v", sta.Data)
}
for worker := range values {
for ifIdx := range values[worker] {
if string(ifNames[ifIdx]) != "" {
Expand All @@ -157,7 +161,10 @@ func (s *Server) exportMetricsForStat(names []string, sta adapter.StatEntry, ifN
}
} else if sta.Type == adapter.CombinedCounterVector {
metric.MetricDescriptor.Unit = units[k]
values := sta.Data.(adapter.CombinedCounterStat)
values, ok := sta.Data.(adapter.CombinedCounterStat)
if !ok {
return fmt.Errorf("sta.Data is not a (adapter.CombinedCounterStat), %v", sta.Data)
}
for worker := range values {
for ifIdx := range values[worker] {
if string(ifNames[ifIdx]) != "" {
Expand Down Expand Up @@ -220,7 +227,11 @@ func (s *Server) ServePrometheus(t *tomb.Tomb) error {
evt := <-s.channel
switch evt.Type {
case common.PodAdded:
podSpec := evt.New.(*storage.LocalPodSpec)
podSpec, ok := evt.New.(*storage.LocalPodSpec)
if !ok {
s.log.Errorf("evt.New is not a *storage.LocalPodSpec %v", evt.New)
continue
}
s.lock.Lock()
if podSpec.TunTapSwIfIndex == vpplink.INVALID_SW_IF_INDEX {
s.podInterfacesBySwifIndex[podSpec.MemifSwIfIndex] = *podSpec
Expand All @@ -231,7 +242,11 @@ func (s *Server) ServePrometheus(t *tomb.Tomb) error {
s.lock.Unlock()
case common.PodDeleted:
s.lock.Lock()
podSpec := evt.Old.(*storage.LocalPodSpec)
podSpec, ok := evt.Old.(*storage.LocalPodSpec)
if !ok {
s.log.Errorf("evt.Old is not a *storage.LocalPodSpec %v", evt.Old)
continue
}
initialPod := s.podInterfacesByKey[podSpec.Key()]
delete(s.podInterfacesByKey, initialPod.Key())
if podSpec.TunTapSwIfIndex == vpplink.INVALID_SW_IF_INDEX {
Expand Down
Loading
Loading