當前位置: 首頁>>代碼示例>>Golang>>正文


Golang container.DockerID類代碼示例

本文整理匯總了Golang中k8s/io/kubernetes/pkg/kubelet/container.DockerID的典型用法代碼示例。如果您正苦於以下問題:Golang DockerID類的具體用法?Golang DockerID怎麽用?Golang DockerID使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了DockerID類的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類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。