Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename engine to backend #2950

Merged
merged 4 commits into from
Dec 14, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions agent/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,16 @@ type Runner struct {
filter rpc.Filter
hostname string
counter *State
engine *backend.Engine
backend *backend.Backend
}

func NewRunner(workEngine rpc.Peer, f rpc.Filter, h string, state *State, backend *backend.Engine) Runner {
func NewRunner(workEngine rpc.Peer, f rpc.Filter, h string, state *State, backend *backend.Backend) Runner {
return Runner{
client: workEngine,
filter: f,
hostname: h,
counter: state,
engine: backend,
backend: backend,
}
}

Expand Down Expand Up @@ -144,7 +144,7 @@ func (r *Runner) Run(runnerCtx context.Context) error {
pipeline.WithTaskUUID(fmt.Sprint(work.ID)),
pipeline.WithLogger(r.createLogger(logger, &uploads, work)),
pipeline.WithTracer(r.createTracer(ctxmeta, logger, work)),
pipeline.WithEngine(*r.engine),
pipeline.WithBackend(*r.backend),
pipeline.WithDescription(map[string]string{
"ID": work.ID,
"Repo": repoName,
Expand Down
6 changes: 3 additions & 3 deletions cli/exec/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,12 +215,12 @@ func execWithAxis(c *cli.Context, file, repoPath string, axis matrix.Axis) error
backendCtx := context.WithValue(c.Context, backendTypes.CliContext, c)
backend.Init(backendCtx)

engine, err := backend.FindEngine(backendCtx, c.String("backend-engine"))
backendEngine, err := backend.FindBackend(backendCtx, c.String("backend-engine"))
if err != nil {
return err
}

if _, err = engine.Load(backendCtx); err != nil {
if _, err = backendEngine.Load(backendCtx); err != nil {
return err
}

Expand All @@ -234,7 +234,7 @@ func execWithAxis(c *cli.Context, file, repoPath string, axis matrix.Axis) error
pipeline.WithContext(ctx),
pipeline.WithTracer(pipeline.DefaultTracer),
pipeline.WithLogger(defaultLogger),
pipeline.WithEngine(engine),
pipeline.WithBackend(backendEngine),
pipeline.WithDescription(map[string]string{
"CLI": "exec",
}),
Expand Down
18 changes: 9 additions & 9 deletions cmd/agent/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,22 +156,22 @@
parallel := c.Int("max-workflows")
wg.Add(parallel)

// new engine
engine, err := backend.FindEngine(backendCtx, c.String("backend-engine"))
// new backend
backendEngine, err := backend.FindBackend(backendCtx, c.String("backend-engine"))

Check warning on line 160 in cmd/agent/agent.go

View check run for this annotation

Codecov / codecov/patch

cmd/agent/agent.go#L159-L160

Added lines #L159 - L160 were not covered by tests
if err != nil {
log.Error().Err(err).Msgf("cannot find backend engine '%s'", c.String("backend-engine"))
return err
}

// load engine (e.g. init api client)
engInfo, err := engine.Load(backendCtx)
// load backend (e.g. init api client)
engInfo, err := backendEngine.Load(backendCtx)

Check warning on line 167 in cmd/agent/agent.go

View check run for this annotation

Codecov / codecov/patch

cmd/agent/agent.go#L167

Added line #L167 was not covered by tests
if err != nil {
log.Error().Err(err).Msg("cannot load backend engine")
return err
}
log.Debug().Msgf("loaded %s backend engine", engine.Name())
log.Debug().Msgf("loaded %s backend engine", backendEngine.Name())

Check warning on line 172 in cmd/agent/agent.go

View check run for this annotation

Codecov / codecov/patch

cmd/agent/agent.go#L172

Added line #L172 was not covered by tests

agentConfig.AgentID, err = client.RegisterAgent(ctx, engInfo.Platform, engine.Name(), version.String(), parallel)
agentConfig.AgentID, err = client.RegisterAgent(ctx, engInfo.Platform, backendEngine.Name(), version.String(), parallel)

Check warning on line 174 in cmd/agent/agent.go

View check run for this annotation

Codecov / codecov/patch

cmd/agent/agent.go#L174

Added line #L174 was not covered by tests
if err != nil {
return err
}
Expand All @@ -185,7 +185,7 @@
labels := map[string]string{
"hostname": hostname,
"platform": engInfo.Platform,
"backend": engine.Name(),
"backend": backendEngine.Name(),

Check warning on line 188 in cmd/agent/agent.go

View check run for this annotation

Codecov / codecov/patch

cmd/agent/agent.go#L188

Added line #L188 was not covered by tests
"repo": "*", // allow all repos by default
}

Expand Down Expand Up @@ -221,7 +221,7 @@
go func() {
defer wg.Done()

r := agent.NewRunner(client, filter, hostname, counter, &engine)
r := agent.NewRunner(client, filter, hostname, counter, &backendEngine)

Check warning on line 224 in cmd/agent/agent.go

View check run for this annotation

Codecov / codecov/patch

cmd/agent/agent.go#L224

Added line #L224 was not covered by tests
log.Debug().Msgf("created new runner %d", i)

for {
Expand All @@ -241,7 +241,7 @@

log.Info().Msgf(
"Starting Woodpecker agent with version '%s' and backend '%s' using platform '%s' running up to %d pipelines in parallel",
version.String(), engine.Name(), engInfo.Platform, parallel)
version.String(), backendEngine.Name(), engInfo.Platform, parallel)

Check warning on line 244 in cmd/agent/agent.go

View check run for this annotation

Codecov / codecov/patch

cmd/agent/agent.go#L244

Added line #L244 was not covered by tests

wg.Wait()
return nil
Expand Down
2 changes: 1 addition & 1 deletion cmd/agent/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ var flags = []cli.Flag{
&cli.StringFlag{
EnvVars: []string{"WOODPECKER_BACKEND"},
Name: "backend-engine",
Usage: "backend engine to run pipelines on",
Usage: "backend to run pipelines on",
Value: "auto-detect",
},
}
22 changes: 11 additions & 11 deletions pipeline/backend/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,26 +25,26 @@ import (
)

var (
enginesByName map[string]types.Engine
engines []types.Engine
backendsByName map[string]types.Backend
backends []types.Backend
)

func Init(ctx context.Context) {
engines = []types.Engine{
backends = []types.Backend{
docker.New(),
local.New(),
kubernetes.New(ctx),
}

enginesByName = make(map[string]types.Engine)
for _, engine := range engines {
enginesByName[engine.Name()] = engine
backendsByName = make(map[string]types.Backend)
for _, engine := range backends {
backendsByName[engine.Name()] = engine
}
}

func FindEngine(ctx context.Context, engineName string) (types.Engine, error) {
if engineName == "auto-detect" {
for _, engine := range engines {
func FindBackend(ctx context.Context, backendName string) (types.Backend, error) {
if backendName == "auto-detect" {
for _, engine := range backends {
if engine.IsAvailable(ctx) {
return engine, nil
}
Expand All @@ -53,9 +53,9 @@ func FindEngine(ctx context.Context, engineName string) (types.Engine, error) {
return nil, fmt.Errorf("can't detect an available backend engine")
}

engine, ok := enginesByName[engineName]
engine, ok := backendsByName[backendName]
if !ok {
return nil, fmt.Errorf("backend engine '%s' not found", engineName)
return nil, fmt.Errorf("backend engine '%s' not found", backendName)
}

return engine, nil
Expand Down
6 changes: 3 additions & 3 deletions pipeline/backend/docker/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@
volumeDriver = "local"
)

// New returns a new Docker Engine.
func New() backend.Engine {
// New returns a new Docker Backend.
func New() backend.Backend {

Check warning on line 55 in pipeline/backend/docker/docker.go

View check run for this annotation

Codecov / codecov/patch

pipeline/backend/docker/docker.go#L55

Added line #L55 was not covered by tests
return &docker{
client: nil,
}
Expand Down Expand Up @@ -93,7 +93,7 @@
}
}

// Load new client for Docker Engine using environment variables.
// Load new client for Docker Backend using environment variables.
func (e *docker) Load(ctx context.Context) (*backend.EngineInfo, error) {
c, ok := ctx.Value(backend.CliContext).(*cli.Context)
if !ok {
Expand Down
7 changes: 4 additions & 3 deletions pipeline/backend/kubernetes/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,10 @@
"time"

"github.com/rs/zerolog/log"
"go.woodpecker-ci.org/woodpecker/v2/pipeline/backend/types"
"gopkg.in/yaml.v3"

"go.woodpecker-ci.org/woodpecker/v2/pipeline/backend/types"

"github.com/urfave/cli/v2"
v1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/errors"
Expand Down Expand Up @@ -101,8 +102,8 @@
return nil, types.ErrNoCliContextFound
}

// New returns a new Kubernetes Engine.
func New(ctx context.Context) types.Engine {
// New returns a new Kubernetes Backend.
func New(ctx context.Context) types.Backend {

Check warning on line 106 in pipeline/backend/kubernetes/kubernetes.go

View check run for this annotation

Codecov / codecov/patch

pipeline/backend/kubernetes/kubernetes.go#L106

Added line #L106 was not covered by tests
return &kube{
ctx: ctx,
}
Expand Down
4 changes: 2 additions & 2 deletions pipeline/backend/local/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@
os, arch string
}

// New returns a new local Engine.
func New() types.Engine {
// New returns a new local Backend.
func New() types.Backend {

Check warning on line 54 in pipeline/backend/local/local.go

View check run for this annotation

Codecov / codecov/patch

pipeline/backend/local/local.go#L54

Added line #L54 was not covered by tests
return &local{
os: runtime.GOOS,
arch: runtime.GOARCH,
Expand Down
4 changes: 2 additions & 2 deletions pipeline/backend/types/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ import (
"io"
)

6543 marked this conversation as resolved.
Show resolved Hide resolved
// Engine defines a container orchestration backend and is used
// Backend defines a container orchestration backend and is used
// to create and manage container resources.
type Engine interface {
type Backend interface {
// Name returns the name of the backend.
Name() string

Expand Down
6 changes: 3 additions & 3 deletions pipeline/option.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@
// Option configures a runtime option.
type Option func(*Runtime)

// WithEngine returns an option configured with a runtime engine.
func WithEngine(engine backend.Engine) Option {
// WithBackend returns an option configured with a runtime engine.
func WithBackend(backend backend.Backend) Option {

Check warning on line 27 in pipeline/option.go

View check run for this annotation

Codecov / codecov/patch

pipeline/option.go#L27

Added line #L27 was not covered by tests
return func(r *Runtime) {
r.engine = engine
r.engine = backend

Check warning on line 29 in pipeline/option.go

View check run for this annotation

Codecov / codecov/patch

pipeline/option.go#L29

Added line #L29 was not covered by tests
}
}

Expand Down
2 changes: 1 addition & 1 deletion pipeline/pipeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ type (
type Runtime struct {
err error
spec *backend.Config
engine backend.Engine
engine backend.Backend
started int64

ctx context.Context
Expand Down