2019-01-01 08:23:01 +00:00
|
|
|
package proxy
|
|
|
|
|
|
|
|
import (
|
|
|
|
"crypto/tls"
|
|
|
|
"net/http"
|
|
|
|
|
|
|
|
"github.com/pkg/errors"
|
2019-01-09 16:54:15 +00:00
|
|
|
"github.com/rancher/k3s/pkg/daemons/config"
|
2019-05-09 22:05:51 +00:00
|
|
|
"github.com/rancher/k3s/pkg/proxy"
|
2019-01-01 08:23:01 +00:00
|
|
|
"github.com/sirupsen/logrus"
|
|
|
|
)
|
|
|
|
|
2019-01-09 16:54:15 +00:00
|
|
|
func Run(config *config.Node) error {
|
2019-01-01 08:23:01 +00:00
|
|
|
proxy, err := proxy.NewSimpleProxy(config.ServerAddress, config.CACerts, true)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
listener, err := tls.Listen("tcp", config.LocalAddress, &tls.Config{
|
|
|
|
Certificates: []tls.Certificate{
|
|
|
|
*config.Certificate,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
return errors.Wrap(err, "Failed to start tls listener")
|
|
|
|
}
|
|
|
|
|
|
|
|
go func() {
|
|
|
|
err := http.Serve(listener, proxy)
|
|
|
|
logrus.Fatalf("TLS proxy stopped: %v", err)
|
|
|
|
}()
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|