MCPcopy Create free account
hub / github.com/containerd/nerdctl / newHandlerOpts

Function newHandlerOpts

pkg/ocihook/ocihook.go:136–252  ·  view source on GitHub ↗
(state *specs.State, dataStore, cniPath, cniNetconfPath, bridgeIP string)

Source from the content-addressed store, hash-verified

134}
135
136func newHandlerOpts(state *specs.State, dataStore, cniPath, cniNetconfPath, bridgeIP string) (*handlerOpts, error) {
137 o := &handlerOpts{
138 state: state,
139 dataStore: dataStore,
140 }
141
142 extraHosts, err := getExtraHosts(state)
143 if err != nil {
144 return nil, err
145 }
146 o.extraHosts = extraHosts
147
148 hs, err := loadSpec(o.state.Bundle)
149 if err != nil {
150 return nil, err
151 }
152 o.rootfs = hs.Root.Path
153 if !filepath.IsAbs(o.rootfs) {
154 o.rootfs = filepath.Join(o.state.Bundle, o.rootfs)
155 }
156
157 namespace := o.state.Annotations[labels.Namespace]
158 if namespace == "" {
159 return nil, errors.New("namespace must be set")
160 }
161 if o.state.ID == "" {
162 return nil, errors.New("state.ID must be set")
163 }
164 o.fullID = namespace + "-" + o.state.ID
165
166 networksJSON := o.state.Annotations[labels.Networks]
167 var networks []string
168 if err := json.Unmarshal([]byte(networksJSON), &networks); err != nil {
169 return nil, err
170 }
171
172 netType, err := nettype.Detect(networks)
173 if err != nil {
174 return nil, err
175 }
176
177 switch netType {
178 case nettype.Host, nettype.None, nettype.Container, nettype.Namespace:
179 // NOP
180 case nettype.CNI:
181 e, err := netutil.NewCNIEnv(cniPath, cniNetconfPath, netutil.WithNamespace(namespace), netutil.WithDefaultNetwork(bridgeIP))
182 if err != nil {
183 return nil, err
184 }
185 cniOpts := []cni.Opt{
186 cni.WithPluginDir([]string{cniPath}),
187 }
188 var netw *netutil.NetworkConfig
189 for _, netstr := range networks {
190 if netw, err = e.NetworkByNameOrID(netstr); err != nil {
191 return nil, err
192 }
193 cniOpts = append(cniOpts, cni.WithConfListBytes(netw.Bytes))

Callers 1

RunFunction · 0.85

Calls 14

NetworkByNameOrIDMethod · 0.95
DetectFunction · 0.92
NewCNIEnvFunction · 0.92
WithNamespaceFunction · 0.92
WithDefaultNetworkFunction · 0.92
LoadPortMappingsFunction · 0.92
IsRootlessChildFunction · 0.92
NewRootlessKitClientFunction · 0.92
IsBypass4netnsEnabledFunction · 0.92
getExtraHostsFunction · 0.85
loadSpecFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…