config.go 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. package agent
  2. import (
  3. "github.com/boltdb/bolt"
  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. "google.golang.org/grpc/credentials"
  10. )
  11. // NodeChanges encapsulates changes that should be made to the node as per session messages
  12. // from the dispatcher
  13. type NodeChanges struct {
  14. Node *api.Node
  15. RootCert []byte
  16. }
  17. // Config provides values for an Agent.
  18. type Config struct {
  19. // Hostname the name of host for agent instance.
  20. Hostname string
  21. // ConnBroker provides a connection broker for retrieving gRPC
  22. // connections to managers.
  23. ConnBroker *connectionbroker.Broker
  24. // Executor specifies the executor to use for the agent.
  25. Executor exec.Executor
  26. // DB used for task storage. Must be open for the lifetime of the agent.
  27. DB *bolt.DB
  28. // NotifyNodeChange channel receives new node changes from session messages.
  29. NotifyNodeChange chan<- *NodeChanges
  30. // NotifyTLSChange channel sends new TLS information changes, which can cause a session to restart
  31. NotifyTLSChange <-chan events.Event
  32. // Credentials is credentials for grpc connection to manager.
  33. Credentials credentials.TransportCredentials
  34. // NodeTLSInfo contains the starting node TLS info to bootstrap into the agent
  35. NodeTLSInfo *api.NodeTLSInfo
  36. }
  37. func (c *Config) validate() error {
  38. if c.Credentials == nil {
  39. return errors.New("agent: Credentials is required")
  40. }
  41. if c.Executor == nil {
  42. return errors.New("agent: executor required")
  43. }
  44. if c.DB == nil {
  45. return errors.New("agent: database required")
  46. }
  47. if c.NodeTLSInfo == nil {
  48. return errors.New("agent: Node TLS info is required")
  49. }
  50. return nil
  51. }