diff --git a/CHANGELOG.md b/CHANGELOG.md index efbdab70..6d063277 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ ## In development +- Fixed GC goroutine; make GC interval configurable [#63](https://github.com/nre-learning/syringe/pull/63/files) + +## 0.2.0 - January 24, 2019 + - Simplified authentication by using consistent credentials, statically [#40](https://github.com/nre-learning/syringe/pull/40) - Serve lab guide directly from lesson definition API [#41](https://github.com/nre-learning/syringe/pull/41) - Simplify and improve safety of in-memory state model [#42](https://github.com/nre-learning/syringe/pull/42) diff --git a/config/config.go b/config/config.go index f9d8f065..04045ede 100644 --- a/config/config.go +++ b/config/config.go @@ -17,6 +17,7 @@ type SyringeConfig struct { HealthCheckInterval int TSDBExportInterval int TSDBEnabled bool + GCInterval int LessonRepoRemote string LessonRepoBranch string @@ -94,6 +95,13 @@ func LoadConfigVars() (*SyringeConfig, error) { config.LessonRepoDir = dir } + gc, err := strconv.Atoi(os.Getenv("SYRINGE_GC_INTERVAL")) + if gc == 0 || err != nil { + config.GCInterval = 30 + } else { + config.GCInterval = gc + } + return &config, nil } diff --git a/scheduler/namespaces.go b/scheduler/namespaces.go index 8ca0ea9d..6209f986 100644 --- a/scheduler/namespaces.go +++ b/scheduler/namespaces.go @@ -130,7 +130,7 @@ func (ls *LessonScheduler) createNamespace(req *LessonScheduleRequest) (*corev1. Labels: map[string]string{ "lessonId": fmt.Sprintf("%d", req.LessonDef.LessonId), "syringeManaged": "yes", - "name": nsName, + "name": nsName, "syringeTier": ls.SyringeConfig.Tier, "lastAccessed": strconv.Itoa(int(time.Now().Unix())), "created": strconv.Itoa(int(time.Now().Unix())), @@ -185,7 +185,8 @@ func (ls *LessonScheduler) purgeOldLessons() ([]string, error) { panic(err) } lastAccessed := time.Unix(i, 0) - if time.Since(lastAccessed) < 30*time.Minute { + + if time.Since(lastAccessed) < time.Duration(ls.SyringeConfig.GCInterval)*time.Minute { continue } @@ -205,14 +206,15 @@ func (ls *LessonScheduler) purgeOldLessons() ([]string, error) { return []string{}, nil } - log.Warnf("Garbage-collecting %d old lessons", len(oldNameSpaces)) + log.Infof("Garbage-collecting %d old lessons", len(oldNameSpaces)) + log.Debug(oldNameSpaces) var wg sync.WaitGroup wg.Add(len(oldNameSpaces)) for n := range oldNameSpaces { - go func() { + go func(ns string) { defer wg.Done() - ls.deleteNamespace(oldNameSpaces[n]) - }() + ls.deleteNamespace(ns) + }(oldNameSpaces[n]) } wg.Wait() log.Infof("Finished garbage-collecting %d old lessons", len(oldNameSpaces))