From 0a0c85e9593cfe120e64a24c0be272bf667e11cc Mon Sep 17 00:00:00 2001 From: Elio Bischof Date: Wed, 25 Aug 2021 11:38:16 +0200 Subject: [PATCH 1/4] fix: only cleanup expendable current node agents --- internal/operator/orbiter/takeoff.go | 35 +++++++++++++++------------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/internal/operator/orbiter/takeoff.go b/internal/operator/orbiter/takeoff.go index 898e41da8..5b6720838 100644 --- a/internal/operator/orbiter/takeoff.go +++ b/internal/operator/orbiter/takeoff.go @@ -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() { @@ -202,25 +198,32 @@ 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 { + delete(currentNodeAgents.Current.NA, currentNA) + deletedACurrentNodeAgent = true + } + } + if deletedACurrentNodeAgent { + monitor.Info("Clearing node agents current states") + currentNodeAgentBytes, err := yaml.Marshal(currentNodeAgents) + if err != nil { + panic(err) + } + pushFiles = append(pushFiles, git.File{ + Path: "caos-internal/orbiter/node-agents-current.yml", + Content: currentNodeAgentBytes, + }) + } } return pushFiles }) From ab6751402239a5edf335835bfd4f1c350f4f6371 Mon Sep 17 00:00:00 2001 From: Elio Bischof Date: Wed, 25 Aug 2021 12:10:15 +0200 Subject: [PATCH 2/4] fix: use custom yaml marshaller --- internal/operator/orbiter/takeoff.go | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/internal/operator/orbiter/takeoff.go b/internal/operator/orbiter/takeoff.go index 5b6720838..5f796716e 100644 --- a/internal/operator/orbiter/takeoff.go +++ b/internal/operator/orbiter/takeoff.go @@ -215,13 +215,9 @@ func Takeoff(monitor mntr.Monitor, conf *Config, healthyChan chan bool) func() { } if deletedACurrentNodeAgent { monitor.Info("Clearing node agents current states") - currentNodeAgentBytes, err := yaml.Marshal(currentNodeAgents) - if err != nil { - panic(err) - } pushFiles = append(pushFiles, git.File{ Path: "caos-internal/orbiter/node-agents-current.yml", - Content: currentNodeAgentBytes, + Content: common.MarshalYAML(currentNodeAgents), }) } } From eb74ce25eb40c93ae72840586f22b5e4836481c8 Mon Sep 17 00:00:00 2001 From: Elio Bischof Date: Wed, 25 Aug 2021 14:02:50 +0200 Subject: [PATCH 3/4] fix: avoid memory leaks --- internal/operator/orbiter/takeoff.go | 1 + 1 file changed, 1 insertion(+) diff --git a/internal/operator/orbiter/takeoff.go b/internal/operator/orbiter/takeoff.go index 5f796716e..3815e7b6e 100644 --- a/internal/operator/orbiter/takeoff.go +++ b/internal/operator/orbiter/takeoff.go @@ -209,6 +209,7 @@ func Takeoff(monitor mntr.Monitor, conf *Config, healthyChan chan bool) func() { var deletedACurrentNodeAgent bool for currentNA := range currentNodeAgents.Current.NA { if _, ok := desiredNodeAgents.Spec.NodeAgents.NA[currentNA]; !ok { + currentNodeAgents.Current.NA = nil delete(currentNodeAgents.Current.NA, currentNA) deletedACurrentNodeAgent = true } From 161b66e0b53def42d53749abe1839e5961f45501 Mon Sep 17 00:00:00 2001 From: Elio Bischof Date: Wed, 25 Aug 2021 14:07:16 +0200 Subject: [PATCH 4/4] fix: set specific node agent to nil, not the whole map --- internal/operator/orbiter/takeoff.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/operator/orbiter/takeoff.go b/internal/operator/orbiter/takeoff.go index 3815e7b6e..a8b780532 100644 --- a/internal/operator/orbiter/takeoff.go +++ b/internal/operator/orbiter/takeoff.go @@ -209,7 +209,7 @@ func Takeoff(monitor mntr.Monitor, conf *Config, healthyChan chan bool) func() { var deletedACurrentNodeAgent bool for currentNA := range currentNodeAgents.Current.NA { if _, ok := desiredNodeAgents.Spec.NodeAgents.NA[currentNA]; !ok { - currentNodeAgents.Current.NA = nil + currentNodeAgents.Current.NA[currentNA] = nil delete(currentNodeAgents.Current.NA, currentNA) deletedACurrentNodeAgent = true }