Skip to content

Commit

Permalink
Rework flasher as a generic agent to handle all bare metal actions
Browse files Browse the repository at this point in the history
This is done to have a single service that interfaces with the hardware
to carry out condition related actions. Instead of having one service
for each kind of hardware interaction, now this service does it all
and can be scaled up/down as a NATS worker.

Going ahead we converge the functionalities of Alloy, Flipflop into
this agent. The ctrl library is also included.
  • Loading branch information
joelrebel committed Oct 28, 2024
1 parent aac6b3d commit 19f5c96
Show file tree
Hide file tree
Showing 89 changed files with 6,544 additions and 509 deletions.
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/default.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ Please don't forget to include the following information in your issue:

- The HW model number, BMC firmware and/or BIOS versions impacted by this issue (if applicable)

- What version of Flasher exhibits this behavior (if applicable)
- What version of Agent exhibits this behavior (if applicable)

- Detailed steps to verify the issue(s)
24 changes: 0 additions & 24 deletions .github/mergify.yml

This file was deleted.

12 changes: 6 additions & 6 deletions .github/workflows/push-pr-lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
uses: golangci/golangci-lint-action@v6
with:
args: --config .golangci.yml --timeout 2m
version: v1.56.2
version: v1.60.1

- name: Test
run: go test ./...
Expand All @@ -40,19 +40,19 @@ jobs:
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Build flasher Docker image - no push
id: dockerbuild-flasher
- name: Build agent Docker image - no push
id: dockerbuild-agent
uses: docker/build-push-action@v6
with:
context: .
push: false
file: Dockerfile

- name: Scan image - flasher
id: scan-flasher-image
- name: Scan image - agent
id: scan-agent-image
uses: anchore/scan-action@v4
with:
image: ghcr.io/metal-automata/flasher:latest
image: ghcr.io/metal-automata/agent:latest
acs-report-enable: true
fail-build: false

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,4 @@ jobs:
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
COSIGN_EXPERIMENTAL: 1
GOVERSION: "1.20"
GOVERSION: "1.22"
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
*.test

# Application binary itself
/flasher
/flasher-osx
/agent
/agent-osx

.DS_Store
*~
Expand Down
50 changes: 7 additions & 43 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,19 +1,14 @@
# golangci.com configuration
# https://github.com/golangci/golangci/wiki/Configuration
service:
golangci-lint-version: v1.56.2 # use the fixed version to not introduce new linters unexpectedly
golangci-lint-version: v1.60.1 # pin version to not introduce new linters unexpectedly

linters-settings:
govet:
auto-fix: true
check-shadowing: true
settings:
printf:
funcs:
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Infof
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Warnf
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Errorf
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Fatalf
enable-all: true
disable:
fieldalignment
revive:
min-confidence: 0
gocyclo:
Expand All @@ -25,10 +20,6 @@ linters-settings:
min-occurrences: 2
depguard:
list-type: blacklist
packages:
# logging is allowed only by logutils.Log, logrus
# is allowed to use only in logutils package
- github.com/sirupsen/logrus
misspell:
locale: US
auto-fix: true
Expand Down Expand Up @@ -65,7 +56,7 @@ linters:
# additional linters
- bodyclose
- gocritic
- goerr113
- err113
- goimports
- revive
- misspell
Expand All @@ -80,18 +71,13 @@ linters:
- nilerr
- reassign
- whitespace
- exportloopref
enable-all: false
disable-all: true

run:
# build-tags:
skip-dirs:
- internal/fixtures
skip-files:
issues:
exclude-files:
- "(.*/)*.*_test.go"

