File: config.go

package info (click to toggle)
docker.io 26.1.5%2Bdfsg1-9
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 68,576 kB
  • sloc: sh: 5,748; makefile: 912; ansic: 664; asm: 228; python: 162
file content (86 lines) | stat: -rw-r--r-- 2,435 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
package agent

import (
	"github.com/docker/go-events"
	"github.com/moby/swarmkit/v2/agent/exec"
	"github.com/moby/swarmkit/v2/api"
	"github.com/moby/swarmkit/v2/connectionbroker"
	"github.com/pkg/errors"
	bolt "go.etcd.io/bbolt"
	"google.golang.org/grpc/credentials"
)

// NodeChanges encapsulates changes that should be made to the node as per session messages
// from the dispatcher
type NodeChanges struct {
	Node     *api.Node
	RootCert []byte
}

// Config provides values for an Agent.
type Config struct {
	// Hostname the name of host for agent instance.
	Hostname string

	// ConnBroker provides a connection broker for retrieving gRPC
	// connections to managers.
	ConnBroker *connectionbroker.Broker

	// Executor specifies the executor to use for the agent.
	Executor exec.Executor

	// DB used for task storage. Must be open for the lifetime of the agent.
	DB *bolt.DB

	// NotifyNodeChange channel receives new node changes from session messages.
	NotifyNodeChange chan<- *NodeChanges

	// NotifyTLSChange channel sends new TLS information changes, which can cause a session to restart
	NotifyTLSChange <-chan events.Event

	// Credentials is credentials for grpc connection to manager.
	Credentials credentials.TransportCredentials

	// NodeTLSInfo contains the starting node TLS info to bootstrap into the agent
	NodeTLSInfo *api.NodeTLSInfo

	// SessionTracker, if provided, will have its SessionClosed and SessionError methods called
	// when sessions close and error.
	SessionTracker SessionTracker

	// FIPS returns whether the node is FIPS-enabled
	FIPS bool
}

func (c *Config) validate() error {
	if c.Credentials == nil {
		return errors.New("agent: Credentials is required")
	}

	if c.Executor == nil {
		return errors.New("agent: executor required")
	}

	if c.DB == nil {
		return errors.New("agent: database required")
	}

	if c.NodeTLSInfo == nil {
		return errors.New("agent: Node TLS info is required")
	}

	return nil
}

// A SessionTracker gets notified when sessions close and error
type SessionTracker interface {
	// SessionClosed is called whenever a session is closed - if the function errors, the agent
	// will exit with the returned error.  Otherwise the agent can continue and rebuild a new session.
	SessionClosed() error

	// SessionError is called whenever a session errors
	SessionError(err error)

	// SessionEstablished is called whenever a session is established
	SessionEstablished()
}