• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Golang cniapi.RspAddPod类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/contiv/netplugin/mgmtfn/k8splugin/cniapi.RspAddPod的典型用法代码示例。如果您正苦于以下问题:Golang RspAddPod类的具体用法?Golang RspAddPod怎么用?Golang RspAddPod使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



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

示例1: deletePod

// deletePod is the handler for pod deletes
func deletePod(r *http.Request) (interface{}, error) {

	resp := cniapi.RspAddPod{}

	logEvent("del pod")

	content, err := ioutil.ReadAll(r.Body)
	if err != nil {
		log.Errorf("Failed to read request: %v", err)
		return resp, err
	}

	pInfo := cniapi.CNIPodAttr{}
	if err := json.Unmarshal(content, &pInfo); err != nil {
		return resp, err
	}

	// Get labels from the kube api server
	epReq, err := getEPSpec(&pInfo)
	if err != nil {
		log.Errorf("Error getting labels. Err: %v", err)
		setErrorResp(&resp, "Error getting labels", err)
		return resp, err
	}

	netPlugin.DeleteHostAccPort(epReq.EndpointID)
	err = epCleanUp(epReq)
	resp.Result = 0
	resp.EndpointID = pInfo.InfraContainerID
	return resp, err
}
开发者ID:abhinandanpb,项目名称:netplugin,代码行数:32,代码来源:driver.go


示例2: stubAddPod

// stubAddPod is the handler for testing pod additions
func stubAddPod(r *http.Request) (interface{}, error) {

	resp := cniapi.RspAddPod{}

	content, err := ioutil.ReadAll(r.Body)
	if err != nil {
		logger.Errorf("Failed to read request: %v", err)
		return resp, err
	}

	pInfo := cniapi.CNIPodAttr{}
	if err := json.Unmarshal(content, &pInfo); err != nil {
		return resp, err
	}

	// verify pod attributes are as expected.
	if pInfo.Name == "utPod" && pInfo.K8sNameSpace == "utK8sNS" &&
		pInfo.InfraContainerID != "" && pInfo.IntfName != "" {
		_, err := nsToPID(pInfo.NwNameSpace)
		if err != nil {
			logger.Errorf("Failed to fetch pid from netns %s: %v", pInfo.NwNameSpace,
				err)
		} else {
			// respond with success
			resp.IPAddress = utPodIP
			resp.EndpointID = pInfo.InfraContainerID
			return resp, nil
		}
	}
	logger.Errorf("Failed pod %v", pInfo)
	return resp, fmt.Errorf("Failed to add pod")
}
开发者ID:rtrentin73,项目名称:netplugin,代码行数:33,代码来源:k8s_cni_test.go


示例3: addPod

// addPod is the handler for pod additions
func addPod(r *http.Request) (interface{}, error) {

	resp := cniapi.RspAddPod{}

	logEvent("add pod")

	content, err := ioutil.ReadAll(r.Body)
	if err != nil {
		log.Errorf("Failed to read request: %v", err)
		return resp, err
	}

	pInfo := cniapi.CNIPodAttr{}
	if err := json.Unmarshal(content, &pInfo); err != nil {
		return resp, err
	}

	// Get labels from the kube api server
	epReq, err := getEPSpec(&pInfo)
	if err != nil {
		log.Errorf("Error getting labels. Err: %v", err)
		return resp, err
	}

	ep, err := createEP(epReq)
	if err != nil {
		log.Errorf("Error creating ep. Err: %v", err)
		return resp, err
	}

	// convert netns to pid that netlink needs
	pid, err := nsToPID(pInfo.NwNameSpace)
	if err != nil {
		return resp, err
	}

	// Set interface attributes for the new port
	err = setIfAttrs(pid, ep.PortName, ep.IPAddress, pInfo.IntfName)
	if err != nil {
		log.Errorf("Error setting interface attributes. Err: %v", err)
		return resp, err
	}

	// Set default gateway
	err = setDefGw(pid, ep.Gateway, pInfo.IntfName)
	if err != nil {
		log.Errorf("Error setting default gateway. Err: %v", err)
		return resp, err
	}

	resp.IPAddress = ep.IPAddress
	resp.EndpointID = pInfo.InfraContainerID
	return resp, nil
}
开发者ID:vvb,项目名称:netplugin,代码行数:55,代码来源:driver.go


示例4: stubDeletePod

