Skip to content

Refactor pkg/netutil to support more network parameters #671

@junnplus

Description

@junnplus

https://github.com/containerd/nerdctl/blob/master/pkg/netutil/netutil_unix.go#L37-L56

Now the cni plugin is generated through a fixed template, it is difficult to be extended to support more network parameters, like --ip-range.

I think we can refactor it in the follow way:

const ConfigListTemplate = `{
  "cniVersion": "0.4.0",
  "name": "{{.Name}}",
  "nerdctlID": {{.ID}},
  "nerdctlLabels": {{.Labels}},
  "plugins": {{.Plugins}}
}`

type ConfigListTemplateOpts struct {
	ID      int
	Name    string // e.g. "nerdctl"
	Labels  string // e.g. `{"version":"1.1.0"}`
	Plugins string
}

func GenerateConfigList(e *CNIEnv, labels []string, id int, name, cidr string) (*NetworkConfigList, error) {
...
    	plugins := []CNIPlugin{bridge, NewPortMapPlugin()...]
    	pluginJson, err := json.Marshal(plugins)
	if err != nil {
		return nil, err
	}

}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions