代码拉取完成,页面将自动刷新
package clusterrouter
import (
"net/http"
"sync"
"github.com/docker/docker/pkg/locker"
"github.com/rancher/rancher/pkg/clusterrouter/proxy"
"github.com/rancher/types/apis/management.cattle.io/v3"
"github.com/rancher/types/config/dialer"
"k8s.io/client-go/rest"
)
type factory struct {
dialerFactory dialer.Factory
clusterLookup ClusterLookup
clusters sync.Map
serverLock *locker.Locker
servers sync.Map
localConfig *rest.Config
}
func newFactory(localConfig *rest.Config, dialer dialer.Factory, lookup ClusterLookup) *factory {
return &factory{
dialerFactory: dialer,
serverLock: locker.New(),
clusterLookup: lookup,
localConfig: localConfig,
}
}
func (s *factory) lookupCluster(clusterID string) (*v3.Cluster, http.Handler) {
srv, ok := s.servers.Load(clusterID)
if ok {
if cluster, ok := s.clusters.Load(clusterID); ok {
return cluster.(*v3.Cluster), srv.(server).Handler()
}
}
return nil, nil
}
func (s *factory) get(req *http.Request) (*v3.Cluster, http.Handler, error) {
cluster, err := s.clusterLookup.Lookup(req)
if err != nil || cluster == nil {
return nil, nil, err
}
clusterID := cluster.Name
if newCluster, handler := s.lookupCluster(clusterID); newCluster != nil {
return newCluster, handler, nil
}
s.serverLock.Lock("cluster." + clusterID)
defer s.serverLock.Unlock("cluster." + clusterID)
if newCluster, handler := s.lookupCluster(clusterID); newCluster != nil {
return newCluster, handler, nil
}
var srv interface{}
srv, err = s.newServer(cluster)
if err != nil || srv == nil {
return nil, nil, err
}
srv, _ = s.servers.LoadOrStore(cluster.Name, srv)
s.clusters.LoadOrStore(cluster.Name, cluster)
return cluster, srv.(server).Handler(), nil
}
func (s *factory) newServer(c *v3.Cluster) (server, error) {
return proxy.New(s.localConfig, c, s.dialerFactory)
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。