Skip to content

Commit

Permalink
feat: move actual logic into the agent package
Browse files Browse the repository at this point in the history
This change makes `github.com/siderolabs/siderolink/cmd/siderolink-agent` importable as `github.com/siderolabs/siderolink/pkg/agent`.

It also contains the ability to "pre-bind" specific UUIDs to the specific IPv6s.

Signed-off-by: Dmitriy Matrenichev <dmitry.matrenichev@siderolabs.com>
  • Loading branch information
DmitriyMV committed Mar 21, 2024
1 parent 8866351 commit 9300968
Show file tree
Hide file tree
Showing 14 changed files with 390 additions and 178 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# THIS FILE WAS AUTOMATICALLY GENERATED, PLEASE DO NOT EDIT.
#
# Generated on 2024-02-29T11:57:03Z by kres latest.
# Generated on 2024-03-20T20:16:10Z by kres latest.

name: default
concurrency:
Expand Down Expand Up @@ -31,7 +31,7 @@ jobs:
if: (!startsWith(github.head_ref, 'renovate/') && !startsWith(github.head_ref, 'dependabot/'))
services:
buildkitd:
image: moby/buildkit:v0.12.5
image: moby/buildkit:v0.13.1
options: --privileged
ports:
- 1234:1234
Expand All @@ -48,8 +48,8 @@ jobs:
uses: docker/setup-buildx-action@v3
with:
driver: remote
endpoint: tcp://localhost:1234
timeout-minutes: 1
endpoint: tcp://127.0.0.1:1234
timeout-minutes: 10
- name: base
run: |
make base
Expand Down
78 changes: 30 additions & 48 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
# THIS FILE WAS AUTOMATICALLY GENERATED, PLEASE DO NOT EDIT.
#
# Generated on 2024-02-29T11:57:03Z by kres latest.
# Generated on 2024-03-20T20:16:10Z by kres latest.

# options for analysis running
run:
timeout: 10m
issues-exit-code: 1
tests: true
build-tags: []
skip-dirs: []
skip-dirs-use-default: true
skip-files: []
build-tags: [ ]
modules-download-mode: readonly

# output configuration options
output:
format: colored-line-number
formats:
- format: colored-line-number
path: stdout
print-issued-lines: true
print-linter-name: true
uniq-by-line: true
Expand All @@ -32,54 +31,38 @@ linters-settings:
check-blank: true
exhaustive:
default-signifies-exhaustive: false
funlen:
lines: 60
statements: 40
gci:
local-prefixes: github.com/siderolabs/siderolink/
sections:
- standard # Standard section: captures all standard packages.
- default # Default section: contains all imports that could not be matched to another section type.
- prefix(github.com/siderolabs/siderolink/) # Custom section: groups all imports with the specified Prefix.
gocognit:
min-complexity: 30
ireturn:
allow:
- anon
- error
- empty
- stdlib
- github.com\/talos-systems\/kres\/internal\/dag.Node
nestif:
min-complexity: 5
goconst:
min-len: 3
min-occurrences: 3
gocritic:
disabled-checks: []
disabled-checks: [ ]
gocyclo:
min-complexity: 20
godot:
check-all: false
godox:
keywords: # default keywords are TODO, BUG, and FIXME, these can be overwritten by this setting
- NOTE
- OPTIMIZE # marks code that should be optimized before merging
- HACK # marks hack-arounds that should be removed before merging
scope: declarations
gofmt:
simplify: true
goimports:
local-prefixes: github.com/siderolabs/siderolink/
golint:
min-confidence: 0.8
gomnd:
settings: {}
gomodguard: {}
gomodguard: { }
gomnd: { }
govet:
check-shadowing: true
enable-all: true
lll:
line-length: 200
tab-width: 4
misspell:
locale: US
ignore-words: []
ignore-words: [ ]
nakedret:
max-func-lines: 30
prealloc:
Expand All @@ -88,16 +71,15 @@ linters-settings:
for-loops: false # Report preallocation suggestions on for loops, false by default
nolintlint:
allow-unused: false
allow-leading-space: false
allow-no-explanation: []
allow-no-explanation: [ ]
require-explanation: false
require-specific: true
rowserrcheck: {}
testpackage: {}
rowserrcheck: { }
testpackage: { }
unparam:
check-exported: false
unused:
check-exported: false
local-variables-are-used: false
whitespace:
multi-if: false # Enforces newlines (or comments) after every multi-line if statement
multi-func: false # Enforces newlines (or comments) after every multi-line function signature
Expand All @@ -113,8 +95,8 @@ linters-settings:
gofumpt:
extra-rules: false
cyclop:
# the maximal code complexity to report
max-complexity: 20
# the maximal code complexity to report
max-complexity: 20
# depguard:
# Main:
# deny:
Expand All @@ -125,48 +107,48 @@ linters:
disable-all: false
fast: false
disable:
- exhaustruct
- exhaustivestruct
- exhaustruct
- forbidigo
- funlen
- gas
- gochecknoglobals
- gochecknoinits
- godox
- goerr113
- gomnd
- gomoddirectives
- gosec
- inamedparam
- ireturn
- nestif
- nonamedreturns
- nosnakecase
- paralleltest
- tagalign
- tagliatelle
- thelper
- typecheck
- varnamelen
- wrapcheck
- depguard # Disabled because starting with golangci-lint 1.53.0 it doesn't allow denylist alone anymore
- tagalign
- inamedparam
- testifylint # complains about our assert recorder and has a number of false positives for assert.Greater(t, thing, 1)
- protogetter # complains about us using Value field on typed spec, instead of GetValue which has a different signature
- perfsprint # complains about us using fmt.Sprintf in non-performance critical code, updating just kres took too long
# abandoned linters for which golangci shows the warning that the repo is archived by the owner
- deadcode
- golint
- ifshort
- interfacer
- maligned
- golint
- scopelint
- varcheck
- deadcode
- structcheck
- ifshort
- varcheck
# disabled as it seems to be broken - goes into imported libraries and reports issues there
- musttag

issues:
exclude: []
exclude-rules: []
exclude: [ ]
exclude-rules: [ ]
exclude-use-default: false
exclude-case-sensitive: false
max-issues-per-linter: 10
Expand Down
5 changes: 3 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

# THIS FILE WAS AUTOMATICALLY GENERATED, PLEASE DO NOT EDIT.
#
# Generated on 2024-03-10T14:36:55Z by kres latest.
# Generated on 2024-03-20T20:16:10Z by kres latest.

ARG TOOLCHAIN

# runs markdownlint
FROM docker.io/node:21.6.2-alpine3.19 AS lint-markdown
FROM docker.io/node:21.7.1-alpine3.19 AS lint-markdown
WORKDIR /src
RUN npm i -g markdownlint-cli@0.39.0
RUN npm i sentences-per-line@0.2.1
Expand Down Expand Up @@ -99,6 +99,7 @@ FROM base AS lint-golangci-lint
WORKDIR /src
COPY .golangci.yml .
ENV GOGC 50
RUN golangci-lint config verify --config .golangci.yml
RUN --mount=type=cache,target=/root/.cache/go-build --mount=type=cache,target=/root/.cache/golangci-lint --mount=type=cache,target=/go/pkg golangci-lint run --config .golangci.yml

# runs govulncheck
Expand Down
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# THIS FILE WAS AUTOMATICALLY GENERATED, PLEASE DO NOT EDIT.
#
# Generated on 2024-03-07T11:10:45Z by kres latest.
# Generated on 2024-03-20T20:16:10Z by kres latest.

# common variables

SHA := $(shell git describe --match=none --always --abbrev=8 --dirty)
TAG := $(shell git describe --tag --always --dirty)
TAG := $(shell git describe --tag --always --dirty --match v[0-9]\*)
ABBREV_TAG := $(shell git describe --tags >/dev/null 2>/dev/null && git describe --tag --always --match v[0-9]\* --abbrev=0 || echo 'undefined')
BRANCH := $(shell git rev-parse --abbrev-ref HEAD)
ARTIFACTS := _out
Expand All @@ -19,7 +19,7 @@ GRPC_GO_VERSION ?= 1.3.0
GRPC_GATEWAY_VERSION ?= 2.19.1
VTPROTOBUF_VERSION ?= 0.6.0
DEEPCOPY_VERSION ?= v0.5.6
GOLANGCILINT_VERSION ?= v1.56.2
GOLANGCILINT_VERSION ?= v1.57.0
GOFUMPT_VERSION ?= v0.6.0
GO_VERSION ?= 1.22.1
GOIMPORTS_VERSION ?= v0.19.0
Expand Down
64 changes: 34 additions & 30 deletions cmd/siderolink-agent/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,61 +2,65 @@
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.

