github.com/moby/docker@v26.1.3+incompatible/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  func WithUserNsRemap(remap string) Option {
    23  	return func(d *Daemon) {
    24  		d.usernsRemap = remap
    25  	}
    26  }
    27  
    28  // WithDefaultCgroupNamespaceMode sets the default cgroup namespace mode for the daemon
    29  func WithDefaultCgroupNamespaceMode(mode string) Option {
    30  	return func(d *Daemon) {
    31  		d.defaultCgroupNamespaceMode = mode
    32  	}
    33  }
    34  
    35  // WithTestLogger causes the daemon to log certain actions to the provided test.
    36  func WithTestLogger(t LogT) Option {
    37  	return func(d *Daemon) {
    38  		d.log = t
    39  	}
    40  }
    41  
    42  // WithExperimental sets the daemon in experimental mode
    43  func WithExperimental() Option {
    44  	return func(d *Daemon) {
    45  		d.experimental = true
    46  	}
    47  }
    48  
    49  // WithInit sets the daemon init
    50  func WithInit() Option {
    51  	return func(d *Daemon) {
    52  		d.init = true
    53  	}
    54  }
    55  
    56  // WithDockerdBinary sets the dockerd binary to the specified one
    57  func WithDockerdBinary(dockerdBinary string) Option {
    58  	return func(d *Daemon) {
    59  		d.dockerdBinary = dockerdBinary
    60  	}
    61  }
    62  
    63  // WithSwarmPort sets the swarm port to use for swarm mode
    64  func WithSwarmPort(port int) Option {
    65  	return func(d *Daemon) {
    66  		d.SwarmPort = port
    67  	}
    68  }
    69  
    70  // WithSwarmListenAddr sets the swarm listen addr to use for swarm mode
    71  func WithSwarmListenAddr(listenAddr string) Option {
    72  	return func(d *Daemon) {
    73  		d.swarmListenAddr = listenAddr
    74  	}
    75  }
    76  
    77  // WithSwarmDefaultAddrPool sets the swarm default address pool to use for swarm mode
    78  func WithSwarmDefaultAddrPool(defaultAddrPool []string) Option {
    79  	return func(d *Daemon) {
    80  		d.DefaultAddrPool = defaultAddrPool
    81  	}
    82  }
    83  
    84  // WithSwarmDefaultAddrPoolSubnetSize sets the subnet length mask of swarm default address pool to use for swarm mode
    85  func WithSwarmDefaultAddrPoolSubnetSize(subnetSize uint32) Option {
    86  	return func(d *Daemon) {
    87  		d.SubnetSize = subnetSize
    88  	}
    89  }
    90  
    91  // WithSwarmDataPathPort sets the  swarm datapath port to use for swarm mode
    92  func WithSwarmDataPathPort(datapathPort uint32) Option {
    93  	return func(d *Daemon) {
    94  		d.DataPathPort = datapathPort
    95  	}
    96  }
    97  
    98  // WithEnvironment sets options from testutil/environment.Execution struct
    99  func WithEnvironment(e environment.Execution) Option {
   100  	return func(d *Daemon) {
   101  		if e.DaemonInfo.ExperimentalBuild {
   102  			d.experimental = true
   103  		}
   104  	}
   105  }
   106  
   107  // WithStorageDriver sets store driver option
   108  func WithStorageDriver(driver string) Option {
   109  	return func(d *Daemon) {
   110  		d.storageDriver = driver
   111  	}
   112  }
   113  
   114  // WithRootlessUser sets the daemon to be rootless
   115  func WithRootlessUser(username string) Option {
   116  	return func(d *Daemon) {
   117  		u, err := user.Lookup(username)
   118  		if err != nil {
   119  			panic(err)
   120  		}
   121  		d.rootlessUser = u
   122  	}
   123  }
   124  
   125  // WithOOMScoreAdjust sets OOM score for the daemon
   126  func WithOOMScoreAdjust(score int) Option {
   127  	return func(d *Daemon) {
   128  		d.OOMScoreAdjust = score
   129  	}
   130  }
   131  
   132  // WithEnvVars sets additional environment variables for the daemon
   133  func WithEnvVars(vars ...string) Option {
   134  	return func(d *Daemon) {
   135  		d.extraEnv = append(d.extraEnv, vars...)
   136  	}
   137  }