Merge PR #56260 again.

This commit is contained in:
Jing Ai 2017-11-24 18:23:56 -08:00
parent ba577bb5dd
commit ce5d158f22
2 changed files with 9 additions and 17 deletions

View File

@ -244,9 +244,7 @@ func (op *updateOp) validateRange(ctx context.Context, sync *NodeSync, node *v1.
// alias. // alias.
func (op *updateOp) updateNodeFromAlias(ctx context.Context, sync *NodeSync, node *v1.Node, aliasRange *net.IPNet) error { func (op *updateOp) updateNodeFromAlias(ctx context.Context, sync *NodeSync, node *v1.Node, aliasRange *net.IPNet) error {
if sync.mode != SyncFromCloud { if sync.mode != SyncFromCloud {
sync.kubeAPI.EmitNodeWarningEvent(node.Name, InvalidModeEvent, glog.Warningf("Detect mode %q while expect to sync from cloud", sync.mode)
"Cannot sync from cloud in mode %q", sync.mode)
return fmt.Errorf("cannot sync from cloud in mode %q", sync.mode)
} }
glog.V(2).Infof("Updating node spec with alias range, node.PodCIDR = %v", aliasRange) glog.V(2).Infof("Updating node spec with alias range, node.PodCIDR = %v", aliasRange)
@ -276,9 +274,7 @@ func (op *updateOp) updateNodeFromAlias(ctx context.Context, sync *NodeSync, nod
// updateAliasFromNode updates the cloud alias given the node allocation. // updateAliasFromNode updates the cloud alias given the node allocation.
func (op *updateOp) updateAliasFromNode(ctx context.Context, sync *NodeSync, node *v1.Node) error { func (op *updateOp) updateAliasFromNode(ctx context.Context, sync *NodeSync, node *v1.Node) error {
if sync.mode != SyncFromCluster { if sync.mode != SyncFromCluster {
sync.kubeAPI.EmitNodeWarningEvent( glog.Warningf("Detect mode %q while expect to sync from cluster", sync.mode)
node.Name, InvalidModeEvent, "Cannot sync to cloud in mode %q", sync.mode)
return fmt.Errorf("cannot sync to cloud in mode %q", sync.mode)
} }
_, aliasRange, err := net.ParseCIDR(node.Spec.PodCIDR) _, aliasRange, err := net.ParseCIDR(node.Spec.PodCIDR)

View File

@ -145,11 +145,9 @@ func TestNodeSyncUpdate(t *testing.T) {
events: []fakeEvent{{"node1", "CloudCIDRAllocatorMismatch"}}, events: []fakeEvent{{"node1", "CloudCIDRAllocatorMismatch"}},
}, },
{ {
desc: "update alias from node", desc: "update alias from node",
mode: SyncFromCloud, mode: SyncFromCloud,
node: nodeWithCIDRRange, node: nodeWithCIDRRange,
events: []fakeEvent{{"node1", "CloudCIDRAllocatorInvalidMode"}},
wantError: true,
}, },
{ {
desc: "update alias from node", desc: "update alias from node",
@ -165,12 +163,10 @@ func TestNodeSyncUpdate(t *testing.T) {
// XXX/bowei -- validation // XXX/bowei -- validation
}, },
{ {
desc: "update node from alias", desc: "update node from alias",
mode: SyncFromCluster, mode: SyncFromCluster,
node: nodeWithoutCIDRRange, node: nodeWithoutCIDRRange,
fake: fakeAPIs{aliasRange: test.MustParseCIDR("10.1.2.3/16")}, fake: fakeAPIs{aliasRange: test.MustParseCIDR("10.1.2.3/16")},
events: []fakeEvent{{"node1", "CloudCIDRAllocatorInvalidMode"}},
wantError: true,
}, },
{ {
desc: "allocate range", desc: "allocate range",