Skip to content

Commit

Permalink
Merge branch 'main' into heartbeats_br
Browse files Browse the repository at this point in the history
  • Loading branch information
elevran authored Oct 9, 2023
2 parents ed27593 + 08b04db commit 459d3f2
Show file tree
Hide file tree
Showing 8 changed files with 137 additions and 26 deletions.
119 changes: 115 additions & 4 deletions .golangci.yaml
Original file line number Diff line number Diff line change
@@ -1,29 +1,140 @@
# Based on recommendations in https://olegk.dev/go-linters-configuration-the-right-version

run:
# linter execution
timeout: 30m
issues-exit-code: 1
concurrency: 4
# check tests as well
tests: true
# fail if go.mod file is outdated.
modules-download-mode: readonly
# use the Go version from the go.mod file.
go: ""

linters:
disable-all: false
# set to true to run only fast linters (e.g., for pre-commit)
fast: false

disable-all: true
enable:
- asasalint
- asciicheck
- bidichk
- bodyclose
- errcheck
- contextcheck
- durationcheck
- errcheck
- errname
# - errorlint
- exportloopref
- gosec
- gosimple
- ginkgolinter
- gocritic
# - godot
- gofmt
# - gofumpt
- goimports
- gomoddirectives
- gosec
- gosimple
- govet
- grouper
# - lll
- loggercheck
- importas
- ineffassign
- makezero
- misspell
- nakedret
# - nestif
- nilerr
# - nilnil
# - noctx
# - nolintlint
- nonamedreturns
- nosprintfhostport
- prealloc
- predeclared
- promlinter
- reassign
- revive
- staticcheck
- stylecheck
# - tagliatelle
- tenv
- testableexamples
# - thelper
# - testpackage
- tparallel
- unconvert
- unparam
- unused
- usestdlibvars
# - varnamelen

linters-settings:
gocritic:
enabled-tags:
- diagnostic
# - experimental
# - opinionated
- performance
# - style
disabled-checks:
# consider enabling in performance oriented code
- hugeParam
- rangeExprCopy
- rangeValCopy

errcheck:
# change some error checks which are disabled by default
# check-type-assertions: true
# check-blank: true
# exclude-functions:
# - io/ioutil.ReadFile
# - io.Copy(*bytes.Buffer)
# - io.Copy(os.Stdout)

govet:
disable:
- fieldalignment

nakedret:
# No naked returns (default: 30)
max-func-lines: 1

staticcheck:
checks:
- "all"

stylecheck:

tagliatelle:
case:
rules:
json: snake
yaml: snake
xml: camel
bson: camel
avro: snake
mapstructure: kebab

output:
# prefer the simplest output: `line-number` without saving to file
format: line-number
print-issued-lines: false
print-linter-name: true
# allow multiple reports per line
uniq-by-line: false
# easier to follow the results with a deterministic output
sort-results: true

issues:
# setting 0 to have all the results.
max-issues-per-linter: 0
# nothing should be skipped to not miss errors.
max-same-issues: 0
# analyze only new code (manually set to false to check existing code)
new: true
# do not automatically fix (until AI assisted code improves)
fix: false
12 changes: 6 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ IMG ?= $(IMAGE_TAG_BASE):$(SW_VERSION)
# Target: clean
#-----------------------------------------------------------------------------
.PHONY: clean
clean: ; $(info $(M) cleaning...) @
clean: ; $(info cleaning previous builds...) @
@rm -rf ./bin

#------------------------------------------------------
Expand All @@ -32,16 +32,16 @@ format: fmt
fmt: format-go tidy-go vet-go
vet: vet-go

lint: ; $(info $(M) running linters...)
@golangci-lint run
lint: ; $(info running linters...)
@golangci-lint run --config=./.golangci.yaml ./...

tidy-go: ; $(info $(M) tidying up go.mod...)
tidy-go: ; $(info tidying up go.mod...)
@go mod tidy

format-go: tidy-go vet-go ; $(info $(M) formatting code...)
format-go: tidy-go vet-go ; $(info formatting code...)
@goimports -l -w .

vet-go: ; $(info $(M) vetting code...)
vet-go: ; $(info vetting code...)
@go vet ./...

#------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion pkg/controlplane/store/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ func GetDataplane() string {
func GetDataplaneEndpoint() string {
return s.MyInfo.DataplaneEndpoint
}
func GetChiRouter() (r *chi.Mux) {
func GetChiRouter() *chi.Mux {
return ChiRouter
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/k8s/kubernetes/kubeinformer.go
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ func (k *kubeData) initInformers(client kubernetes.Interface) error {
return err
}

log.Infof("Starting kubernetes informers, waiting for syncronization")
log.Infof("Starting kubernetes informers, waiting for synchronization")
informerFactory.Start(k.stopChan)
informerFactory.WaitForCacheSync(k.stopChan)
k.serviceMap = make(map[string]string)
Expand Down
1 change: 0 additions & 1 deletion pkg/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ func (m *Metrics) aggregateMetrics(connectionStatus event.ConnectionStatusAttr)
flow.OutgoingBytes += connectionStatus.OutgoingBytes
flow.LastTstamp = connectionStatus.LastTstamp
flow.State = connectionStatus.State
// m.ConnectionFlow[connectionStatus.ConnectionID] = flow
} else {
m.ConnectionFlow[connectionStatus.ConnectionID] = &connectionStatus
}
Expand Down
1 change: 0 additions & 1 deletion pkg/policyengine/accessControl.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,6 @@ func (acl *AccessControl) RulesLookup(serviceSrc string, serviceDst string, mbgD
resultAction = myRule.Action
bitrate = myRule.Bitrate
}
// plog.Infof("Rules Matched.. action=%d", myRule.Action)
}
return priority, resultAction, bitrate
}
Expand Down
4 changes: 3 additions & 1 deletion pkg/util/jsonapi/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ import (
"crypto/tls"
"fmt"
"io"
"net"
"net/http"
"strconv"
"time"

"github.com/sirupsen/logrus"
Expand Down Expand Up @@ -92,7 +94,7 @@ func (c *Client) do(method, path string, body []byte) (*Response, error) {

// NewClient returns a new HTTP client.
func NewClient(host string, port uint16, tlsConfig *tls.Config) *Client {
serverURL := fmt.Sprintf("https://%s:%d", host, port)
serverURL := "https://" + net.JoinHostPort(host, strconv.Itoa(int(port)))
return &Client{
client: &http.Client{
Transport: &http.Transport{TLSClientConfig: tlsConfig},
Expand Down
22 changes: 11 additions & 11 deletions tests/k8s.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,38 +32,38 @@ function test_k8s {
kubectl wait --for=condition=ready pod/gwctl

# install iperf3 and jq
kubectl exec -it gwctl -- apk add iperf3 jq
kubectl exec -i gwctl -- apk add iperf3 jq

# start iperf3 server
kubectl exec -it gwctl -- iperf3 -s -D -p 1234
kubectl exec -i gwctl -- iperf3 -s -D -p 1234

# expose iperf3 server
kubectl expose pod gwctl --name=foo --port=80 --target-port=1234

# wait for API server to come up
kubectl exec -it gwctl -- timeout 30 sh -c 'until gwctl get peer; do sleep 0.1; done > /dev/null 2>&1'
kubectl exec -i gwctl -- timeout 30 sh -c 'until gwctl get peer; do sleep 0.1; done > /dev/null 2>&1'

# export iperf server
kubectl exec -it gwctl -- gwctl create export --name foo --host foo --port 80
kubectl exec -i gwctl -- gwctl create export --name foo --host foo --port 80

# import
kubectl exec -it gwctl -- gwctl create peer --host cl-dataplane --port 443 --name peer1
kubectl exec -it gwctl -- gwctl create import --name foo --host bla --port 9999
kubectl exec -it gwctl -- gwctl create binding --import foo --peer peer1
kubectl exec -i gwctl -- gwctl create peer --host cl-dataplane --port 443 --name peer1
kubectl exec -i gwctl -- gwctl create import --name foo --host bla --port 9999
kubectl exec -i gwctl -- gwctl create binding --import foo --peer peer1

# get imported service port
PORT=$(kubectl exec -it gwctl -- /bin/bash -c "gwctl get import --name foo | jq '.Status.Listener.Port' | tr -d '\n'")
PORT=$(kubectl exec -i gwctl -- /bin/bash -c "gwctl get import --name foo | jq '.Status.Listener.Port' | tr -d '\n'")

# expose imported service (TODO: remove this when controlplane automatically creates a service)
kubectl expose deployment cl-dataplane --name=bla --port=9999 --target-port=$PORT

# wait for imported service socket to come up
kubectl exec -it gwctl -- timeout 30 sh -c 'until nc -z $0 $1; do sleep 0.1; done' bla 9999
kubectl exec -i gwctl -- timeout 30 sh -c 'until nc -z $0 $1; do sleep 0.1; done' bla 9999
# wait for iperf server to come up
kubectl exec -it gwctl -- timeout 30 sh -c 'until nc -z $0 $1; do sleep 0.1; done' gwctl 1234
kubectl exec -i gwctl -- timeout 30 sh -c 'until nc -z $0 $1; do sleep 0.1; done' gwctl 1234

# run iperf client
kubectl exec -it gwctl -- iperf3 -c bla -p 9999 -t 1
kubectl exec -i gwctl -- iperf3 -c bla -p 9999 -t 1
}

cd $TEST_DIR
Expand Down

0 comments on commit 459d3f2

Please sign in to comment.