github.com/kaisenlinux/docker.io@v0.0.0-20230510090727-ea55db55fac7/swarmkit/agent/config.go (about)

     1  package agent
     2  
     3  import (
     4  	"github.com/docker/go-events"
     5  	"github.com/docker/swarmkit/agent/exec"
     6  	"github.com/docker/swarmkit/api"
     7  	"github.com/docker/swarmkit/connectionbroker"
     8  	"github.com/pkg/errors"
     9  	bolt "go.etcd.io/bbolt"
    10  	"google.golang.org/grpc/credentials"
    11  )
    12  
    13  // NodeChanges encapsulates changes that should be made to the node as per session messages
    14  // from the dispatcher
    15  type NodeChanges struct {
    16  	Node     *api.Node
    17  	RootCert []byte
    18  }
    19  
    20  // Config provides values for an Agent.
    21  type Config struct {
    22  	// Hostname the name of host for agent instance.
    23  	Hostname string
    24  
    25  	// ConnBroker provides a connection broker for retrieving gRPC
    26  	// connections to managers.
    27  	ConnBroker *connectionbroker.Broker
    28  
    29  	// Executor specifies the executor to use for the agent.
    30  	Executor exec.Executor
    31  
    32  	// DB used for task storage. Must be open for the lifetime of the agent.
    33  	DB *bolt.DB
    34  
    35  	// NotifyNodeChange channel receives new node changes from session messages.
    36  	NotifyNodeChange chan<- *NodeChanges
    37  
    38  	// NotifyTLSChange channel sends new TLS information changes, which can cause a session to restart
    39  	NotifyTLSChange <-chan events.Event
    40  
    41  	// Credentials is credentials for grpc connection to manager.
    42  	Credentials credentials.TransportCredentials
    43  
    44  	// NodeTLSInfo contains the starting node TLS info to bootstrap into the agent
    45  	NodeTLSInfo *api.NodeTLSInfo
    46  
    47  	// SessionTracker, if provided, will have its SessionClosed and SessionError methods called
    48  	// when sessions close and error.
    49  	SessionTracker SessionTracker
    50  
    51  	// FIPS returns whether the node is FIPS-enabled
    52  	FIPS bool
    53  }
    54  
    55  func (c *Config) validate() error {
    56  	if c.Credentials == nil {
    57  		return errors.New("agent: Credentials is required")
    58  	}
    59  
    60  	if c.Executor == nil {
    61  		return errors.New("agent: executor required")
    62  	}
    63  
    64  	if c.DB == nil {
    65  		return errors.New("agent: database required")
    66  	}
    67  
    68  	if c.NodeTLSInfo == nil {
    69  		return errors.New("agent: Node TLS info is required")
    70  	}
    71  
    72  	return nil
    73  }
    74  
    75  // A SessionTracker gets notified when sessions close and error
    76  type SessionTracker interface {
    77  	// SessionClosed is called whenever a session is closed - if the function errors, the agent
    78  	// will exit with the returned error.  Otherwise the agent can continue and rebuild a new session.
    79  	SessionClosed() error
    80  
    81  	// SessionError is called whenever a session errors
    82  	SessionError(err error)
    83  
    84  	// SessionEstablished is called whenever a session is established
    85  	SessionEstablished()
    86  }