Skip to content

Commit

Permalink
update ci (#36)
Browse files Browse the repository at this point in the history
Summary: Pull Request resolved: #36

Reviewed By: pzmarzly

Differential Revision: D39419264

Pulled By: pmazzini

fbshipit-source-id: 41eafb3aab5a85ee2440913ddce40c49f0bd91fe
  • Loading branch information
pmazzini authored and facebook-github-bot committed Sep 12, 2022
1 parent 838dcff commit 8f8a23d
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 41 deletions.
15 changes: 8 additions & 7 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,20 @@ name: Run tests

on:
push:
# To all branches
pull_request:

jobs:
test:
runs-on: ubuntu-20.04
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-go@v2
- uses: actions/checkout@v3
- uses: actions/setup-go@v3
with:
stable: 'false'
go-version: '1.15.4'
go-version: 1.18
- name: Convert to modules # To avoid the "outside of GOPATH" nonsense
run: go mod init github.com/facebookincubator/dhcplb
run: |
go mod init github.com/facebookincubator/dhcplb
go mod tidy
- name: Fetch Dependencies
run: go get -v ./...
- name: Run Tests
Expand Down
19 changes: 10 additions & 9 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,23 @@ name: Lint

on:
push:
pull_request:

jobs:
lint:
name: Lint Test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-go@v2
- uses: actions/checkout@v3
- uses: actions/setup-go@v3
with:
stable: 'false'
go-version: '1.15.4'
go-version: 1.18
- name: Convert to modules
run: go mod init github.com/facebookincubator/dhcplb
run: |
go mod init github.com/facebookincubator/dhcplb
go mod tidy
- name: Run golangci-lint
uses: golangci/golangci-lint-action@v2
uses: golangci/golangci-lint-action@v3
with:
version: latest
skip-go-installation: true
args: --timeout 300s
# TODO: fix lint
args: -D errcheck -D staticcheck
2 changes: 1 addition & 1 deletion glog_logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func (l glogLogger) Log(msg dhcplb.LogMessage) error {
// Order samples by key, store them into logline slice
keys := make([]string, len(sample))
i := 0
for key, _ := range sample {
for key := range sample {
keys[i] = key
i++
}
Expand Down
10 changes: 7 additions & 3 deletions lib/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ func LoadConfig(path, overridesPath string, version int, provider ConfigProvider
overridesFile := []byte{}
// path length of 0 means we aren't using overrides
if len(overridesPath) != 0 {
err = nil
if overridesFile, err = ioutil.ReadFile(overridesPath); err != nil {
return nil, err
}
Expand Down Expand Up @@ -141,19 +140,24 @@ func WatchConfig(
if err == nil {
// configPath is a symlink, also watch the pointee
err = watcher.Add(realConfigPath)
if err != nil {
return nil, err
}
}

// setup watcher on overrides file if present
if len(overridesPath) > 0 {
err = watcher.Add(filepath.Dir(overridesPath))
if err != nil {
glog.Errorf("Failed to start fsnotify on overrides config file: %s", err)
return nil, err
}
realOverridesPath, err = filepath.EvalSymlinks(overridesPath)
if err == nil {
// overridesPath is a symlink, also watch the pointee
err = watcher.Add(realOverridesPath)
if err != nil {
return nil, err
}
}
}

Expand Down Expand Up @@ -216,7 +220,7 @@ func (c *configSpec) sourcer(provider ConfigProvider) (DHCPServerSourcer, error)
sourcerType := sourcerInfo[0]
stable := sourcerInfo[1]
rc := ""
if strings.Index(sourcerInfo[1], ",") > -1 {
if strings.Contains(sourcerInfo[1], ",") {
sourcerArgs := strings.Split(sourcerInfo[1], ",")
stable = sourcerArgs[0]
rc = sourcerArgs[1]
Expand Down
5 changes: 1 addition & 4 deletions lib/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,6 @@ func (s *Server) handleV4Server(start time.Time, packet *dhcpv4.DHCPv4, peer *ne
if err != nil {
glog.Errorf("Failed to log reply: %s", err)
}
return
}

func (s *Server) handleRawPacketV6(buffer []byte, peer *net.UDPAddr) {
Expand Down Expand Up @@ -294,7 +293,7 @@ func (s *Server) handleRawPacketV6(buffer []byte, peer *net.UDPAddr) {
return
}

relayMsg, err := dhcpv6.EncapsulateRelay(packet, dhcpv6.MessageTypeRelayForward, net.IPv6zero, peer.IP)
relayMsg, _ := dhcpv6.EncapsulateRelay(packet, dhcpv6.MessageTypeRelayForward, net.IPv6zero, peer.IP)
s.sendToServer(start, server, relayMsg.ToBytes(), peer)
}

Expand Down Expand Up @@ -326,7 +325,6 @@ func (s *Server) handleV6RelayRepl(start time.Time, packet dhcpv6.DHCPv6, peer *
glog.Errorf("Failed to log request: %s", err)
}
conn.Close()
return
}

func (s *Server) handleV6Server(start time.Time, packet dhcpv6.DHCPv6, peer *net.UDPAddr) {
Expand All @@ -349,5 +347,4 @@ func (s *Server) handleV6Server(start time.Time, packet dhcpv6.DHCPv6, peer *net
if err != nil {
glog.Errorf("Failed to log reply: %s", err)
}
return
}
7 changes: 0 additions & 7 deletions lib/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
package dhcplb

import (
"fmt"
"net"

"github.com/insomniacslk/dhcp/dhcpv4"
Expand All @@ -24,12 +23,6 @@ type DHCPMessage struct {
Serial string
}

type id string

func (m *DHCPMessage) id() id {
return id(fmt.Sprintf("%s%x%x", m.Peer.IP, m.XID, m.ClientID))
}

// DHCPBalancingAlgorithm defines an interface for load balancing algorithms.
// Users can implement their own and add them to config.go (in the
// configSpec.algorithm method)
Expand Down
13 changes: 3 additions & 10 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ func main() {

if *configPath == "" {
glog.Fatal("Config file is necessary")
return
}

if *pprofPort != 0 {
Expand All @@ -53,31 +52,25 @@ func main() {
*configPath, *overridesPath, *version, provider)
if err != nil {
glog.Fatalf("Failed to load config: %s", err)
return
}

// start watching config
configChan, err := dhcplb.WatchConfig(
*configPath, *overridesPath, *version, provider)
if err != nil {
glog.Fatalf("Failed to watch config: %s", err)
return
}

server, err := dhcplb.NewServer(config, *serverMode, logger)
if err != nil {
glog.Fatal(err)
return
}

// update server config whenever file changes
go func() {
for {
select {
case config := <-configChan:
glog.Info("Config changed")
server.SetConfig(config)
}
for config := range configChan {
glog.Info("Config changed")
server.SetConfig(config)
}
}()

Expand Down

0 comments on commit 8f8a23d

Please sign in to comment.