(state *specs.State, dataStore, cniPath, cniNetconfPath, bridgeIP string)
| 134 | } |
| 135 | |
| 136 | func 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)) |
no test coverage detected
searching dependent graphs…