-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #824 from duanmengkk/feature_etcd_watcher
add etcd watcher for blockaffinity
- Loading branch information
Showing
8 changed files
with
819 additions
and
103 deletions.
There are no files selected for viewing
19 changes: 19 additions & 0 deletions
19
pkg/clusterlink/controllers/nodecidr/adaper/blockwatchsyncer/blockaffinitysyncer.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package blockwatchsyncer | ||
|
||
import ( | ||
apiv3 "github.com/projectcalico/api/pkg/apis/projectcalico/v3" | ||
"github.com/projectcalico/calico/libcalico-go/lib/backend/api" | ||
"github.com/projectcalico/calico/libcalico-go/lib/backend/model" | ||
"github.com/projectcalico/calico/libcalico-go/lib/backend/watchersyncer" | ||
) | ||
|
||
// NewBlockWatchSyncer creates a new BlockAffinity v1 Syncer. | ||
func NewBlockWatchSyncer(client api.Client, callbacks api.SyncerCallbacks) api.Syncer { | ||
resourceTypes := []watchersyncer.ResourceType{ | ||
{ | ||
ListInterface: model.ResourceListOptions{Kind: apiv3.KindBlockAffinity}, | ||
}, | ||
} | ||
|
||
return watchersyncer.New(client, resourceTypes, callbacks) | ||
} |
92 changes: 92 additions & 0 deletions
92
pkg/clusterlink/controllers/nodecidr/adaper/blockwatchsyncer/blockeventhandler.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
package blockwatchsyncer | ||
|
||
import ( | ||
"github.com/kosmos.io/kosmos/pkg/utils/lifted" | ||
"github.com/projectcalico/calico/libcalico-go/lib/backend/api" | ||
"k8s.io/apimachinery/pkg/util/wait" | ||
"k8s.io/klog/v2" | ||
"time" | ||
) | ||
|
||
// syncedPollPeriod controls how often you look at the status of your sync funcs | ||
var syncedPollPeriod = 100 * time.Millisecond | ||
|
||
type BlockEventHandler struct { | ||
// Channel for getting updates and status updates from syncer. | ||
syncerC chan interface{} | ||
|
||
processor lifted.AsyncWorker | ||
// Channel to indicate node status reporter routine is not needed anymore. | ||
done chan struct{} | ||
|
||
// Flag to show we are in-sync. | ||
inSync bool | ||
} | ||
|
||
func NewBlockEventHandler(processor lifted.AsyncWorker) *BlockEventHandler { | ||
return &BlockEventHandler{ | ||
processor: processor, | ||
} | ||
} | ||
|
||
func (b *BlockEventHandler) Run(stopCh <-chan struct{}) { | ||
for { | ||
select { | ||
case <-stopCh: | ||
return | ||
case <-b.done: | ||
return | ||
case event := <-b.syncerC: | ||
switch event := event.(type) { | ||
case []api.Update: | ||
b.onupdate(event) | ||
case api.SyncStatus: | ||
b.inSync = true | ||
} | ||
} | ||
} | ||
} | ||
|
||
func (b *BlockEventHandler) Stop() { | ||
b.done <- struct{}{} | ||
} | ||
|
||
func (b *BlockEventHandler) Done() <-chan struct{} { | ||
return b.done | ||
} | ||
|
||
func (b *BlockEventHandler) InSync() bool { | ||
return b.inSync | ||
} | ||
|
||
func (b *BlockEventHandler) OnStatusUpdated(status api.SyncStatus) { | ||
if status == api.InSync { | ||
b.syncerC <- status | ||
} | ||
} | ||
|
||
func (b *BlockEventHandler) OnUpdates(updates []api.Update) { | ||
b.syncerC <- updates | ||
} | ||
|
||
// todo put etcd's event info AsyncWorker's queue | ||
func (b *BlockEventHandler) onupdate(event []api.Update) { | ||
|
||
} | ||
|
||
func (b *BlockEventHandler) WaitForCacheSync(stopCh <-chan struct{}) bool { | ||
err := wait.PollImmediateUntil(syncedPollPeriod, func() (done bool, err error) { | ||
if b.inSync { | ||
return true, nil | ||
} | ||
return false, nil | ||
}, stopCh) | ||
|
||
if err != nil { | ||
klog.V(2).Infof("stop requested") | ||
return false | ||
} | ||
|
||
klog.V(4).Infof("caches populated") | ||
return true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
vendor/github.com/projectcalico/calico/libcalico-go/lib/backend/watchersyncer/doc.go
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.