ops.go 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. package daemon
  2. import (
  3. "testing"
  4. "github.com/docker/docker/testutil/environment"
  5. )
  6. // Option is used to configure a daemon.
  7. type Option func(*Daemon)
  8. // WithDefaultCgroupNamespaceMode sets the default cgroup namespace mode for the daemon
  9. func WithDefaultCgroupNamespaceMode(mode string) Option {
  10. return func(d *Daemon) {
  11. d.defaultCgroupNamespaceMode = mode
  12. }
  13. }
  14. // WithTestLogger causes the daemon to log certain actions to the provided test.
  15. func WithTestLogger(t testing.TB) Option {
  16. return func(d *Daemon) {
  17. d.log = t
  18. }
  19. }
  20. // WithExperimental sets the daemon in experimental mode
  21. func WithExperimental() Option {
  22. return func(d *Daemon) {
  23. d.experimental = true
  24. }
  25. }
  26. // WithInit sets the daemon init
  27. func WithInit() Option {
  28. return func(d *Daemon) {
  29. d.init = true
  30. }
  31. }
  32. // WithDockerdBinary sets the dockerd binary to the specified one
  33. func WithDockerdBinary(dockerdBinary string) Option {
  34. return func(d *Daemon) {
  35. d.dockerdBinary = dockerdBinary
  36. }
  37. }
  38. // WithSwarmPort sets the swarm port to use for swarm mode
  39. func WithSwarmPort(port int) Option {
  40. return func(d *Daemon) {
  41. d.SwarmPort = port
  42. }
  43. }
  44. // WithSwarmListenAddr sets the swarm listen addr to use for swarm mode
  45. func WithSwarmListenAddr(listenAddr string) Option {
  46. return func(d *Daemon) {
  47. d.swarmListenAddr = listenAddr
  48. }
  49. }
  50. // WithSwarmDefaultAddrPool sets the swarm default address pool to use for swarm mode
  51. func WithSwarmDefaultAddrPool(defaultAddrPool []string) Option {
  52. return func(d *Daemon) {
  53. d.DefaultAddrPool = defaultAddrPool
  54. }
  55. }
  56. // WithSwarmDefaultAddrPoolSubnetSize sets the subnet length mask of swarm default address pool to use for swarm mode
  57. func WithSwarmDefaultAddrPoolSubnetSize(subnetSize uint32) Option {
  58. return func(d *Daemon) {
  59. d.SubnetSize = subnetSize
  60. }
  61. }
  62. // WithSwarmDataPathPort sets the swarm datapath port to use for swarm mode
  63. func WithSwarmDataPathPort(datapathPort uint32) Option {
  64. return func(d *Daemon) {
  65. d.DataPathPort = datapathPort
  66. }
  67. }
  68. // WithEnvironment sets options from testutil/environment.Execution struct
  69. func WithEnvironment(e environment.Execution) Option {
  70. return func(d *Daemon) {
  71. if e.DaemonInfo.ExperimentalBuild {
  72. d.experimental = true
  73. }
  74. }
  75. }
  76. // WithStorageDriver sets store driver option
  77. func WithStorageDriver(driver string) Option {
  78. return func(d *Daemon) {
  79. d.storageDriver = driver
  80. }
  81. }