File: setup.go

package info (click to toggle)
docker.io 28.5.2%2Bdfsg1-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 69,048 kB
  • sloc: sh: 5,867; makefile: 863; ansic: 184; python: 162; asm: 159
file content (47 lines) | stat: -rw-r--r-- 1,028 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
//go:build linux

package bridge

import (
	"context"

	"github.com/docker/docker/internal/otelutil"
	"go.opentelemetry.io/otel"
)

type setupStep struct {
	name string
	fn   stepFn
}

type stepFn func(*networkConfiguration, *bridgeInterface) error

type bridgeSetup struct {
	config *networkConfiguration
	bridge *bridgeInterface
	steps  []setupStep
}

func newBridgeSetup(c *networkConfiguration, i *bridgeInterface) *bridgeSetup {
	return &bridgeSetup{config: c, bridge: i}
}

func (b *bridgeSetup) apply(ctx context.Context) error {
	for _, step := range b.steps {
		ctx, span := otel.Tracer("").Start(ctx, spanPrefix+"."+step.name)
		_ = ctx // To avoid unused variable error while making sure that if / when setupStep starts taking a context, the right value will be used.

		err := step.fn(b.config, b.bridge)
		otelutil.RecordStatus(span, err)
		span.End()

		if err != nil {
			return err
		}
	}
	return nil
}

func (b *bridgeSetup) queueStep(name string, fn stepFn) {
	b.steps = append(b.steps, setupStep{name, fn})
}