// Package main provides the entrypoint for the SideroLink agent.
package main

import (
"context"
"errors"
"flag"
"fmt"
"os"
"os/signal"
"strings"

"go.uber.org/zap"
"golang.org/x/sync/errgroup"
"google.golang.org/grpc"

"github.com/siderolabs/siderolink/pkg/agent"
)

func main() {
flag.StringVar(&sideroLinkFlags.wireguardEndpoint, "sidero-link-wireguard-endpoint", "172.20.0.1:51821", "advertised Wireguard endpoint")
flag.StringVar(&sideroLinkFlags.apiEndpoint, "sidero-link-api-endpoint", ":4000", "gRPC API endpoint for the SideroLink")
flag.StringVar(&sideroLinkFlags.joinToken, "sidero-link-join-token", "", "join token")
flag.BoolVar(&sideroLinkFlags.forceUserspace, "sidero-link-force-userspace", false, "force usage of userspace UDP device for Wireguard")
flag.StringVar(&eventSinkFlags.apiEndpoint, "event-sink-endpoint", ":8080", "gRPC API endpoint for the Event Sink")
flag.StringVar(&logReceiverFlags.endpoint, "log-receiver-endpoint", ":4001", "TCP log receiver endpoint")
flag.Parse()

ctx, cancel := signal.NotifyContext(context.Background(), os.Interrupt)
defer cancel()
if err := run(); err != nil {
println("error :", err.Error())

if err := run(ctx); err != nil {
fmt.Fprintln(os.Stderr, "error: ", err)
os.Exit(1)
}
}

func run(ctx context.Context) error {
func run() error {
var cfg agent.Config

var predefinedPairs predefinedPairsFlag

flag.StringVar(&cfg.WireguardEndpoint, "sidero-link-wireguard-endpoint", "172.20.0.1:51821", "advertised Wireguard endpoint")
flag.StringVar(&cfg.APIEndpoint, "sidero-link-api-endpoint", ":4000", "gRPC API endpoint for the SideroLink")
flag.StringVar(&cfg.JoinToken, "sidero-link-join-token", "", "join token")
flag.BoolVar(&cfg.ForceUserspace, "sidero-link-force-userspace", false, "force usage of userspace UDP device for Wireguard")
flag.StringVar(&cfg.SinkEndpoint, "event-sink-endpoint", ":8080", "gRPC API endpoint for the Event Sink")
flag.StringVar(&cfg.LogEndpoint, "log-receiver-endpoint", ":4001", "TCP log receiver endpoint")
flag.Var(&predefinedPairs, "predefined-pairs", "predefined pairs of UUID=IPv6 addrs for the nodes")
flag.Parse()

cfg.UUIDIPv6Pairs = predefinedPairs

logger, err := zap.NewDevelopment()
if err != nil {
return fmt.Errorf("error creating logger")
return fmt.Errorf("error creating logger: %w", err)
}

eg, ctx := errgroup.WithContext(ctx)
ctx, cancel := signal.NotifyContext(context.Background(), os.Interrupt)
defer cancel()

if err := sideroLink(ctx, eg, logger); err != nil {
return fmt.Errorf("SideroLink: %w", err)
}
return agent.Run(ctx, cfg, nil, logger)
}

if err := eventSink(ctx, eg); err != nil {
return fmt.Errorf("event sink: %w", err)
}
type predefinedPairsFlag []string

if err := logReceiver(ctx, eg, logger); err != nil {
return fmt.Errorf("log receiver: %w", err)
}
func (p *predefinedPairsFlag) String() string {
return strings.Join(*p, " ")
}

if err := eg.Wait(); err != nil && !errors.Is(err, grpc.ErrServerStopped) {
return err
}
func (p *predefinedPairsFlag) Set(s string) error {
*p = append(*p, s)

return nil
}
Loading

0 comments on commit 9300968

Please sign in to comment.