Skip to content

Commit

Permalink
Update golang version
Browse files Browse the repository at this point in the history
Signed-off-by: sferna1 <santhosh.fernandes@gmail.com>
  • Loading branch information
sanfern committed Sep 21, 2022
1 parent 7023cc1 commit 91c9fca
Show file tree
Hide file tree
Showing 15 changed files with 70 additions and 114 deletions.
49 changes: 26 additions & 23 deletions .github/workflows/ci-build.yaml
Expand Up @@ -12,7 +12,7 @@ jobs:
build:
runs-on: ubuntu-latest
container:
image: golang:1.17-alpine3.16
image: golang:1.18.6-alpine3.16

steps:
- name: Harden Runner
Expand All @@ -28,29 +28,32 @@ jobs:
- name: Checkout repository
uses: actions/checkout@d0651293c4a5a52e711f25b41b05b2212f385d28

- name: Format
run: |
go install golang.org/x/tools/cmd/goimports@latest
res="$(goimports -l .)"
if [[ "$(printf '%s' "$res")" != '' ]]; then
echo "Unformatted source code:"
echo "$res"
exit 1
fi
- name: Vet
run: |
go vet ./...
- name: Test
run: |
go test ./...
- uses: dominikh/staticcheck-action@4ec9a0dff54be2642bc76581598ba433fd8d4967
with:
version: "2021.1.2"
install-go: false
# - name: Format
# run: |
# go install golang.org/x/tools/cmd/goimports@latest
# res="$(goimports -l -d .)"
# if [[ "$(printf '%s' "$res")" != '' ]]; then
# echo "Unformatted source code:"
# echo "$res"
# exit 1
# fi
#
# - name: Vet
# run: |
# go vet ./...
#
# - name: Test
# run: |
# go test ./...
#
# - uses: dominikh/staticcheck-action@v1.2.0
# with:
# version: "2022.1.1"
# install-go: false

- name: Build
run: |
echo $GOPATH
ls -lrt
make
ls -lrt $GOPATH/bin
9 changes: 7 additions & 2 deletions Makefile
@@ -1,13 +1,18 @@
.PHONY: all

export GOPATH := $(HOME)/go
GOPATH ?= $(HOME)/go
export GOPATH

all: swagger build

swagger:
@mkdir $(GOPATH) || true
@mkdir $(GOPATH)/bin || true
@go get -u github.com/swaggo/swag/cmd/swag
@go get -u github.com/swaggo/http-swagger
@go get -u github.com/alecthomas/template
@find / -name swag
ls -l /usr/local/go/bin
ls -l /go/bin
@$(GOPATH)/bin/swag init -d "./" -g "apis/configwatch.go"