issues:
exclude-rules:
- linters:
- gosec
Expand All @@ -100,26 +86,4 @@ issues:
- linters:
- stylecheck
text: "ST1016"
exclude:
# Default excludes from `golangci-lint run --help` with EXC0002 removed
# EXC0001 errcheck: Almost all programs ignore errors on these functions and in most cases it's ok
- Error return value of .((os\.)?std(out|err)\..*|.*Close|.*Flush|os\.Remove(All)?|.*print(f|ln)?|os\.(Un)?Setenv). is not checked
# EXC0002 golint: Annoying issue about not having a comment. The rare codebase has such comments
# - (comment on exported (method|function|type|const)|should have( a package)? comment|comment should be of the form)
# EXC0003 golint: False positive when tests are defined in package 'test'
- func name will be used as test\.Test.* by other packages, and that stutters; consider calling this
# EXC0004 govet: Common false positives
- (possible misuse of unsafe.Pointer|should have signature)
# EXC0005 staticcheck: Developers tend to write in C-style with an explicit 'break' in a 'switch', so it's ok to ignore
- ineffective break statement. Did you mean to break out of the outer loop
# EXC0006 gosec: Too many false-positives on 'unsafe' usage
- Use of unsafe calls should be audited
# EXC0007 gosec: Too many false-positives for parametrized shell calls
- Subprocess launch(ed with variable|ing should be audited)
# EXC0008 gosec: Duplicated errcheck checks
- (G104|G307)
# EXC0009 gosec: Too many issues in popular repos
- (Expect directory permissions to be 0750 or less|Expect file permissions to be 0600 or less)
# EXC0010 gosec: False positive is triggered by 'src, err := ioutil.ReadFile(filename)'
- Potential file inclusion via variable
exclude-use-default: false
12 changes: 6 additions & 6 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
project_name: flasher
project_name: agent
before:
hooks:
- go mod tidy
Expand All @@ -11,11 +11,11 @@ builds:
- linux
- darwin
ldflags:
- -X "github.com/metal-automata/flasher/internal/version.AppVersion={{ .Version }}"
-X "github.com/metal-automata/flasher/internal/version.GoVersion={{ .Env.GOVERSION }}"
-X "github.com/metal-automata/flasher/internal/version.GitCommit={{ .Commit }}"
-X "github.com/metal-automata/flasher/internal/version.GitBranch={{ .Branch }}"
-X "github.com/metal-automata/flasher/internal/version.BuildDate={{ .Date }}"
- -X "github.com/metal-automata/agent/internal/version.AppVersion={{ .Version }}"
-X "github.com/metal-automata/agent/internal/version.GoVersion={{ .Env.GOVERSION }}"
-X "github.com/metal-automata/agent/internal/version.GitCommit={{ .Commit }}"
-X "github.com/metal-automata/agent/internal/version.GitBranch={{ .Branch }}"
-X "github.com/metal-automata/agent/internal/version.BuildDate={{ .Date }}"

archives:
- id: go
Expand Down
19 changes: 16 additions & 3 deletions .mockery.yaml
Original file line number Diff line number Diff line change
@@ -1,19 +1,32 @@
testonly: False
with-expecter: True
packages:
github.com/metal-automata/flasher/internal/runner:
github.com/metal-automata/agent/internal/firmware/runner:
config:
dir: internal/runner
dir: internal/firmware/runner
fileName: "mock_{{.InterfaceName | firstLower}}.go"
inpackage: true
interfaces:
TaskHandler:
ActionHandler:
github.com/metal-automata/flasher/internal/device:
github.com/metal-automata/agent/internal/device:
config:
dir: internal/device
fileName: "mock_{{.InterfaceName | firstLower}}.go"
inpackage: true
interfaces:
OutofbandQueryor:
InbandQueryor:
github.com/metal-automata/agent/internal/ctrl:
config:
fileName: "mock_{{.InterfaceName | firstLower}}.go"
dir: internal/ctrl
inpackage: True
interfaces:
TaskHandler:
Publisher:
StatusPublisher:
ConditionStatusQueryor:
ConditionStatusPublisher:
eventStatusAcknowleger:
LivenessCheckin:
6 changes: 3 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
FROM alpine:latest

ENTRYPOINT ["/usr/sbin/flasher"]
ENTRYPOINT ["/usr/sbin/agent"]

