mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-03 09:22:44 +00:00
isolate node creation into separate function, address PR comments
This commit is contained in:
parent
23a6c5b3b7
commit
58f96f76e3
@ -246,8 +246,8 @@ func TestDeleteAddressWithWrongTier(t *testing.T) {
|
|||||||
|
|
||||||
const (
|
const (
|
||||||
gceProjectId = "test-project"
|
gceProjectId = "test-project"
|
||||||
gceRegion = "test-region"
|
gceRegion = "us-central1"
|
||||||
zoneName = "zone1"
|
zoneName = "us-central1-b"
|
||||||
nodeName = "test-node-1"
|
nodeName = "test-node-1"
|
||||||
clusterName = "Test Cluster Name"
|
clusterName = "Test Cluster Name"
|
||||||
clusterID = "test-cluster-id"
|
clusterID = "test-cluster-id"
|
||||||
@ -272,7 +272,9 @@ func fakeGCECloud() (*GCECloud, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Used in disk unit tests
|
||||||
fakeManager := newFakeManager(gceProjectId, gceRegion)
|
fakeManager := newFakeManager(gceProjectId, gceRegion)
|
||||||
|
zonesWithNodes := createNodeZones([]string{zoneName})
|
||||||
|
|
||||||
alphaFeatureGate, err := NewAlphaFeatureGate([]string{})
|
alphaFeatureGate, err := NewAlphaFeatureGate([]string{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -281,7 +283,6 @@ func fakeGCECloud() (*GCECloud, error) {
|
|||||||
|
|
||||||
cloud := cloud.NewMockGCE()
|
cloud := cloud.NewMockGCE()
|
||||||
cloud.MockTargetPools.AddInstanceHook = mock.AddInstanceHook
|
cloud.MockTargetPools.AddInstanceHook = mock.AddInstanceHook
|
||||||
zonesWithNodes := createNodeZones([]string{zoneName})
|
|
||||||
|
|
||||||
gce := GCECloud{
|
gce := GCECloud{
|
||||||
region: gceRegion,
|
region: gceRegion,
|
||||||
@ -298,38 +299,58 @@ func fakeGCECloud() (*GCECloud, error) {
|
|||||||
return &gce, nil
|
return &gce, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func createExternalLoadBalancer(gce *GCECloud) (*v1.LoadBalancerStatus, error) {
|
func createAndInsertNodes(gce *GCECloud, nodeNames []string) ([]*v1.Node, error) {
|
||||||
err := gce.InsertInstance(
|
nodes := []*v1.Node{}
|
||||||
gceProjectId,
|
|
||||||
zoneName,
|
for _, name := range nodeNames {
|
||||||
&compute.Instance{
|
// Inserting the same node name twice causes an error - here we call
|
||||||
Name: nodeName,
|
// DeleteInstance to guarantee that nodes aren't inserted twice.
|
||||||
Tags: &compute.Tags{
|
// See TestUpdateExternalLoadBalancer.
|
||||||
Items: []string{nodeName},
|
err := gce.DeleteInstance(gceProjectId, zoneName, name)
|
||||||
|
|
||||||
|
err = gce.InsertInstance(
|
||||||
|
gceProjectId,
|
||||||
|
zoneName,
|
||||||
|
&compute.Instance{
|
||||||
|
Name: name,
|
||||||
|
Tags: &compute.Tags{
|
||||||
|
Items: []string{name},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
)
|
||||||
)
|
|
||||||
|
if err != nil {
|
||||||
|
return nodes, err
|
||||||
|
}
|
||||||
|
|
||||||
|
nodes = append(
|
||||||
|
nodes,
|
||||||
|
&v1.Node{
|
||||||
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
|
Name: name,
|
||||||
|
Labels: map[string]string{
|
||||||
|
kubeletapis.LabelHostname: name,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Status: v1.NodeStatus{
|
||||||
|
NodeInfo: v1.NodeSystemInfo{
|
||||||
|
KubeProxyVersion: "v1.7.2",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nodes, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func createExternalLoadBalancer(gce *GCECloud) (*v1.LoadBalancerStatus, error) {
|
||||||
|
nodes, err := createAndInsertNodes(gce, []string{nodeName})
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
nodes := []*v1.Node{
|
|
||||||
{
|
|
||||||
ObjectMeta: metav1.ObjectMeta{
|
|
||||||
Name: nodeName,
|
|
||||||
Labels: map[string]string{
|
|
||||||
kubeletapis.LabelHostname: nodeName,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
Status: v1.NodeStatus{
|
|
||||||
NodeInfo: v1.NodeSystemInfo{
|
|
||||||
KubeProxyVersion: "v1.7.2",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
status, err := gce.ensureExternalLoadBalancer(
|
status, err := gce.ensureExternalLoadBalancer(
|
||||||
clusterName,
|
clusterName,
|
||||||
clusterID,
|
clusterID,
|
||||||
@ -386,45 +407,8 @@ func TestUpdateExternalLoadBalancer(t *testing.T) {
|
|||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
newNodeName := "test-node-2"
|
newNodeName := "test-node-2"
|
||||||
gce.InsertInstance(
|
newNodes, err := createAndInsertNodes(gce, []string{nodeName, newNodeName})
|
||||||
gceProjectId,
|
assert.NoError(t, err)
|
||||||
zoneName,
|
|
||||||
&compute.Instance{
|
|
||||||
Name: newNodeName,
|
|
||||||
Tags: &compute.Tags{
|
|
||||||
Items: []string{newNodeName},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
)
|
|
||||||
|
|
||||||
newNodes := []*v1.Node{
|
|
||||||
{
|
|
||||||
ObjectMeta: metav1.ObjectMeta{
|
|
||||||
Name: nodeName,
|
|
||||||
Labels: map[string]string{
|
|
||||||
kubeletapis.LabelHostname: nodeName,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
Status: v1.NodeStatus{
|
|
||||||
NodeInfo: v1.NodeSystemInfo{
|
|
||||||
KubeProxyVersion: "v1.7.2",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
ObjectMeta: metav1.ObjectMeta{
|
|
||||||
Name: newNodeName,
|
|
||||||
Labels: map[string]string{
|
|
||||||
kubeletapis.LabelHostname: newNodeName,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
Status: v1.NodeStatus{
|
|
||||||
NodeInfo: v1.NodeSystemInfo{
|
|
||||||
KubeProxyVersion: "v1.7.2",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
err = gce.updateExternalLoadBalancer(clusterName, apiService, newNodes)
|
err = gce.updateExternalLoadBalancer(clusterName, apiService, newNodes)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
Loading…
Reference in New Issue
Block a user