X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/e95bf5c03b1b956b9a7196c2a6c357e79f6eb60e..3a35c1dca48cf1470690be5c021046ac87faaa21:/lib/controller/localdb/conn.go diff --git a/lib/controller/localdb/conn.go b/lib/controller/localdb/conn.go index 5a3faa7279..6ab9e1450b 100644 --- a/lib/controller/localdb/conn.go +++ b/lib/controller/localdb/conn.go @@ -8,6 +8,7 @@ import ( "context" "encoding/json" "fmt" + "net" "net/http" "os" "sync" @@ -19,6 +20,7 @@ import ( "git.arvados.org/arvados.git/sdk/go/ctxlog" "git.arvados.org/arvados.git/sdk/go/httpserver" "github.com/hashicorp/yamux" + "github.com/jmoiron/sqlx" "github.com/sirupsen/logrus" ) @@ -27,6 +29,7 @@ type railsProxy = rpc.Conn type Conn struct { cluster *arvados.Cluster *railsProxy // handles API methods that aren't defined on Conn itself + getdb func(context.Context) (*sqlx.DB, error) vocabularyCache *arvados.Vocabulary vocabularyFileModTime time.Time lastVocabularyRefreshCheck time.Time @@ -37,16 +40,21 @@ type Conn struct { activeUsers map[string]bool activeUsersLock sync.Mutex activeUsersReset time.Time + + wantContainerPriorityUpdate chan struct{} } -func NewConn(cluster *arvados.Cluster) *Conn { +func NewConn(bgCtx context.Context, cluster *arvados.Cluster, getdb func(context.Context) (*sqlx.DB, error)) *Conn { railsProxy := railsproxy.NewConn(cluster) railsProxy.RedactHostInErrors = true conn := Conn{ - cluster: cluster, - railsProxy: railsProxy, + cluster: cluster, + railsProxy: railsProxy, + getdb: getdb, + wantContainerPriorityUpdate: make(chan struct{}, 1), } conn.loginController = chooseLoginController(cluster, &conn) + go conn.runContainerPriorityUpdateThread(bgCtx) return &conn } @@ -165,6 +173,26 @@ func (conn *Conn) UserAuthenticate(ctx context.Context, opts arvados.UserAuthent return conn.loginController.UserAuthenticate(ctx, opts) } +var privateNetworks = func() (nets []*net.IPNet) { + for _, s := range []string{ + "127.0.0.0/8", + "10.0.0.0/8", + "172.16.0.0/12", + "192.168.0.0/16", + "169.254.0.0/16", + "::1/128", + "fe80::/10", + "fc00::/7", + } { + _, n, err := net.ParseCIDR(s) + if err != nil { + panic(fmt.Sprintf("privateNetworks: %q: %s", s, err)) + } + nets = append(nets, n) + } + return +}() + func httpErrorf(code int, format string, args ...interface{}) error { return httpserver.ErrorWithStatus(fmt.Errorf(format, args...), code) }