Repository: moby/moby
File: integration/internal/network/ops.go (Go)

Code before:
	return func(n *types.NetworkCreate) {
		n.Internal = true
	}
}

// WithAttachable sets Attachable flag on the create network request
func WithAttachable() func(*types.NetworkCreate) {
	return func(n *types.NetworkCreate) {
		n.Attachable = true
	}
}

// WithMacvlan sets the network as macvlan with the specified parent
func WithMacvlan(parent string) func(*types.NetworkCreate) {
	return func(n *types.NetworkCreate) {
		n.Driver = "macvlan"
		if parent != "" {
			n.Options = map[string]string{
				"parent": parent,
			}
		}
	}
}

// WithMacvlanPassthru sets the network as macvlan with the specified parent in passthru mode
func WithMacvlanPassthru(parent string) func(*types.NetworkCreate) {
	return func(n *types.NetworkCreate) {
		n.Driver = "macvlan"
		n.Options = map[string]string{
			"macvlan_mode": "passthru",
		}
		if parent != "" {
			n.Options["parent"] = parent
		}
	}
}

// WithIPvlan sets the network as ipvlan with the specified parent and mode
func WithIPvlan(parent, mode string) func(*types.NetworkCreate) {
	return func(n *types.NetworkCreate) {
		n.Driver = "ipvlan"
		if n.Options == nil {
			n.Options = map[string]string{}
		}
		if parent != "" {
			n.Options["parent"] = parent
		}
		if mode != "" {
			n.Options["ipvlan_mode"] = mode
		}
	}

Review comment (bug):
Looks like this no longer compiles when merged into master; I noticed this was failing when I restarted  Jenkins (which does a merge before testing);

[2024-06-15T13:02:18.893Z] # github.com/docker/docker/integration/internal/network
[2024-06-15T13:02:18.893Z] integration/internal/network/ops.go:49:47: undefined: types
[2024-06-15T13:02:18.893Z] integration/internal/network/ops.go:50:17: undefined: types


This needs to be updated to use `network.CreateOptions`.


Let me do a quick rebase, and fix this so that Ci can do another run 👍 

Code after:
	return func(n *network.CreateOptions) {
		n.Internal = true
	}
}

// WithAttachable sets Attachable flag on the create network request
func WithAttachable() func(*network.CreateOptions) {
	return func(n *network.CreateOptions) {
		n.Attachable = true
	}
}

// WithMacvlan sets the network as macvlan with the specified parent
func WithMacvlan(parent string) func(*network.CreateOptions) {
	return func(n *network.CreateOptions) {
		n.Driver = "macvlan"
		if parent != "" {
			n.Options = map[string]string{
				"parent": parent,
			}
		}
	}
}

// WithMacvlanPassthru sets the network as macvlan with the specified parent in passthru mode
func WithMacvlanPassthru(parent string) func(options *network.CreateOptions) {
	return func(n *network.CreateOptions) {
		n.Driver = "macvlan"
		n.Options = map[string]string{
			"macvlan_mode": "passthru",
		}
		if parent != "" {
			n.Options["parent"] = parent
		}
	}
}

// WithIPvlan sets the network as ipvlan with the specified parent and mode
func WithIPvlan(parent, mode string) func(*network.CreateOptions) {
	return func(n *network.CreateOptions) {
		n.Driver = "ipvlan"
		if n.Options == nil {
			n.Options = map[string]string{}
		}
		if parent != "" {
			n.Options["parent"] = parent
		}
		if mode != "" {
			n.Options["ipvlan_mode"] = mode
		}
	}