github.com/jfrazelle/docker@v1.1.2-0.20210712172922-bf78e25fe508/testutil/daemon/ops.go (about)

     1  package daemon
     2  
     3  import (
     4  	"os/user"
     5  
     6  	"github.com/docker/docker/testutil/environment"
     7  )
     8  
     9  // Option is used to configure a daemon.
    10  type Option func(*Daemon)
    11  
    12  // WithContainerdSocket sets the --containerd option on the daemon.
    13  // Use an empty string to remove the option.
    14  //
    15  // If unset the --containerd option will be used with a default value.
    16  func WithContainerdSocket(socket string) Option {
    17  	return func(d *Daemon) {
    18  		d.containerdSocket = socket
    19  	}
    20  }
    21  
    22  // WithDefaultCgroupNamespaceMode sets the default cgroup namespace mode for the daemon
    23  func WithDefaultCgroupNamespaceMode(mode string) Option {
    24  	return func(d *Daemon) {
    25  		d.defaultCgroupNamespaceMode = mode
    26  	}
    27  }
    28  
    29  // WithTestLogger causes the daemon to log certain actions to the provided test.
    30  func WithTestLogger(t LogT) Option {
    31  	return func(d *Daemon) {
    32  		d.log = t
    33  	}
    34  }
    35  
    36  // WithExperimental sets the daemon in experimental mode
    37  func WithExperimental() Option {
    38  	return func(d *Daemon) {
    39  		d.experimental = true
    40  	}
    41  }
    42  
    43  // WithInit sets the daemon init
    44  func WithInit() Option {
    45  	return func(d *Daemon) {
    46  		d.init = true
    47  	}
    48  }
    49  
    50  // WithDockerdBinary sets the dockerd binary to the specified one
    51  func WithDockerdBinary(dockerdBinary string) Option {
    52  	return func(d *Daemon) {
    53  		d.dockerdBinary = dockerdBinary
    54  	}
    55  }
    56  
    57  // WithSwarmPort sets the swarm port to use for swarm mode
    58  func WithSwarmPort(port int) Option {
    59  	return func(d *Daemon) {
    60  		d.SwarmPort = port
    61  	}
    62  }
    63  
    64  // WithSwarmListenAddr sets the swarm listen addr to use for swarm mode
    65  func WithSwarmListenAddr(listenAddr string) Option {
    66  	return func(d *Daemon) {
    67  		d.swarmListenAddr = listenAddr
    68  	}
    69  }
    70  
    71  // WithSwarmDefaultAddrPool sets the swarm default address pool to use for swarm mode
    72  func WithSwarmDefaultAddrPool(defaultAddrPool []string) Option {
    73  	return func(d *Daemon) {
    74  		d.DefaultAddrPool = defaultAddrPool
    75  	}
    76  }
    77  
    78  // WithSwarmDefaultAddrPoolSubnetSize sets the subnet length mask of swarm default address pool to use for swarm mode
    79  func WithSwarmDefaultAddrPoolSubnetSize(subnetSize uint32) Option {
    80  	return func(d *Daemon) {
    81  		d.SubnetSize = subnetSize
    82  	}
    83  }
    84  
    85  // WithSwarmDataPathPort sets the  swarm datapath port to use for swarm mode
    86  func WithSwarmDataPathPort(datapathPort uint32) Option {
    87  	return func(d *Daemon) {
    88  		d.DataPathPort = datapathPort
    89  	}
    90  }
    91  
    92  // WithEnvironment sets options from testutil/environment.Execution struct
    93  func WithEnvironment(e environment.Execution) Option {
    94  	return func(d *Daemon) {
    95  		if e.DaemonInfo.ExperimentalBuild {
    96  			d.experimental = true
    97  		}
    98  	}
    99  }
   100  
   101  // WithStorageDriver sets store driver option
   102  func WithStorageDriver(driver string) Option {
   103  	return func(d *Daemon) {
   104  		d.storageDriver = driver
   105  	}
   106  }
   107  
   108  // WithRootlessUser sets the daemon to be rootless
   109  func WithRootlessUser(username string) Option {
   110  	return func(d *Daemon) {
   111  		u, err := user.Lookup(username)
   112  		if err != nil {
   113  			panic(err)
   114  		}
   115  		d.rootlessUser = u
   116  	}
   117  }
   118  
   119  // WithOOMScoreAdjust sets OOM score for the daemon
   120  func WithOOMScoreAdjust(score int) Option {
   121  	return func(d *Daemon) {
   122  		d.OOMScoreAdjust = score
   123  	}
   124  }