本文整理汇总了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
}