From fda6e6a636aeb4e817855aefff5262be1eb40f7a Mon Sep 17 00:00:00 2001 From: Chris Kim Date: Mon, 8 Nov 2021 10:39:56 -0800 Subject: [PATCH] K8splan should run probes Signed-off-by: Chris Kim --- pkg/k8splan/watcher.go | 14 ++++++++++++++ pkg/prober/probes.go | 8 ++++---- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/pkg/k8splan/watcher.go b/pkg/k8splan/watcher.go index cca7a26d..1b225af1 100644 --- a/pkg/k8splan/watcher.go +++ b/pkg/k8splan/watcher.go @@ -288,10 +288,24 @@ func (w *watcher) start(ctx context.Context) { secret.Data[successCountKey] = incrementCount(secret.Data[successCountKey]) } } + + prober.DoProbes(cp.Plan.Probes, probeStatuses, needsApplied) + + marshalledProbeStatus, err := json.Marshal(probeStatuses) + if err != nil { + logrus.Errorf("error while marshalling probe statuses: %v", err) + } else { + secret.Data[probeStatusesKey] = marshalledProbeStatus + } + if errorFromApply == nil { + // If we did not receive an error while applying (or in the case where needsApplied=false which means + // errorFromApply will be nil), we should enqueue for the next probe period to ensure probes get run on + // a timely basis. logrus.Debugf("[K8s] Enqueueing after %f seconds", probePeriod.Seconds()) core.Secret().EnqueueAfter(w.connInfo.Namespace, w.connInfo.SecretName, probePeriod) } + if reflect.DeepEqual(originalSecret.Data, secret.Data) && reflect.DeepEqual(originalSecret.StringData, secret.StringData) { logrus.Debugf("[K8s] secret data/string-data did not change, not updating secret") return originalSecret, nil diff --git a/pkg/prober/probes.go b/pkg/prober/probes.go index 33f8be4a..6a044b1e 100644 --- a/pkg/prober/probes.go +++ b/pkg/prober/probes.go @@ -14,20 +14,20 @@ func DoProbes(probes map[string]Probe, probeStatuses map[string]ProbeStatus, ini wg.Add(1) go func(probeName string, probe Probe, wg *sync.WaitGroup) { defer wg.Done() - logrus.Debugf("[K8s] (%s) running probe", probeName) + logrus.Debugf("[Prober] (%s) running probe", probeName) mu.Lock() - logrus.Debugf("[K8s] (%s) retrieving existing probe status from map if existing", probeName) + logrus.Debugf("[Prober] (%s) retrieving existing probe status from map if existing", probeName) probeStatus, ok := probeStatuses[probeName] mu.Unlock() if !ok { - logrus.Debugf("[K8s] (%s) probe status was not present in map, initializing", probeName) + logrus.Debugf("[Prober] (%s) probe status was not present in map, initializing", probeName) probeStatus = ProbeStatus{} } if err := DoProbe(probe, &probeStatus, initial); err != nil { logrus.Errorf("error running probe %s", probeName) } mu.Lock() - logrus.Debugf("[K8s] (%s) writing probe status to map", probeName) + logrus.Debugf("[Prober] (%s) writing probe status to map", probeName) probeStatuses[probeName] = probeStatus mu.Unlock() }(probeName, probe, &wg)