Remove dns from nginx. Use upstreams for default backend service
This commit is contained in:
parent
9b142b56f8
commit
28f9cb0b2b
15 changed files with 173 additions and 225 deletions
126
controllers/nginx-third-party/utils.go
vendored
126
controllers/nginx-third-party/utils.go
vendored
|
|
@ -102,79 +102,93 @@ func getLBDetails(kubeClient *unversioned.Client) (rc *lbInfo, err error) {
|
|||
}
|
||||
}
|
||||
|
||||
func getService(kubeClient *unversioned.Client, name string) (nginx.Service, error) {
|
||||
func isValidService(kubeClient *unversioned.Client, name string) error {
|
||||
if name == "" {
|
||||
return nginx.Service{}, fmt.Errorf("Empty string is not a valid service name")
|
||||
return fmt.Errorf("Empty string is not a valid service name")
|
||||
}
|
||||
|
||||
parts := strings.Split(name, "/")
|
||||
if len(parts) != 2 {
|
||||
glog.Fatalf("Please check the service format (namespace/name) in service %v", name)
|
||||
return fmt.Errorf("Invalid name format (namespace/name) in service '%v'", name)
|
||||
}
|
||||
|
||||
defaultPort, err := getServicePorts(kubeClient, parts[0], parts[1])
|
||||
if err != nil {
|
||||
return nginx.Service{}, fmt.Errorf("Error obtaining service %v: %v", name, err)
|
||||
}
|
||||
|
||||
return nginx.Service{
|
||||
ServiceName: parts[1],
|
||||
ServicePort: defaultPort[0], //TODO: which port?
|
||||
Namespace: parts[0],
|
||||
}, nil
|
||||
_, err = kubeClient.Services(parts[0]).Get(parts[1])
|
||||
return err
|
||||
}
|
||||
|
||||
// getServicePorts returns the ports defined in a service spec
|
||||
func getServicePorts(kubeClient *unversioned.Client, ns, name string) (ports []string, err error) {
|
||||
var svc *api.Service
|
||||
glog.Infof("Checking service %v/%v", ns, name)
|
||||
svc, err = kubeClient.Services(ns).Get(name)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
// func getService(kubeClient *unversioned.Client, name string) (nginx.Service, error) {
|
||||
// if name == "" {
|
||||
// return nginx.Service{}, fmt.Errorf("Empty string is not a valid service name")
|
||||
// }
|
||||
|
||||
for _, p := range svc.Spec.Ports {
|
||||
if p.Port != 0 {
|
||||
ports = append(ports, strconv.Itoa(p.Port))
|
||||
break
|
||||
}
|
||||
}
|
||||
// parts := strings.Split(name, "/")
|
||||
// if len(parts) != 2 {
|
||||
// glog.Fatalf("Please check the service format (namespace/name) in service %v", name)
|
||||
// }
|
||||
|
||||
glog.Infof("Ports for %v/%v : %v", ns, name, ports)
|
||||
// defaultPort, err := getServicePorts(kubeClient, parts[0], parts[1])
|
||||
// if err != nil {
|
||||
// return nginx.Service{}, fmt.Errorf("Error obtaining service %v: %v", name, err)
|
||||
// }
|
||||
|
||||
return
|
||||
}
|
||||
// return nginx.Service{
|
||||
// ServiceName: parts[1],
|
||||
// ServicePort: defaultPort[0], //TODO: which port?
|
||||
// Namespace: parts[0],
|
||||
// }, nil
|
||||
// }
|
||||
|
||||
func getTCPServices(kubeClient *unversioned.Client, tcpServices string) []nginx.Service {
|
||||
svcs := []nginx.Service{}
|
||||
for _, svc := range strings.Split(tcpServices, ",") {
|
||||
if svc == "" {
|
||||
continue
|
||||
}
|
||||
// // getServicePorts returns the ports defined in a service spec
|
||||
// func getServicePorts(kubeClient *unversioned.Client, ns, name string) (ports []string, err error) {
|
||||
// var svc *api.Service
|
||||
// glog.Infof("Checking service %v/%v", ns, name)
|
||||
// svc, err = kubeClient.Services(ns).Get(name)
|
||||
// if err != nil {
|
||||
// return
|
||||
// }
|
||||
|
||||
namePort := strings.Split(svc, ":")
|
||||
if len(namePort) == 2 {
|
||||
tcpSvc, err := getService(kubeClient, namePort[0])
|
||||
if err != nil {
|
||||
glog.Errorf("%s", err)
|
||||
continue
|
||||
}
|
||||
// for _, p := range svc.Spec.Ports {
|
||||
// if p.Port != 0 {
|
||||
// ports = append(ports, strconv.Itoa(p.Port))
|
||||
// break
|
||||
// }
|
||||
// }
|
||||
|
||||
// the exposed TCP service cannot use 80 or 443 as ports
|
||||
if namePort[1] == httpPort || namePort[1] == httpsPort {
|
||||
glog.Errorf("The TCP service %v cannot use ports 80 or 443 (it creates a conflict with nginx)", svc)
|
||||
continue
|
||||
}
|
||||
// glog.Infof("Ports for %v/%v : %v", ns, name, ports)
|
||||
|
||||
tcpSvc.ExposedPort = namePort[1]
|
||||
svcs = append(svcs, tcpSvc)
|
||||
} else {
|
||||
glog.Errorf("TCP services should take the form namespace/name:port not %v from %v", namePort, svc)
|
||||
}
|
||||
}
|
||||
// return
|
||||
// }
|
||||
|
||||
return svcs
|
||||
}
|
||||
// func getTCPServices(kubeClient *unversioned.Client, tcpServices string) []nginx.Service {
|
||||
// svcs := []nginx.Service{}
|
||||
// for _, svc := range strings.Split(tcpServices, ",") {
|
||||
// if svc == "" {
|
||||
// continue
|
||||
// }
|
||||
|
||||
// namePort := strings.Split(svc, ":")
|
||||
// if len(namePort) == 2 {
|
||||
// tcpSvc, err := getService(kubeClient, namePort[0])
|
||||
// if err != nil {
|
||||
// glog.Errorf("%s", err)
|
||||
// continue
|
||||
// }
|
||||
|
||||
// // the exposed TCP service cannot use 80 or 443 as ports
|
||||
// if namePort[1] == httpPort || namePort[1] == httpsPort {
|
||||
// glog.Errorf("The TCP service %v cannot use ports 80 or 443 (it creates a conflict with nginx)", svc)
|
||||
// continue
|
||||
// }
|
||||
|
||||
// tcpSvc.ExposedPort = namePort[1]
|
||||
// svcs = append(svcs, tcpSvc)
|
||||
// } else {
|
||||
// glog.Errorf("TCP services should take the form namespace/name:port not %v from %v", namePort, svc)
|
||||
// }
|
||||
// }
|
||||
|
||||
// return svcs
|
||||
// }
|
||||
|
||||
func isHostValid(host string, cns []string) bool {
|
||||
for _, cn := range cns {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue