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


Golang api.ServicePort類代碼示例

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


在下文中一共展示了ServicePort類的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: addIngress

// addIngress adds an ingress to the loadbalancer controllers ingress store. If
// a nodePortManager is supplied, it also adds all backends to the service store
// with a nodePort acquired through it.
func addIngress(lbc *LoadBalancerController, ing *extensions.Ingress, pm *nodePortManager) {
	lbc.ingLister.Store.Add(ing)
	if pm == nil {
		return
	}
	for _, rule := range ing.Spec.Rules {
		for _, path := range rule.HTTP.Paths {
			svc := &api.Service{
				ObjectMeta: api.ObjectMeta{
					Name:      path.Backend.ServiceName,
					Namespace: ing.Namespace,
				},
			}
			var svcPort api.ServicePort
			switch path.Backend.ServicePort.Type {
			case intstr.Int:
				svcPort = api.ServicePort{Port: path.Backend.ServicePort.IntVal}
			default:
				svcPort = api.ServicePort{Name: path.Backend.ServicePort.StrVal}
			}
			svcPort.NodePort = int32(pm.getNodePort(path.Backend.ServiceName))
			svc.Spec.Ports = []api.ServicePort{svcPort}
			lbc.svcLister.Store.Add(svc)
		}
	}
}
開發者ID:spxtr,項目名稱:contrib,代碼行數:29,代碼來源:controller_test.go

示例2: ServicePorts

func ServicePorts(srvcPorts []interface{}) []api.ServicePort {
	if len(srvcPorts) == 0 {
		return nil
	}

	var ports []api.ServicePort

	for _, p := range srvcPorts {
		userPort := p.(map[string]interface{})
		srvcPort := api.ServicePort{}

		if _, ok := userPort["name"]; ok {
			srvcPort.Name = userPort["name"].(string)
		}

		if _, ok := userPort["protocol"]; ok {
			srvcPort.Protocol = api.Protocol(userPort["protocol"].(string))
		}

		if _, ok := userPort["port"]; ok {
			srvcPort.Port = userPort["port"].(int)
		}

		if _, ok := userPort["node_port"]; ok {
			srvcPort.NodePort = userPort["node_port"].(int)
		}

		ports = append(ports, srvcPort)
	}

	return ports
}
開發者ID:brendangibat,項目名稱:terraform-provider-kubernetes,代碼行數:32,代碼來源:service.go


注:本文中的k8s/io/kubernetes/pkg/api.ServicePort類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。