Skip to content

Commit

Permalink
fix(torch): processing duplications
Browse files Browse the repository at this point in the history
Signed-off-by: Jose Ramon Mañes <[email protected]>
  • Loading branch information
tty47 committed Nov 8, 2023
1 parent 76b8f07 commit 4398782
Showing 1 changed file with 18 additions and 7 deletions.
25 changes: 18 additions & 7 deletions pkg/k8s/statefulsets.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,28 @@ func WatchStatefulSets() error {
return err
}

// Variable to keep track of the last processed name
lastProcessedName := ""

// Watch for events on the watcher channel
for event := range watcher.ResultChan() {
if statefulSet, ok := event.Object.(*v1.StatefulSet); ok {
//log.Info("StatefulSet containers: ", statefulSet.Spec.Template.Spec.Containers)

// check if the node is DA, if so, send it to the queue to generate the multi address
// Check if the name has the "da" prefix
if strings.HasPrefix(statefulSet.Name, "da") {
err := redis.Producer(statefulSet.Name, queueK8SNodes)
if err != nil {
log.Error("ERROR adding the node to the queue: ", err)
return err
// Check if the name is different from the last processed one
if statefulSet.Name != lastProcessedName {
// Process the name and perform necessary actions
err := redis.Producer(statefulSet.Name, queueK8SNodes)
if err != nil {
log.Error("ERROR adding the node to the queue: ", err)
return err
}

// Update the last processed name to don't process it more than once.
lastProcessedName = statefulSet.Name
} else {
// cleanup the previous processed to add it in future iterations.
lastProcessedName = ""
}
}
}
Expand Down

0 comments on commit 4398782

Please sign in to comment.