COPY flasher /usr/sbin/flasher
RUN chmod +x /usr/sbin/flasher
COPY agent /usr/sbin/agent
RUN chmod +x /usr/sbin/agent
1 change: 0 additions & 1 deletion LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,6 @@
same "printed page" as the copyright notice for easier
identification within third-party archives.

Copyright 2022-2024 Metal toolbox Authors
Copyright 2024 metal-automata https://github.com/metal-automata

Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
21 changes: 11 additions & 10 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
export DOCKER_BUILDKIT=1
LDFLAG_LOCATION := github.com/metal-automata/flasher/internal/version
LDFLAG_LOCATION := github.com/metal-automata/agent/internal/version
GIT_COMMIT := $(shell git rev-parse --short HEAD)
GIT_BRANCH := $(shell git symbolic-ref -q --short HEAD)
GIT_SUMMARY := $(shell git describe --tags --dirty --always)
VERSION := $(shell git describe --tags 2> /dev/null)
BUILD_DATE := $(shell date +%s)
GIT_COMMIT_FULL := $(shell git rev-parse HEAD)
GO_VERSION := $(shell expr `go version |cut -d ' ' -f3 |cut -d. -f2` \>= 16)
DOCKER_IMAGE := "ghcr.io/metal-automata/flasher"
REPO := "https://github.com/metal-automata/flasher.git"
DOCKER_IMAGE := "ghcr.io/metal-automata/agent"
REPO := "https://github.com/metal-automata/agent.git"

.DEFAULT_GOAL := help

Expand All @@ -31,7 +31,7 @@ build-osx:
ifeq (${GO_VERSION}, 0)
$(error build requies go version 1.17.n or higher)
endif
CGO_ENABLED=0 go build -o flasher \
CGO_ENABLED=0 go build -o agent \
-ldflags \
"-X ${LDFLAG_LOCATION}.GitCommit=${GIT_COMMIT} \
-X ${LDFLAG_LOCATION}.GitBranch=${GIT_BRANCH} \
Expand All @@ -44,15 +44,15 @@ build-linux:
ifeq (${GO_VERSION}, 0)
$(error build requies go version 1.16.n or higher)
endif
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o flasher \
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o agent \
-ldflags \
"-X ${LDFLAG_LOCATION}.GitCommit=${GIT_COMMIT} \
-X ${LDFLAG_LOCATION}.GitBranch=${GIT_BRANCH} \
-X ${LDFLAG_LOCATION}.GitSummary=${GIT_SUMMARY} \
-X ${LDFLAG_LOCATION}.AppVersion=${VERSION} \
-X ${LDFLAG_LOCATION}.BuildDate=${BUILD_DATE}"

## build docker image and tag as ghcr.io/metal-automata/flasher:latest
## build docker image and tag as ghcr.io/metal-automata/agent:latest
build-image: build-linux
@echo ">>>> NOTE: You may want to execute 'make build-image-nocache' depending on the Docker stages changed"
docker build --rm=true -f Dockerfile -t ${DOCKER_IMAGE}:latest . \
Expand All @@ -62,17 +62,18 @@ build-image: build-linux

## tag and push devel docker image to local registry
push-image-devel: build-image
docker tag ${DOCKER_IMAGE}:latest localhost:5001/flasher:latest
docker push localhost:5001/flasher:latest
kind load docker-image localhost:5001/flasher:latest
docker tag ${DOCKER_IMAGE}:latest localhost:5001/agent:latest
docker push localhost:5001/agent:latest
kind load docker-image localhost:5001/agent:latest

## push docker image
push-image:
docker push ${DOCKER_IMAGE}:latest

## generate doc and flowchart
gen-docs:
CGO_ENABLED=0 go build -o flasher
CGO_ENABLED=0 go build -o agent
./agent gendocs
./docs/generate.sh

# https://gist.github.com/prwhite/8168133
Expand Down
Loading

0 comments on commit 19f5c96

Please sign in to comment.