// stubDeletePod is the handler for testing pod additions
func stubDeletePod(r *http.Request) (interface{}, error) {

	resp := cniapi.RspAddPod{}

	content, err := ioutil.ReadAll(r.Body)
	if err != nil {
		logger.Errorf("Failed to read request: %v", err)
		return resp, err
	}

	pInfo := cniapi.CNIPodAttr{}
	if err := json.Unmarshal(content, &pInfo); err != nil {
		return resp, err
	}

	// verify pod attributes are as expected.
	if pInfo.Name == "utPod" && pInfo.K8sNameSpace == "utK8sNS" &&
		pInfo.InfraContainerID != "" && pInfo.IntfName != "" {
		resp.EndpointID = pInfo.InfraContainerID
		return resp, nil
	}
	logger.Errorf("Failed pod %v", pInfo)
	return resp, fmt.Errorf("Failed to delete pod")
}
开发者ID:rtrentin73,项目名称:netplugin,代码行数:25,代码来源:k8s_cni_test.go


示例5: addPod

// addPod is the handler for pod additions
func addPod(r *http.Request) (interface{}, error) {

	resp := cniapi.RspAddPod{}

	logEvent("add pod")

	content, err := ioutil.ReadAll(r.Body)
	if err != nil {
		log.Errorf("Failed to read request: %v", err)
		return resp, err
	}

	pInfo := cniapi.CNIPodAttr{}
	if err := json.Unmarshal(content, &pInfo); err != nil {
		return resp, err
	}

	// Get labels from the kube api server
	epReq, err := getEPSpec(&pInfo)
	if err != nil {
		log.Errorf("Error getting labels. Err: %v", err)
		setErrorResp(&resp, "Error getting labels", err)
		return resp, err
	}

	ep, err := createEP(epReq)
	if err != nil {
		log.Errorf("Error creating ep. Err: %v", err)
		setErrorResp(&resp, "Error creating EP", err)
		return resp, err
	}

	// convert netns to pid that netlink needs
	pid, err := nsToPID(pInfo.NwNameSpace)
	if err != nil {
		log.Errorf("Error moving to netns. Err: %v", err)
		setErrorResp(&resp, "Error moving to netns", err)
		return resp, err
	}

	// Set interface attributes for the new port
	err = setIfAttrs(pid, ep.PortName, ep.IPAddress, pInfo.IntfName)
	if err != nil {
		log.Errorf("Error setting interface attributes. Err: %v", err)
		setErrorResp(&resp, "Error setting interface attributes", err)
		return resp, err
	}

	// if Gateway is not specified on the nw, use the host gateway
	gwIntf := pInfo.IntfName
	gw := ep.Gateway
	if gw == "" {
		hostIf := netutils.GetHostIntfName(ep.PortName)
		hostIP, _ := netutils.HostIfToIP(hostIf)
		err = netPlugin.CreateHostAccPort(hostIf, ep.IPAddress, hostIP)
		if err != nil {
			log.Errorf("Error setting host access. Err: %v", err)
		} else {
			err = setIfAttrs(pid, hostIf, hostIP, "host1")
			if err != nil {
				log.Errorf("Move to pid %d failed", pid)
			} else {
				gw = hostGWIP
				gwIntf = "host1"
				// make sure service subnet points to eth0
				svcSubnet := contivK8Config.SvcSubnet
				addStaticRoute(pid, svcSubnet, pInfo.IntfName)
			}
		}

	}

	// Set default gateway
	err = setDefGw(pid, gw, gwIntf)
	if err != nil {
		log.Errorf("Error setting default gateway. Err: %v", err)
		setErrorResp(&resp, "Error setting default gateway", err)
		return resp, err
	}

	resp.Result = 0
	resp.IPAddress = ep.IPAddress
	resp.EndpointID = pInfo.InfraContainerID
	return resp, nil
}
开发者ID:abhinandanpb,项目名称:netplugin,代码行数:86,代码来源:driver.go


示例6: setErrorResp

func setErrorResp(resp *cniapi.RspAddPod, msg string, err error) {
	resp.Result = 1
	resp.ErrMsg = msg
	resp.ErrInfo = fmt.Sprintf("Err: %v", err)
}
开发者ID:abhinandanpb,项目名称:netplugin,代码行数:5,代码来源:driver.go



注:本文中的github.com/contiv/netplugin/mgmtfn/k8splugin/cniapi.RspAddPod类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang gstate.Cfg类代码示例发布时间:2022-05-23
下一篇:
Golang gstate.Cfg类代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap