mirror of
https://github.com/k3s-io/k3s.git
synced 2024-06-07 19:41:36 +00:00
36 lines
679 B
Go
36 lines
679 B
Go
|
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
|
||
|
}
|