build:
Expand Down
3 changes: 1 addition & 2 deletions apis/configwatch.go
Expand Up @@ -11,7 +11,6 @@ import (
"crypto/tls"
"crypto/x509"
"encoding/pem"
"io/ioutil"
"net"
"net/http"
"os"
Expand Down Expand Up @@ -79,7 +78,7 @@ func StartConfigWatcher(ctx context.Context, hostname, daemonName string, conf *
if conf.MTLSEnabled {
log.Info().Msgf("l3afd server listening with mTLS - %s ", conf.L3afConfigsRestAPIAddr)
// Create a CA certificate pool and add client ca's to it
caCert, err := ioutil.ReadFile(path.Join(conf.MTLSCertDir, conf.MTLSCACertFilename))
caCert, err := os.ReadFile(path.Join(conf.MTLSCertDir, conf.MTLSCACertFilename))
if err != nil {
log.Fatal().Err(err).Msgf("client CA %s file not found", conf.MTLSCACertFilename)
}
Expand Down
4 changes: 2 additions & 2 deletions apis/handlers/addprog.go
Expand Up @@ -7,8 +7,8 @@ import (
"context"
"encoding/json"
"fmt"
"io"

"io/ioutil"
"net/http"

"github.com/rs/zerolog/log"
Expand Down Expand Up @@ -45,7 +45,7 @@ func AddEbpfPrograms(ctx context.Context, kfcfg *kf.NFConfigs) http.HandlerFunc
log.Warn().Msgf("Empty request body")
return
}
bodyBuffer, err := ioutil.ReadAll(r.Body)
bodyBuffer, err := io.ReadAll(r.Body)
if err != nil {
mesg = fmt.Sprintf("failed to read request body: %v", err)
log.Error().Msg(mesg)
Expand Down
4 changes: 2 additions & 2 deletions apis/handlers/deleteprog.go
Expand Up @@ -7,8 +7,8 @@ import (
"context"
"encoding/json"
"fmt"
"io"

"io/ioutil"
"net/http"

"github.com/rs/zerolog/log"
Expand Down Expand Up @@ -45,7 +45,7 @@ func DeleteEbpfPrograms(ctx context.Context, kfcfg *kf.NFConfigs) http.HandlerFu
log.Warn().Msgf("Empty request body")
return
}
bodyBuffer, err := ioutil.ReadAll(r.Body)
bodyBuffer, err := io.ReadAll(r.Body)
if err != nil {
mesg = fmt.Sprintf("failed to read request body: %v", err)
log.Error().Msg(mesg)
Expand Down
4 changes: 2 additions & 2 deletions apis/handlers/updateconfig.go
Expand Up @@ -7,8 +7,8 @@ import (
"context"
"encoding/json"
"fmt"
"io"

"io/ioutil"
"net/http"

"github.com/rs/zerolog/log"
Expand Down Expand Up @@ -45,7 +45,7 @@ func UpdateConfig(ctx context.Context, kfcfg *kf.NFConfigs) http.HandlerFunc {
log.Warn().Msgf("Empty request body")
return
}
bodyBuffer, err := ioutil.ReadAll(r.Body)
bodyBuffer, err := io.ReadAll(r.Body)
if err != nil {
mesg = fmt.Sprintf("failed to read request body: %v", err)
log.Error().Msg(mesg)
Expand Down
2 changes: 1 addition & 1 deletion go.mod
@@ -1,6 +1,6 @@
module github.com/l3af-project/l3afd

go 1.17
go 1.19

require (
github.com/cilium/ebpf v0.9.0
Expand Down
50 changes: 1 addition & 49 deletions go.sum

Large diffs are not rendered by default.

3 changes: 1 addition & 2 deletions kf/bpf.go
Expand Up @@ -14,7 +14,6 @@ import (
"errors"
"fmt"
"io"
"io/ioutil"
"net/http"
"net/url"
"os"
Expand Down Expand Up @@ -707,7 +706,7 @@ func (b *BPF) createUpdateRulesFile(direction string) (string, error) {

fileName := path.Join(b.FilePath, direction, b.Program.RulesFile)

if err := ioutil.WriteFile(fileName, []byte(b.Program.Rules), 0644); err != nil {
if err := os.WriteFile(fileName, []byte(b.Program.Rules), 0644); err != nil {
return "", fmt.Errorf("create or Update Rules File failed with error %v", err)
}

Expand Down
5 changes: 2 additions & 3 deletions kf/bpf_test.go
Expand Up @@ -10,7 +10,6 @@ import (
"compress/gzip"
"context"
"io"
"io/ioutil"
"net/http"
"os"
"os/exec"
Expand Down Expand Up @@ -423,7 +422,7 @@ func TestBPF_GetArtifacts(t *testing.T) {
tarWriter.Write([]byte("random things"))
return &http.Response{
StatusCode: 200,
Body: ioutil.NopCloser(buf),
Body: io.NopCloser(buf),
Header: make(http.Header),
}
}),
Expand Down Expand Up @@ -506,7 +505,7 @@ func TestBPF_GetArtifacts(t *testing.T) {
writer.Close()
return &http.Response{
StatusCode: 200,
Body: ioutil.NopCloser(buf),
Body: io.NopCloser(buf),
Header: make(http.Header),
}
}),
Expand Down
23 changes: 12 additions & 11 deletions kf/bpfmap.go
Expand Up @@ -33,23 +33,24 @@ type MetricsBPFMap struct {
lastValue float64
}

// This function is used to update eBPF maps, which are used by network functions.
// Update function is used to update eBPF maps, which are used by network functions.
// Supported types are Array and Hash
// Multiple values are comma separated
// Hashmap can be multiple values or single values.
// If hash map entries then key will be values and value will be set to 1
// In case of Array then key will be index starting from 0 and values are stored.
// for e.g.
// HashMap scenario 1. --ports="80,443" values are stored in rl_ports_map BPF map
// key => 80 value => 1
// key => 443 value => 1
// HashMap scenario 2. --ports="443" value is stored in rl_ports_map BPF map
// key => 443 value => 1
// Array scenario 1. --ports="80,443" values are stored in rl_ports_map BPF map
// key => 0 value => 80
// key => 1 value => 443
// Array scenario 2. --rate="10000" value is stored in rl_config_map BPF map
// key => 0 value => 10000
//
// HashMap scenario 1. --ports="80,443" values are stored in rl_ports_map BPF map
// key => 80 value => 1
// key => 443 value => 1
// HashMap scenario 2. --ports="443" value is stored in rl_ports_map BPF map
// key => 443 value => 1
// Array scenario 1. --ports="80,443" values are stored in rl_ports_map BPF map
// key => 0 value => 80
// key => 1 value => 443
// Array scenario 2. --rate="10000" value is stored in rl_config_map BPF map
// key => 0 value => 10000
func (b *BPFMap) Update(value string) error {

log.Debug().Msgf("update map name %s ID %d", b.Name, b.MapID)
Expand Down
7 changes: 3 additions & 4 deletions kf/kf_unix.go
Expand Up @@ -11,7 +11,6 @@ import (
"bytes"
"errors"
"fmt"
"io/ioutil"
"os"
"strings"
"syscall"
Expand Down Expand Up @@ -105,7 +104,7 @@ func VerifyNMountBPFFS() error {
fstype := "bpf"
flags := 0

mnts, err := ioutil.ReadFile("/proc/mounts")
mnts, err := os.ReadFile("/proc/mounts")
if err != nil {
return fmt.Errorf("failed to read procfs: %v", err)
}
Expand All @@ -127,7 +126,7 @@ func VerifyNMountTraceFS() error {
fstype := "tracefs"
flags := syscall.MS_NODEV | syscall.MS_NOEXEC | syscall.MS_NOSUID | syscall.MS_RELATIME

mnts, err := ioutil.ReadFile("/proc/self/mounts")
mnts, err := os.ReadFile("/proc/self/mounts")
if err != nil {
return fmt.Errorf("failed to read procfs: %v", err)
}
Expand Down Expand Up @@ -165,7 +164,7 @@ func GetPlatform() (string, error) {
}

func IsProcessRunning(pid int, name string) (bool, error) {
procState, err := ioutil.ReadFile(fmt.Sprintf("/proc/%d/stat", pid))
procState, err := os.ReadFile(fmt.Sprintf("/proc/%d/stat", pid))
if err != nil {
return false, fmt.Errorf("BPF Program not running %s because of error: %v", name, err)
}
Expand Down
4 changes: 2 additions & 2 deletions kf/nfconfig.go
Expand Up @@ -9,8 +9,8 @@ import (
"context"
"encoding/json"
"fmt"
"io/ioutil"
"net"
"os"
"reflect"
"sort"
"strings"
Expand Down Expand Up @@ -739,7 +739,7 @@ func (c *NFConfigs) SaveConfigsToConfigStore() error {
return fmt.Errorf("failed to marshal configs %v", err)
}

if err = ioutil.WriteFile(c.HostConfig.L3afConfigStoreFileName, file, 0644); err != nil {
if err = os.WriteFile(c.HostConfig.L3afConfigStoreFileName, file, 0644); err != nil {
log.Error().Err(err).Msgf("failed write to file operation")
return fmt.Errorf("failed to save configs %v", err)
}
Expand Down
6 changes: 3 additions & 3 deletions main.go
Expand Up @@ -9,7 +9,7 @@ import (
"errors"
"flag"
"fmt"
"io/ioutil"
"io"
"os"
"strconv"
"strings"
Expand Down Expand Up @@ -172,7 +172,7 @@ func checkKernelVersion(conf *config.Config) error {
}

func getKernelVersion() (string, error) {
osVersion, err := ioutil.ReadFile("/proc/version")
osVersion, err := os.ReadFile("/proc/version")
if err != nil {
return "", fmt.Errorf("failed to read procfs: %v", err)
}
Expand Down Expand Up @@ -202,7 +202,7 @@ func ReadConfigsFromConfigStore(conf *config.Config) ([]models.L3afBPFPrograms,
return nil, fmt.Errorf("failed to open persistent file (%s): %v", conf.L3afConfigStoreFileName, err)
}

byteValue, err := ioutil.ReadAll(file)
byteValue, err := io.ReadAll(file)
if err != nil {
return nil, fmt.Errorf("failed to read persistent file (%s): %v", conf.L3afConfigStoreFileName, err)
}
Expand Down
11 changes: 5 additions & 6 deletions pidfile/pidfile.go
Expand Up @@ -5,7 +5,6 @@ package pidfile

import (
"fmt"
"io/ioutil"
"os"
"os/signal"
"strconv"
Expand All @@ -17,7 +16,7 @@ import (

func CheckPIDConflict(pidFilename string) error {
log.Info().Msgf("Checking for another already running instance (using PID file \"%s\")...", pidFilename)
pidFileContent, err := ioutil.ReadFile(pidFilename)
pidFileContent, err := os.ReadFile(pidFilename)
if err != nil {
if os.IsNotExist(err) {
log.Error().Msgf("OK, no PID file already exists at %s.", pidFilename)
Expand Down Expand Up @@ -58,11 +57,11 @@ func CheckPIDConflict(pidFilename string) error {
}

log.Info().Msgf("Process with PID: %s; is running. Comparing process names to ensure it is a true conflict.", oldPIDString)
selfProcName, err := ioutil.ReadFile("/proc/self/comm")
selfProcName, err := os.ReadFile("/proc/self/comm")
if err != nil {
return fmt.Errorf("could not read this processes command name from the proc filesystem; err: %v", err)
}
conflictProcName, err := ioutil.ReadFile(fmt.Sprintf("/proc/%d/comm", oldPID))
conflictProcName, err := os.ReadFile(fmt.Sprintf("/proc/%d/comm", oldPID))
if err != nil {
return fmt.Errorf("could not read old processes (PID: %s) command name from the proc filesystem; error: %v", oldPIDString, err)
}
Expand All @@ -80,14 +79,14 @@ func CheckPIDConflict(pidFilename string) error {
func CreatePID(pidFilename string) error {
PID := os.Getpid()
log.Info().Msgf("Writing process ID %d to %s...", PID, pidFilename)
if err := ioutil.WriteFile(pidFilename, []byte(strconv.Itoa(PID)), 0640); err != nil {
if err := os.WriteFile(pidFilename, []byte(strconv.Itoa(PID)), 0640); err != nil {
return fmt.Errorf("could not write process ID to file: \"%s\"; error: %v", pidFilename, err)
}
return nil
}

func RemovePID(pidFilename string) error {
err := os.Remove(pidFilename)
err := os.RemoveAll(pidFilename)
if err != nil {
err = fmt.Errorf("could not remove PID file: %s; error: %v", pidFilename, err)
}
Expand Down

0 comments on commit 91c9fca

Please sign in to comment.