mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-09-11 14:11:14 +00:00
Remove OnceAndForever util, create a Run() method on MinionController.
This commit is contained in:
@@ -18,10 +18,12 @@ package controller
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/cloudprovider"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/registry/minion"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
|
||||
"github.com/golang/glog"
|
||||
)
|
||||
|
||||
@@ -30,16 +32,30 @@ type MinionController struct {
|
||||
matchRE string
|
||||
staticResources *api.NodeResources
|
||||
registry minion.Registry
|
||||
period time.Duration
|
||||
}
|
||||
|
||||
// NewMinionController returns a new minion controller to sync instances from cloudprovider.
|
||||
func NewMinionController(cloud cloudprovider.Interface, matchRE string, staticResources *api.NodeResources, registry minion.Registry) (*MinionController, error) {
|
||||
func NewMinionController(
|
||||
cloud cloudprovider.Interface,
|
||||
matchRE string,
|
||||
staticResources *api.NodeResources,
|
||||
registry minion.Registry,
|
||||
period time.Duration) *MinionController {
|
||||
return &MinionController{
|
||||
cloud: cloud,
|
||||
matchRE: matchRE,
|
||||
staticResources: staticResources,
|
||||
registry: registry,
|
||||
}, nil
|
||||
period: period,
|
||||
}
|
||||
}
|
||||
|
||||
// Run starts syncing instances from cloudprovider periodically.
|
||||
func (s *MinionController) Run() {
|
||||
// Call Sync() first to warm up minion registry.
|
||||
s.Sync()
|
||||
go util.Forever(func() { s.Sync() }, s.period)
|
||||
}
|
||||
|
||||
// Sync syncs list of instances from cloudprovider to master etcd registry.
|
||||
|
@@ -18,6 +18,7 @@ package controller
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/latest"
|
||||
@@ -64,10 +65,7 @@ func TestSyncCreateMinion(t *testing.T) {
|
||||
fakeCloud := fake_cloud.FakeCloud{
|
||||
Machines: instances,
|
||||
}
|
||||
minionController, err := NewMinionController(&fakeCloud, ".*", nil, registry)
|
||||
if err != nil {
|
||||
t.Errorf("Unexpected error")
|
||||
}
|
||||
minionController := NewMinionController(&fakeCloud, ".*", nil, registry, time.Second)
|
||||
|
||||
minion, err := registry.GetMinion(ctx, "m3")
|
||||
if minion != nil {
|
||||
@@ -112,10 +110,7 @@ func TestSyncDeleteMinion(t *testing.T) {
|
||||
fakeCloud := fake_cloud.FakeCloud{
|
||||
Machines: instances,
|
||||
}
|
||||
minionController, err := NewMinionController(&fakeCloud, ".*", nil, registry)
|
||||
if err != nil {
|
||||
t.Errorf("Unexpected error")
|
||||
}
|
||||
minionController := NewMinionController(&fakeCloud, ".*", nil, registry, time.Second)
|
||||
|
||||
minion, err := registry.GetMinion(ctx, "m3")
|
||||
if minion == nil {
|
||||
@@ -150,12 +145,9 @@ func TestSyncMinionRegexp(t *testing.T) {
|
||||
fakeCloud := fake_cloud.FakeCloud{
|
||||
Machines: instances,
|
||||
}
|
||||
minionController, err := NewMinionController(&fakeCloud, "m[0-9]+", nil, registry)
|
||||
if err != nil {
|
||||
t.Errorf("Unexpected error")
|
||||
}
|
||||
minionController := NewMinionController(&fakeCloud, "m[0-9]+", nil, registry, time.Second)
|
||||
|
||||
err = minionController.Sync()
|
||||
err := minionController.Sync()
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error: %v", err)
|
||||
}
|
||||
|
Reference in New Issue
Block a user