Skip to content

Commit

Permalink
Merge pull request #65 from Oats87/issues/system-agent/64
Browse files Browse the repository at this point in the history
K8splan should run probes
  • Loading branch information
Oats87 authored Nov 8, 2021
2 parents 7922dcc + fda6e6a commit bba4422
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
14 changes: 14 additions & 0 deletions pkg/k8splan/watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions pkg/prober/probes.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit bba4422

Please sign in to comment.