Added code to prevent deletion of active fn pod (#1724)
Co-authored-by: Vishal <vishal-biyani@users.noreply.github.com>
This commit is contained in:
@@ -136,7 +136,7 @@ func (fsc *FunctionServiceCache) service() {
|
||||
}
|
||||
fsc.logger.Info("function service cache", zap.Int("item_count", len(funcCopy)), zap.Strings("cache", info))
|
||||
case LISTOLDPOOL:
|
||||
fscs := fsc.connFunctionCache.ListValue()
|
||||
fscs := fsc.connFunctionCache.ListAvailableValue()
|
||||
funcObjects := make([]*FuncSvc, 0)
|
||||
for _, funcSvc := range fscs {
|
||||
fsvc := funcSvc.(*FuncSvc)
|
||||
|
||||
@@ -28,7 +28,7 @@ type requestType int
|
||||
|
||||
const (
|
||||
getValue requestType = iota
|
||||
listValue
|
||||
listAvailableValue
|
||||
getTotalAvailable
|
||||
setValue
|
||||
markAvailable
|
||||
@@ -99,11 +99,13 @@ func (c *Cache) service() {
|
||||
resp.error = ferror.MakeError(ferror.ErrorNotFound, fmt.Sprintf("funtion '%v' No inactive function found", req.function))
|
||||
}
|
||||
req.responseChannel <- resp
|
||||
case listValue:
|
||||
case listAvailableValue:
|
||||
vals := make([]interface{}, 0)
|
||||
for _, values := range c.cache {
|
||||
for _, value := range values {
|
||||
vals = append(vals, value.val)
|
||||
if !value.isActive {
|
||||
vals = append(vals, value.val)
|
||||
}
|
||||
}
|
||||
}
|
||||
resp.allValues = vals
|
||||
@@ -159,11 +161,11 @@ func (c *Cache) GetValue(function interface{}) (interface{}, error) {
|
||||
return resp.value, resp.error
|
||||
}
|
||||
|
||||
// ListValue returns a list of the function services stored in the Cache
|
||||
func (c *Cache) ListValue() []interface{} {
|
||||
// ListAvailableValue returns a list of the available function services stored in the Cache
|
||||
func (c *Cache) ListAvailableValue() []interface{} {
|
||||
respChannel := make(chan *response)
|
||||
c.requestChannel <- &request{
|
||||
requestType: listValue,
|
||||
requestType: listAvailableValue,
|
||||
responseChannel: respChannel,
|
||||
}
|
||||
resp := <-respChannel
|
||||
|
||||
@@ -21,9 +21,9 @@ func TestPoolCache(t *testing.T) {
|
||||
|
||||
c.SetValue("func2", "ip22", "value22")
|
||||
|
||||
cc := c.ListValue()
|
||||
if len(cc) != 3 {
|
||||
log.Panicf("expected 2 items")
|
||||
cc := c.ListAvailableValue()
|
||||
if len(cc) != 0 {
|
||||
log.Panicf("expected 0 available items")
|
||||
}
|
||||
active := c.GetTotalAvailable("func2")
|
||||
if active != 2 {
|
||||
@@ -33,7 +33,11 @@ func TestPoolCache(t *testing.T) {
|
||||
c.DeleteValue("func2", "ip2")
|
||||
|
||||
c.MarkAvailable("func", "ip")
|
||||
cc = c.ListAvailableValue()
|
||||
|
||||
if len(cc) != 1 {
|
||||
log.Panic("expected 1 available items, received", len(cc))
|
||||
}
|
||||
_, err := c.GetValue("func")
|
||||
checkErr(err)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user