Skip to content

Commit

Permalink
Always set status to RollingUpdate if operation exists (#93)
Browse files Browse the repository at this point in the history
* Always set status to RollingUpdate if operation exists

* Fix tests

* Log state transition

* Add test
  • Loading branch information
victor-carvalho committed Jul 10, 2020
1 parent 82080ea commit 1e7e89b
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 13 deletions.
2 changes: 2 additions & 0 deletions helm/charts/maestro-postgres/templates/maestro-postgres.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ spec:
value: maestro
- name: POSTGRES_DB
value: maestro
- name: POSTGRES_HOST_AUTH_METHOD
value: trust
livenessProbe:
exec:
command:
Expand Down
2 changes: 1 addition & 1 deletion helm/charts/maestro/Chart.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: maestro
home: https://github.com/topfreegames/maestro
description: Maestro api and worker
version: 7.2.2
version: 9.5.1
maintainers:
- name: TFGCo
email: backend@tfgco.com
2 changes: 1 addition & 1 deletion metadata/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
package metadata

//Version of Maestro
var Version = "9.4.1"
var Version = "9.5.2"

//KubeVersion is the desired Kubernetes version
var KubeVersion = "v1.13.9"
28 changes: 17 additions & 11 deletions watcher/watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -1262,13 +1262,6 @@ func (w *Watcher) EnsureCorrectRooms() error {

invalidPods := append(incorrectPods, unregisteredPods...)

if len(invalidPods) <= 0 {
// delete invalidRooms key for safety
models.RemoveInvalidRoomsKey(w.RedisClient.Trace(ctx), w.MetricsReporter, w.SchedulerName)
logger.Debug("no invalid pods to replace")
return nil
}

// get operation manager if it exists.
// It won't exist if not in a UpdateSchedulerConfig operation
operationManager, err := w.getOperation(ctx, logger)
Expand All @@ -1289,11 +1282,17 @@ func (w *Watcher) EnsureCorrectRooms() error {
invalidPods = incorrectPods

if status["description"] != models.OpManagerRollingUpdate {
err = models.SetInvalidRooms(w.RedisClient.Trace(ctx), w.MetricsReporter, w.SchedulerName, incorrectPodNames)
if err != nil {
logger.WithError(err).Error("error trying to save invalid rooms to track progress")
return err
if len(invalidPods) > 0 {
err = models.SetInvalidRooms(w.RedisClient.Trace(ctx), w.MetricsReporter, w.SchedulerName, incorrectPodNames)
if err != nil {
logger.WithError(err).Error("error trying to save invalid rooms to track progress")
return err
}
}

logger.WithFields(logrus.Fields{
"operation": operationManager.GetOperationKey(),
}).Infof(`changing state from "%s" to "%s"`, status["description"], models.OpManagerRollingUpdate)
err = operationManager.SetDescription(models.OpManagerRollingUpdate)
if err != nil {
logger.WithError(err).Error("error trying to set opmanager to rolling update status")
Expand All @@ -1302,6 +1301,13 @@ func (w *Watcher) EnsureCorrectRooms() error {
}
}

if len(invalidPods) <= 0 {
// delete invalidRooms key for safety
models.RemoveInvalidRoomsKey(w.RedisClient.Trace(ctx), w.MetricsReporter, w.SchedulerName)
logger.Debug("no invalid pods to replace")
return nil
}

// replace invalid pods using rolling strategy
timeoutSec := w.Config.GetInt("updateTimeoutSeconds")
timeoutDur := time.Duration(timeoutSec) * time.Second
Expand Down
35 changes: 35 additions & 0 deletions watcher/watcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,9 @@ var _ = Describe("Watcher", func() {
w.Run = false
}, mockDb, nil, nil)

opManager := models.NewOperationManager(configYaml.Name, mockRedisClient, logger)
testing.MockGetCurrentOperationKey(opManager, mockRedisClient, nil)

mockRedisClient.EXPECT().TxPipeline().Return(mockPipeline)
mockPipeline.EXPECT().Del(models.GetInvalidRoomsKey(configYaml.Name))
mockPipeline.EXPECT().Exec()
Expand Down Expand Up @@ -4427,6 +4430,38 @@ var _ = Describe("Watcher", func() {
Expect(hook.Entries).To(testing.ContainLogMessage(fmt.Sprintf("error deleting pod %s", podNames[1])))
})

It("should set state to rolling update when there is no invalid pods and a operation is running", func() {
testing.MockSelectScheduler(yaml1, mockDb, nil)
testing.MockListPods(mockPipeline, mockRedisClient, w.SchedulerName, []string{}, nil)
testing.MockGetRegisteredRooms(mockRedisClient, mockPipeline,
w.SchedulerName, [][]string{}, nil)

opKey := fmt.Sprintf("opmanager:%s:1234", configYaml.Name)
opManager := models.NewOperationManager(configYaml.Name, mockRedisClient, logger)
mockRedisClient.EXPECT().
Get(opManager.BuildCurrOpKey()).
Return(redis.NewStringResult(opKey, nil))

mockRedisClient.EXPECT().
HGetAll(opKey).
Return(redis.NewStringStringMapResult(map[string]string{
"description": models.OpManagerRunning,
}, nil))

mockRedisClient.EXPECT().
HMSet(opKey, map[string]interface{}{
"description": models.OpManagerRollingUpdate,
}).Return(redis.NewStatusResult("", nil))

mockRedisClient.EXPECT().TxPipeline().Return(mockPipeline)
mockPipeline.EXPECT().Del(models.GetInvalidRoomsKey(configYaml.Name))
mockPipeline.EXPECT().Exec()

err := w.EnsureCorrectRooms()

Expect(err).ToNot(HaveOccurred())
})

It("should delete invalid pods", func() {
podNames := []string{"room-1", "room-2"}
room := models.NewRoom(podNames[0], w.SchedulerName)
Expand Down

0 comments on commit 1e7e89b

Please sign in to comment.