1,//Cri-o/server/sandbox.go
Func (S *server) Runpodsandbox (CTX context. Context, req *PB. Runpodsandboxrequest) (*PB. Runpodsandboxresponse, error)
In this function, it has been called successively:
(1), container, err: = OCI. Newcontainer (Containerid, ContainerName, Podsandboxdir, Podsandboxdir, labels, nil, ID, false)
Sb.infracontainer = Container
S.runtime.createcontainer (Container)
S.runtime.updatestatus (containers) Create INFRA container
(2), then call Podnamespace: = "" and Netnspath, err: = Container.netnspath (), the function only returns the path/proc/infra-container-id/ns/net
(3), call S.netplugin.setuppod (Netnspath, podnamespace, ID, containername), create a network for the container
--------------------------------------------------------------------------the------------------------------of the MLM initialization --------------------------------------------------------------------
2,//Cri-o/vendor/src/github.com/rajatchopra/ocicni.go
The server's Netplugin field is initialized to: Netplugin, err: = Ocicni. INITCNI ("")
Func initcni (Plugindir string) (Cniplugin, error)
(1), first call plugin: = Probenetworkpluginswithvendorcnidirprefix (Plugindir, "") and plugin.nsenterpath, err = exec. Lookpath ("Nsenter")
(2), check whether the default network exists, if not exist then stop the search, directly return a NoOp plugin, call _, err = Getdefaultcninetwork (Plugin.plugindir, Plugin.vendorcnidirprefix)
(3), when there is a default network presence, periodically read the update of the configuration from the Plugindir. That is, generate a goroutine, call Plugin.syncnetworkconfig () every 10s
3,//Cri-o/vendor/src/github.com/rajatchopra/ocicni.go
Func Probenetworkpluginswithvendorcnidirprefix (Plugindir, Vendorcnidirprefix string) (*cninetworkplugin)
Configuration Get Plugin: = &cninetworkplugin {
Defaultnetwork:nil,
Lonetwork:getlonetwork (Vendorcnidirprefix),
Plugindir:plugindir,
Vendorcnidirprefix:vendorcnidirprefix,
}
Finally call Plugin.syncnetworkconfig () and return the return plugin, where Syncnetworkconfig first calls network, err: = Getdefaultcninetwork ( Plugin.plugindir, Plugin.vendorcnidirprefix), and then call Plugin.setdefaultnetwork (Network) Set to Plugin.defaultnetwork for network
4,//cri-o/vendor/src/github.com/rajachopra/ocicni.go
(1), manually add Loconfig, err: = Libcni. Conffrombytes ([]byte (' {"cniversion": "0.1.0", "name": "Cni-loopback", "type": "Loopback"} '))
(2), call cninet: = &libcni. Cniconfig{path: []string{vendorcnidir (Vendordirprefix, LoConfig.Network.Type), Defaultcnidir}}
and return reutrn lonetwork: = &cninetwork{name: "Lo", Networkconfig:loconfig, cniconfig:cninet}
5,//cri-o/vendor/src/github.com/rajatchopra/ocicni.go
Func getdefaultcninetwork (Plugindir, Vendorcnidirprefix string) (*cninetwork, error)
(1), when Plugindir is empty, set Plugindir to Defaultnetdir for/ETC/CNI/NET.D
(2), call files, err: = Libcni. Conffiles (Plugindir), loading configuration file
(3), if files is not empty, then call for loop, for _, Conffile: = Range Files
For Conffile, first call conf, err: = Libcni. Conffromfile (Conffile)
Call Vendordir again: = Vendorcnidir (Vendorcnidirprefix, Conf.Network.Type),cninet: = &libcni. Cniconfig{path: []string{defaultcnidir, Vendordir}}
Where Vendordir is "/opt/plugintype/bin"
Finally, return to network: = &cninetwork{name:conf.network.name, networkconfig:conf, cniconfig:cninet}
------------------------------------------------------------------------------set the network--------------------for the pod -------------------------------------------------------------------------------
6,//cni-o/vendor/src/github.com/rajatchopra/ocicni.go
Func (plugin *cninetworkplugin) setuppod (Netnspath string, namespace string, name string, ID string) error
(1), call plugin.checkinitialized (), determine whether the plugin.defaultnetwork is empty, if empty, return an error
(2), call Plugin.loNetwork.addToNetwork (name, namespace, ID, Netnspath) and Plugin.getdefaultnetwork () respectively. Addtonetwork ( Name, namespace, ID, Netnspath)
7,//cni-o/vendor/src/github.com/rajatchopra/ocicni.go
Func (Network *cninetwork) addtonetwork (Podname string, podnamespace string, Podinfracontainerid string, Podnetnspath String) (*cnitypes. Result, error)
(1), call RT, err: = buildcniruntimeconf (Podname, Podnamespace, Podinfaracontainerid, Podnetnspath)
(2), then call netconf, cninet: = Network.networkconfig, network. Cniconfig, the last call to res, err: = Cninet. Addnetwork (netconf, RT)
8,//cni-o/vendor/src/github.com/rajatchopra/ocicni.go
Func buildcniruntimeconf (Podname string, Podns string, Podinfracontainerid string, Podnetnspath string) (*LIBCNI. runtimeconf, error)
The function simply fills in the LIBCNI. Runtimeconf and return
RT: = &libcni. runtimeconf {
Containerid:podinfracontainerid,
Netns:podnetnspath,
Ifname:defaultinterfacename,
Args: [][2]string {
{"Ignoreunknown", "1"},
{"K8s_pod_namespace", Podns},
{"K8s_pod_name", Podname},
{"k8s_pod_infra_container_id", Podinfracontainerid},
}
}
Integration analysis of Cri-o and the MLM