k3s/agent/proxy/proxy.go

36 lines
679 B
Go
Raw Normal View History

2019-01-01 08:23:01 +00:00
package proxy
import (
"crypto/tls"
"net/http"
"github.com/pkg/errors"
"github.com/rancher/norman/pkg/proxy"
"github.com/rancher/rio/agent/config"
"github.com/sirupsen/logrus"
)
func Run(config *config.NodeConfig) error {
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
}