Remove proxy from kubernetes file (#2668)
Signed-off-by: Yong Tang <yong.tang.github@outlook.com>
This commit is contained in:
parent
b67e4c47c2
commit
162c3dd95d
3 changed files with 0 additions and 82 deletions
|
@ -1,75 +0,0 @@
|
||||||
package kubernetes
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"io"
|
|
||||||
"net"
|
|
||||||
"net/http"
|
|
||||||
|
|
||||||
"github.com/coredns/coredns/plugin/pkg/healthcheck"
|
|
||||||
)
|
|
||||||
|
|
||||||
type proxyHandler struct {
|
|
||||||
healthcheck.HealthCheck
|
|
||||||
}
|
|
||||||
|
|
||||||
type apiProxy struct {
|
|
||||||
http.Server
|
|
||||||
listener net.Listener
|
|
||||||
handler proxyHandler
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p *proxyHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|
||||||
upstream := p.Select()
|
|
||||||
network := "tcp"
|
|
||||||
address := upstream.Name
|
|
||||||
|
|
||||||
d, err := net.Dial(network, address)
|
|
||||||
if err != nil {
|
|
||||||
log.Errorf("Unable to establish connection to upstream %s://%s: %s", network, address, err)
|
|
||||||
http.Error(w, fmt.Sprintf("Unable to establish connection to upstream %s://%s: %s", network, address, err), 500)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
hj, ok := w.(http.Hijacker)
|
|
||||||
if !ok {
|
|
||||||
log.Error("Unable to establish connection: no hijacker")
|
|
||||||
http.Error(w, "Unable to establish connection: no hijacker", 500)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
nc, _, err := hj.Hijack()
|
|
||||||
if err != nil {
|
|
||||||
log.Errorf("Unable to hijack connection: %s", err)
|
|
||||||
http.Error(w, fmt.Sprintf("Unable to hijack connection: %s", err), 500)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
defer nc.Close()
|
|
||||||
defer d.Close()
|
|
||||||
|
|
||||||
err = r.Write(d)
|
|
||||||
if err != nil {
|
|
||||||
log.Errorf("Unable to copy connection to upstream %s://%s: %s", network, address, err)
|
|
||||||
http.Error(w, fmt.Sprintf("Unable to copy connection to upstream %s://%s: %s", network, address, err), 500)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
errChan := make(chan error, 2)
|
|
||||||
cp := func(dst io.Writer, src io.Reader) {
|
|
||||||
_, err := io.Copy(dst, src)
|
|
||||||
errChan <- err
|
|
||||||
}
|
|
||||||
go cp(d, nc)
|
|
||||||
go cp(nc, d)
|
|
||||||
<-errChan
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p *apiProxy) Run() {
|
|
||||||
p.handler.Start()
|
|
||||||
go func() {
|
|
||||||
p.Serve(p.listener)
|
|
||||||
}()
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p *apiProxy) Stop() {
|
|
||||||
p.handler.Stop()
|
|
||||||
p.listener.Close()
|
|
||||||
}
|
|
|
@ -31,7 +31,6 @@ type Kubernetes struct {
|
||||||
Zones []string
|
Zones []string
|
||||||
Upstream *upstream.Upstream
|
Upstream *upstream.Upstream
|
||||||
APIServerList []string
|
APIServerList []string
|
||||||
APIProxy *apiProxy
|
|
||||||
APICertAuth string
|
APICertAuth string
|
||||||
APIClientCert string
|
APIClientCert string
|
||||||
APIClientKey string
|
APIClientKey string
|
||||||
|
|
|
@ -80,9 +80,6 @@ func setup(c *caddy.Controller) error {
|
||||||
func (k *Kubernetes) RegisterKubeCache(c *caddy.Controller) {
|
func (k *Kubernetes) RegisterKubeCache(c *caddy.Controller) {
|
||||||
c.OnStartup(func() error {
|
c.OnStartup(func() error {
|
||||||
go k.APIConn.Run()
|
go k.APIConn.Run()
|
||||||
if k.APIProxy != nil {
|
|
||||||
k.APIProxy.Run()
|
|
||||||
}
|
|
||||||
|
|
||||||
timeout := time.After(5 * time.Second)
|
timeout := time.After(5 * time.Second)
|
||||||
ticker := time.NewTicker(100 * time.Millisecond)
|
ticker := time.NewTicker(100 * time.Millisecond)
|
||||||
|
@ -99,9 +96,6 @@ func (k *Kubernetes) RegisterKubeCache(c *caddy.Controller) {
|
||||||
})
|
})
|
||||||
|
|
||||||
c.OnShutdown(func() error {
|
c.OnShutdown(func() error {
|
||||||
if k.APIProxy != nil {
|
|
||||||
k.APIProxy.Stop()
|
|
||||||
}
|
|
||||||
return k.APIConn.Stop()
|
return k.APIConn.Stop()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue