Create will create a container.
(ctx context.Context, client *containerd.Client, args []string, netManager containerutil.NetworkOptionsManager, options types.ContainerCreateOptions)
| 71 | |
| 72 | // Create will create a container. |
| 73 | func Create(ctx context.Context, client *containerd.Client, args []string, netManager containerutil.NetworkOptionsManager, options types.ContainerCreateOptions) (containerd.Container, func(), error) { |
| 74 | // Acquire an exclusive lock on the volume store until we are done to avoid being raced by any other |
| 75 | // volume operations (or any other operation involving volume manipulation) |
| 76 | volStore, err := volume.Store(options.GOptions.Namespace, options.GOptions.DataRoot, options.GOptions.Address) |
| 77 | if err != nil { |
| 78 | return nil, nil, err |
| 79 | } |
| 80 | err = volStore.Lock() |
| 81 | if err != nil { |
| 82 | return nil, nil, err |
| 83 | } |
| 84 | defer volStore.Release() |
| 85 | |
| 86 | // simulate the behavior of double dash |
| 87 | newArg := []string{} |
| 88 | if len(args) >= 2 && args[1] == "--" { |
| 89 | newArg = append(newArg, args[:1]...) |
| 90 | newArg = append(newArg, args[2:]...) |
| 91 | args = newArg |
| 92 | } |
| 93 | var internalLabels internalLabels |
| 94 | internalLabels.platform = options.Platform |
| 95 | internalLabels.namespace = options.GOptions.Namespace |
| 96 | |
| 97 | var ( |
| 98 | id = idgen.GenerateID() |
| 99 | opts []oci.SpecOpts |
| 100 | cOpts []containerd.NewContainerOpts |
| 101 | ) |
| 102 | |
| 103 | if options.CidFile != "" { |
| 104 | if err := writeCIDFile(options.CidFile, id); err != nil { |
| 105 | return nil, nil, err |
| 106 | } |
| 107 | internalLabels.cidFile = options.CidFile |
| 108 | } |
| 109 | dataStore, err := clientutil.DataStore(options.GOptions.DataRoot, options.GOptions.Address) |
| 110 | if err != nil { |
| 111 | return nil, nil, err |
| 112 | } |
| 113 | |
| 114 | internalLabels.stateDir, err = containerutil.ContainerStateDirPath(options.GOptions.Namespace, dataStore, id) |
| 115 | if err != nil { |
| 116 | return nil, nil, err |
| 117 | } |
| 118 | if err := os.MkdirAll(internalLabels.stateDir, 0700); err != nil { |
| 119 | return nil, nil, err |
| 120 | } |
| 121 | |
| 122 | opts = append(opts, |
| 123 | oci.WithDefaultSpec(), |
| 124 | ) |
| 125 | |
| 126 | platformOpts, err := setPlatformOptions(ctx, client, id, netManager.NetworkOptions().UTSNamespace, &internalLabels, options) |
| 127 | if err != nil { |
| 128 | return nil, generateRemoveStateDirFunc(ctx, id, internalLabels), err |
| 129 | } |
| 130 | opts = append(opts, platformOpts...) |
no test coverage detected
searching dependent graphs…