Skip to content

Commit

Permalink
Add GHA for staticcheck and address issues (#57)
Browse files Browse the repository at this point in the history
Signed-off-by: Arrobo, Gabriel <gabriel.arrobo@intel.com>
  • Loading branch information
gab-arrobo authored Aug 29, 2024
1 parent a2c7e3f commit 8b1c6c4
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 50 deletions.
14 changes: 14 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,20 @@ jobs:
- name: Build
run: go build ./...

staticcheck:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- uses: WillAbides/setup-go-faster@v1.14.0
with:
go-version-file: 'go.mod'

- uses: dominikh/staticcheck-action@v1.3.1
with:
version: latest
install-go: false

lint:
runs-on: ubuntu-latest
steps:
Expand Down
60 changes: 10 additions & 50 deletions proto/client/gClient.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
package client

import (
context "context"
"context"
"math/rand"
"os"
"time"
Expand All @@ -15,6 +15,7 @@ import (
"google.golang.org/grpc"
"google.golang.org/grpc/backoff"
"google.golang.org/grpc/connectivity"
"google.golang.org/grpc/credentials/insecure"
"google.golang.org/grpc/keepalive"
)

Expand All @@ -30,13 +31,13 @@ func init() {
}

type PlmnId struct {
MCC string
MNC string
Mcc string
Mnc string
}

type Nssai struct {
sst string
sd string
Sst string
Sd string
}

type ConfigClient struct {
Expand Down Expand Up @@ -140,12 +141,13 @@ func newClientConnection(host string) (conn *grpc.ClientConn, err error) {
bc := backoff.Config{BaseDelay: bd, Multiplier: mltpr, Jitter: jitter, MaxDelay: MaxDelay}

crt := grpc.ConnectParams{Backoff: bc}
dialOptions := []grpc.DialOption{grpc.WithInsecure(), grpc.WithKeepaliveParams(kacp), grpc.WithDefaultServiceConfig(retryPolicy), grpc.WithConnectParams(crt)}
conn, err = grpc.Dial(host, dialOptions...)
dialOptions := []grpc.DialOption{grpc.WithTransportCredentials(insecure.NewCredentials()), grpc.WithKeepaliveParams(kacp), grpc.WithDefaultServiceConfig(retryPolicy), grpc.WithConnectParams(crt)}
conn, err = grpc.NewClient(host, dialOptions...)
if err != nil {
logger.GrpcLog.Errorln("grpc dial err: ", err)
logger.GrpcLog.Errorln("grpc newclient err: ", err)
return nil, err
}
conn.Connect()
// defer conn.Close()
return conn, err
}
Expand Down Expand Up @@ -215,45 +217,3 @@ func (confClient *ConfigClient) subscribeToConfigPod(commChan chan *protos.Netwo
}
}
}

func readConfigInLoop(confClient *ConfigClient, commChan chan *protos.NetworkSliceResponse) {
myid := os.Getenv("HOSTNAME")
configReadTimeout := time.NewTicker(5000 * time.Millisecond)
for {
select {
case <-configReadTimeout.C:
status := confClient.Conn.GetState()
if status == connectivity.Ready {
rreq := &protos.NetworkSliceRequest{RestartCounter: selfRestartCounter, ClientId: myid, MetadataRequested: confClient.MetadataRequested}
rsp, err := confClient.Client.GetNetworkSlice(context.Background(), rreq)
if err != nil {
logger.GrpcLog.Errorln("read Network Slice config from webconsole failed : ", err)
continue
}
logger.GrpcLog.Debugf("#Network Slices %v, RC of configpod %v ", len(rsp.NetworkSlice), rsp.RestartCounter)
if configPodRestartCounter == 0 || (configPodRestartCounter == rsp.RestartCounter) {
// first time connection or config update
configPodRestartCounter = rsp.RestartCounter
if len(rsp.NetworkSlice) > 0 {
// always carries full config copy
logger.GrpcLog.Infoln("First time config Received ", rsp)
commChan <- rsp
} else if rsp.ConfigUpdated == 1 {
// config delete , all slices deleted
logger.GrpcLog.Infoln("Complete config deleted ")
commChan <- rsp
}
} else if len(rsp.NetworkSlice) > 0 {
logger.GrpcLog.Errorf("Config received after config Pod restart")
// config received after config pod restart
configPodRestartCounter = rsp.RestartCounter
commChan <- rsp
} else {
logger.GrpcLog.Errorf("Config Pod is restarted and no config received")
}
} else {
logger.GrpcLog.Errorln("read Network Slice config from webconsole skipped. GRPC channel down ")
}
}
}
}

0 comments on commit 8b1c6c4

Please sign in to comment.