当前位置: 首页>>代码示例>>Golang>>正文


Golang DockerID.ContainerID方法代码示例

本文整理汇总了Golang中k8s/io/kubernetes/pkg/kubelet/container.DockerID.ContainerID方法的典型用法代码示例。如果您正苦于以下问题:Golang DockerID.ContainerID方法的具体用法?Golang DockerID.ContainerID怎么用?Golang DockerID.ContainerID使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在k8s/io/kubernetes/pkg/kubelet/container.DockerID的用法示例。


在下文中一共展示了DockerID.ContainerID方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: TearDownPod

func (plugin *cniNetworkPlugin) TearDownPod(namespace string, name string, id kubecontainer.DockerID) error {
	runtime, ok := plugin.host.GetRuntime().(*dockertools.DockerManager)
	if !ok {
		return fmt.Errorf("CNI execution called on non-docker runtime")
	}
	netns, err := runtime.GetNetNS(id.ContainerID())
	if err != nil {
		return err
	}

	return plugin.defaultNetwork.deleteFromNetwork(name, namespace, id.ContainerID(), netns)
}
开发者ID:XiaoningDing,项目名称:UbernetesPOC,代码行数:12,代码来源:cni.go

示例2: SetUpPod

func (plugin *cniNetworkPlugin) SetUpPod(namespace string, name string, id kubecontainer.DockerID) error {
	runtime, ok := plugin.host.GetRuntime().(*dockertools.DockerManager)
	if !ok {
		return fmt.Errorf("CNI execution called on non-docker runtime")
	}
	netns, err := runtime.GetNetNS(id.ContainerID())
	if err != nil {
		return err
	}

	_, err = plugin.defaultNetwork.addToNetwork(name, namespace, id.ContainerID(), netns)
	if err != nil {
		glog.Errorf("Error while adding to cni network: %s", err)
		return err
	}

	return err
}
开发者ID:XiaoningDing,项目名称:UbernetesPOC,代码行数:18,代码来源:cni.go

示例3: SetUpPod

func (plugin *kubenetNetworkPlugin) SetUpPod(namespace string, name string, id kubecontainer.DockerID) error {
	// Can't set up pods if we don't have a PodCIDR yet
	if plugin.netConfig == nil {
		return fmt.Errorf("Kubenet needs a PodCIDR to set up pods")
	}

	runtime, ok := plugin.host.GetRuntime().(*dockertools.DockerManager)
	if !ok {
		return fmt.Errorf("Kubenet execution called on non-docker runtime")
	}
	netnsPath, err := runtime.GetNetNS(id.ContainerID())
	if err != nil {
		return err
	}

	rt := buildCNIRuntimeConf(name, namespace, id.ContainerID(), netnsPath)
	if err != nil {
		return fmt.Errorf("Error building CNI config: %v", err)
	}

	glog.V(3).Infof("Calling cni plugins to add container to network with cni runtime: %+v", rt)
	res, err := plugin.cniConfig.AddNetwork(plugin.netConfig, rt)
	if err != nil {
		return fmt.Errorf("Error adding container to network: %v", err)
	}
	if res.IP4 == nil {
		return fmt.Errorf("CNI plugin reported no IPv4 address for container %v.", id)
	}

	plugin.podCIDRs[id] = res.IP4.IP.String()

	// The first SetUpPod call creates the bridge; ensure shaping is enabled
	if plugin.shaper == nil {
		plugin.shaper = bandwidth.NewTCShaper(BridgeName)
		if plugin.shaper == nil {
			return fmt.Errorf("Failed to create bandwidth shaper!")
		}
		plugin.shaper.ReconcileInterface()
	}

	// TODO: get ingress/egress from Pod.Spec and add pod CIDR to shaper

	return nil
}
开发者ID:RomainVabre,项目名称:origin,代码行数:44,代码来源:kubenet_linux.go

示例4: TearDownPod

func (plugin *kubenetNetworkPlugin) TearDownPod(namespace string, name string, id kubecontainer.DockerID) error {
	if plugin.netConfig == nil {
		return fmt.Errorf("Kubenet needs a PodCIDR to tear down pods")
	}

	runtime, ok := plugin.host.GetRuntime().(*dockertools.DockerManager)
	if !ok {
		return fmt.Errorf("Kubenet execution called on non-docker runtime")
	}
	netnsPath, err := runtime.GetNetNS(id.ContainerID())
	if err != nil {
		return err
	}

	rt := buildCNIRuntimeConf(name, namespace, id.ContainerID(), netnsPath)
	if err != nil {
		return fmt.Errorf("Error building CNI config: %v", err)
	}

	// no cached CIDR is Ok during teardown
	if cidr, ok := plugin.podCIDRs[id]; ok {
		glog.V(5).Infof("Removing pod CIDR %s from shaper", cidr)
		// shaper wants /32
		if addr, _, err := net.ParseCIDR(cidr); err != nil {
			if err = plugin.shaper.Reset(fmt.Sprintf("%s/32", addr.String())); err != nil {
				glog.Warningf("Failed to remove pod CIDR %s from shaper: %v", cidr, err)
			}
		}
	}
	delete(plugin.podCIDRs, id)

	glog.V(3).Infof("Calling cni plugins to remove container from network with cni runtime: %+v", rt)
	if err := plugin.cniConfig.DelNetwork(plugin.netConfig, rt); err != nil {
		return fmt.Errorf("Error removing container from network: %v", err)
	}

	return nil
}
开发者ID:RomainVabre,项目名称:origin,代码行数:38,代码来源:kubenet_linux.go


注:本文中的k8s/io/kubernetes/pkg/kubelet/container.DockerID.ContainerID方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。