Cleanup deleted pools, partly implemented
This commit is contained in:
+29
-2
@@ -26,6 +26,13 @@ import (
|
|||||||
"github.com/fission/fission/controller/client"
|
"github.com/fission/fission/controller/client"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type requestType int
|
||||||
|
|
||||||
|
const (
|
||||||
|
GET_POOL requestType = iota
|
||||||
|
CLEANUP_POOLS
|
||||||
|
)
|
||||||
|
|
||||||
type (
|
type (
|
||||||
GenericPoolManager struct {
|
GenericPoolManager struct {
|
||||||
pools map[fission.Environment]*GenericPool
|
pools map[fission.Environment]*GenericPool
|
||||||
@@ -38,7 +45,9 @@ type (
|
|||||||
requestChannel chan *request
|
requestChannel chan *request
|
||||||
}
|
}
|
||||||
request struct {
|
request struct {
|
||||||
|
requestType
|
||||||
env *fission.Environment
|
env *fission.Environment
|
||||||
|
currentEnvs []fission.Environment
|
||||||
responseChannel chan *response
|
responseChannel chan *response
|
||||||
}
|
}
|
||||||
response struct {
|
response struct {
|
||||||
@@ -72,8 +81,9 @@ func MakeGenericPoolManager(
|
|||||||
|
|
||||||
func (gpm *GenericPoolManager) service() {
|
func (gpm *GenericPoolManager) service() {
|
||||||
for {
|
for {
|
||||||
select {
|
req := <-gpm.requestChannel
|
||||||
case req := <-gpm.requestChannel:
|
switch req.requestType {
|
||||||
|
case GET_POOL:
|
||||||
var err error
|
var err error
|
||||||
pool, ok := gpm.pools[*req.env]
|
pool, ok := gpm.pools[*req.env]
|
||||||
if !ok {
|
if !ok {
|
||||||
@@ -88,6 +98,18 @@ func (gpm *GenericPoolManager) service() {
|
|||||||
gpm.pools[*req.env] = pool
|
gpm.pools[*req.env] = pool
|
||||||
}
|
}
|
||||||
req.responseChannel <- &response{pool: pool}
|
req.responseChannel <- &response{pool: pool}
|
||||||
|
case CLEANUP_POOLS:
|
||||||
|
uids := make(map[string]bool)
|
||||||
|
for _, env := range req.currentEnvs {
|
||||||
|
uids[env.Metadata.Uid] = true
|
||||||
|
}
|
||||||
|
for env, pool := range gpm.pools {
|
||||||
|
_, ok := uids[env.Metadata.Uid]
|
||||||
|
if !ok {
|
||||||
|
// Env no longer exists -- remove from gpm.pools
|
||||||
|
// map and delete the pool
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -115,15 +137,20 @@ func (gpm *GenericPoolManager) eagerPoolCreator() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
envUids := make(map[string]bool)
|
||||||
// Create pools for all envs. TODO: we should make this a bit less eager, only
|
// Create pools for all envs. TODO: we should make this a bit less eager, only
|
||||||
// creating pools for envs that are actually used by functions. Also we might want
|
// creating pools for envs that are actually used by functions. Also we might want
|
||||||
// to keep these eagerly created pools smaller than the ones created when there are
|
// to keep these eagerly created pools smaller than the ones created when there are
|
||||||
// actual function calls.
|
// actual function calls.
|
||||||
for _, env := range envs {
|
for _, env := range envs {
|
||||||
|
envUids[env.Metadata.Uid] = true
|
||||||
_, err := gpm.GetPool(&env)
|
_, err := gpm.GetPool(&env)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("eager-create pool failed: %v", err)
|
log.Printf("eager-create pool failed: %v", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Clean up pools whose env was deleted
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user