Skip to content
This repository has been archived by the owner on Apr 29, 2024. It is now read-only.

Commit

Permalink
Merge pull request #830 from caos/cleanup-node-agents
Browse files Browse the repository at this point in the history
fix: only cleanup expendable current node agents
  • Loading branch information
eliobischof committed Aug 27, 2021
2 parents 67b5aae + 161b66e commit d16a683
Showing 1 changed file with 16 additions and 16 deletions.
32 changes: 16 additions & 16 deletions internal/operator/orbiter/takeoff.go
Expand Up @@ -107,10 +107,6 @@ func Adapt(gitClient *git.Client, monitor mntr.Monitor, finished chan struct{},
return query, destroy, configure, migrate, treeDesired, treeCurrent, secrets, err
}

const clearEachEnsuredIteration uint8 = 10

var clearCount uint8

func Takeoff(monitor mntr.Monitor, conf *Config, healthyChan chan bool) func() {

return func() {
Expand Down Expand Up @@ -202,25 +198,29 @@ func Takeoff(monitor mntr.Monitor, conf *Config, healthyChan chan bool) func() {
}

if result.Done {
if clearCount < clearEachEnsuredIteration {
clearCount++
}
monitor.Info("Desired state is ensured")
} else {
clearCount = 0
monitor.Info("Desired state is not yet ensured")
}

conf.GitClient.UpdateRemote("Current state changed", func() []git.File {
pushFiles := marshalCurrentFiles()
if result.Done &&
(len(currentNodeAgents.Current.NA) != len(desiredNodeAgents.Spec.NodeAgents.NA) || clearCount == clearEachEnsuredIteration) {
clearCount = 0
monitor.Info("Clearing node agents current states")
pushFiles = append(pushFiles, git.File{
Path: "caos-internal/orbiter/node-agents-current.yml",
Content: nil,
})
if result.Done {
var deletedACurrentNodeAgent bool
for currentNA := range currentNodeAgents.Current.NA {
if _, ok := desiredNodeAgents.Spec.NodeAgents.NA[currentNA]; !ok {
currentNodeAgents.Current.NA[currentNA] = nil
delete(currentNodeAgents.Current.NA, currentNA)
deletedACurrentNodeAgent = true
}
}
if deletedACurrentNodeAgent {
monitor.Info("Clearing node agents current states")
pushFiles = append(pushFiles, git.File{
Path: "caos-internal/orbiter/node-agents-current.yml",
Content: common.MarshalYAML(currentNodeAgents),
})
}
}
return pushFiles
})
Expand Down

0 comments on commit d16a683

Please sign in to comment.