Skip to content

Commit

Permalink
Merge pull request #7 from wangyizhi1/main
Browse files Browse the repository at this point in the history
fix: reset annotation after successful probe
  • Loading branch information
wuyingjun-lucky authored Dec 25, 2023
2 parents 29d4e5a + 15d0346 commit c68009c
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 9 deletions.
9 changes: 8 additions & 1 deletion pkg/endpointslice/prober/prober_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"sigs.k8s.io/mcs-api/pkg/apis/v1alpha1"

"github.com/kosmos.io/eps-probe-plugin/pkg/endpointslice/prober/results"
"github.com/kosmos.io/eps-probe-plugin/pkg/serviceimport/annotation"
"github.com/kosmos.io/eps-probe-plugin/pkg/util"
)

Expand Down Expand Up @@ -92,7 +93,13 @@ func (m *manager) AddServiceImport(svcImport *v1alpha1.ServiceImport) {
return
}

w := newWorker(m, addrs, svcImport)
unreachableAddrs, err := util.ConvertStringToAddresses(svcImport.Annotations[annotation.ServiceImportNotReachableEPSAddr])
if err != nil {
klog.ErrorS(err, "Can't parse ips from annotations", "serviceImport", klog.KObj(svcImport))
return
}

w := newWorker(m, addrs, unreachableAddrs, svcImport)
m.workers[key] = w
go w.run()
}
Expand Down
12 changes: 7 additions & 5 deletions pkg/endpointslice/prober/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,11 @@ type record struct {
resultRun int
}

func newWorker(m *manager, addrs []string, svcImport *v1alpha1.ServiceImport) *worker {
func newWorker(m *manager, addrs []string, unReachableAddrs []string, svcImport *v1alpha1.ServiceImport) *worker {
lastResult := results.Success
if len(unReachableAddrs) > 0 {
lastResult = results.Failure
}
w := &worker{
stopCh: make(chan struct{}, 1),
manualTriggerCh: make(chan struct{}, 1),
Expand All @@ -64,9 +68,8 @@ func newWorker(m *manager, addrs []string, svcImport *v1alpha1.ServiceImport) *w
FailureThreshold: m.spec.FailureThreshold,
},
records: map[string]record{},
latestResult: results.Success,
latestResult: lastResult,
}

return w
}

Expand Down Expand Up @@ -117,7 +120,6 @@ func (w *worker) doProbe() (keepGoing bool) {
"serviceImport", klog.KObj(w.serviceImport))

w.resultsManager.Set(w.serviceImport, w.addresses, results.Success)

return false
}

Expand Down Expand Up @@ -150,7 +152,7 @@ func (w *worker) doProbe() (keepGoing bool) {
}

if len(addrs) == 0 && w.latestResult == results.Failure {
w.resultsManager.Set(w.serviceImport, w.addresses, results.Success)
w.resultsManager.Set(w.serviceImport, []string{}, results.Success)
w.latestResult = results.Success
klog.V(3).InfoS("Set probe results to success", "serviceImport", klog.KObj(w.serviceImport))
}
Expand Down
4 changes: 1 addition & 3 deletions pkg/serviceimport/serviceimport.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,7 @@ func (c *Controller) syncLoop() {
select {
case update := <-c.resultsManager.Updates():
klog.V(3).InfoS("Received results", "results", update)
if update.Result == results.Failure {
c.annotationManager.Set("", update.Addresses, update.SvcImportName, update.Namespace)
}
c.annotationManager.Set("", update.Addresses, update.SvcImportName, update.Namespace)
default:
}
}

0 comments on commit c68009c

Please sign in to comment.