本文整理匯總了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)
}
}
}
示例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
}