示例#1
0
// 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)
		}
	}
}
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
}