"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "pkg/controller/cloud/node_controller_test.go" between
kubernetes-1.15.9.tar.gz and kubernetes-1.15.10.tar.gz

About: Kubernetes is a platform for automating deployment, scaling, and operations of application containers across clusters of hosts (written in "Go"). 1.15.x series.

node_controller_test.go  (kubernetes-1.15.9):node_controller_test.go  (kubernetes-1.15.10)
skipping to change at line 21 skipping to change at line 21
distributed under the License is distributed on an "AS IS" BASIS, distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
*/ */
package cloud package cloud
import ( import (
"errors" "errors"
"fmt"
"testing" "testing"
"time" "time"
"k8s.io/api/core/v1" "k8s.io/api/core/v1"
"k8s.io/client-go/kubernetes/fake" "k8s.io/client-go/kubernetes/fake"
"k8s.io/client-go/kubernetes/scheme" "k8s.io/client-go/kubernetes/scheme"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types" "k8s.io/apimachinery/pkg/types"
"k8s.io/client-go/informers" "k8s.io/client-go/informers"
skipping to change at line 1040 skipping to change at line 1041
} }
eventBroadcaster.StartLogging(klog.Infof) eventBroadcaster.StartLogging(klog.Infof)
cloudNodeController.AddCloudNode(fnh.Existing[0]) cloudNodeController.AddCloudNode(fnh.Existing[0])
assert.Equal(t, 1, len(fnh.UpdatedNodes), "Node was not updated") assert.Equal(t, 1, len(fnh.UpdatedNodes), "Node was not updated")
assert.Equal(t, "node0", fnh.UpdatedNodes[0].Name, "Node was not updated" ) assert.Equal(t, "node0", fnh.UpdatedNodes[0].Name, "Node was not updated" )
// CCM node controller should not overwrite provider if it's already set // CCM node controller should not overwrite provider if it's already set
assert.Equal(t, "test-provider-id", fnh.UpdatedNodes[0].Spec.ProviderID, "Node ProviderID not set correctly") assert.Equal(t, "test-provider-id", fnh.UpdatedNodes[0].Spec.ProviderID, "Node ProviderID not set correctly")
} }
// This test checks that a node's provider ID will subsequently be set after an
error has occurred
func TestNodeProviderIDError(t *testing.T) {
fnh := &testutil.FakeNodeHandler{
Existing: []*v1.Node{
{
ObjectMeta: metav1.ObjectMeta{
Name: "node0",
CreationTimestamp: metav1.Date(2012, 1, 1
, 0, 0, 0, 0, time.UTC),
},
Status: v1.NodeStatus{
Conditions: []v1.NodeCondition{
{
Type: v1.No
deReady,
Status: v1.Co
nditionUnknown,
LastHeartbeatTime: metav
1.Date(2015, 1, 1, 12, 0, 0, 0, time.UTC),
LastTransitionTime: metav
1.Date(2015, 1, 1, 12, 0, 0, 0, time.UTC),
},
},
},
Spec: v1.NodeSpec{
Taints: []v1.Taint{
{
Key: schedulerapi.Tain
tExternalCloudProvider,
Value: "true",
Effect: v1.TaintEffectNoS
chedule,
},
},
},
},
},
Clientset: fake.NewSimpleClientset(&v1.PodList{}),
DeleteWaitChan: make(chan struct{}),
}
factory := informers.NewSharedInformerFactory(fnh, 0)
fakeCloud := &fakecloud.Cloud{
InstanceTypes: map[types.NodeName]string{},
Addresses: []v1.NodeAddress{
{
Type: v1.NodeHostName,
Address: "node0.cloud.internal",
},
{
Type: v1.NodeInternalIP,
Address: "10.0.0.1",
},
{
Type: v1.NodeExternalIP,
Address: "132.143.154.163",
},
},
Provider: "test",
ExtID: map[types.NodeName]string{},
ExtIDErr: map[types.NodeName]error{
types.NodeName("node0"): fmt.Errorf("fake error"),
},
Err: nil,
}
eventBroadcaster := record.NewBroadcaster()
cloudNodeController := &CloudNodeController{
kubeClient: fnh,
nodeInformer: factory.Core().V1().Nodes(),
cloud: fakeCloud,
nodeStatusUpdateFrequency: 1 * time.Second,
recorder: eventBroadcaster.NewRecorder(scheme.Sc
heme, v1.EventSource{Component: "cloud-node-controller"}),
}
eventBroadcaster.StartLogging(klog.Infof)
cloudNodeController.AddCloudNode(fnh.Existing[0])
assert.Equal(t, 0, len(fnh.UpdatedNodes), "Node was unexpectedly updated"
)
cloudNodeController.UpdateCloudNode(nil, fnh.Existing[0])
assert.Equal(t, 0, len(fnh.UpdatedNodes), "Node was unexpectedly updated"
)
fakeCloud.ExtID[types.NodeName("node0")] = "test-provider-id"
delete(fakeCloud.ExtIDErr, types.NodeName("node0"))
cloudNodeController.UpdateCloudNode(nil, fnh.Existing[0])
assert.Equal(t, 1, len(fnh.UpdatedNodes), "Node was not updated")
assert.Equal(t, "node0", fnh.UpdatedNodes[0].Name, "Node was not updated"
)
assert.Equal(t, "test://test-provider-id", fnh.UpdatedNodes[0].Spec.Provi
derID, "Node ProviderID not set correctly")
}
// This test checks that a NotImplemented error when getting a node's provider I
D will not prevent removal of the taint
func TestNodeProviderIDNotImplemented(t *testing.T) {
fnh := &testutil.FakeNodeHandler{
Existing: []*v1.Node{
{
ObjectMeta: metav1.ObjectMeta{
Name: "node0",
CreationTimestamp: metav1.Date(2012, 1, 1
, 0, 0, 0, 0, time.UTC),
},
Status: v1.NodeStatus{
Conditions: []v1.NodeCondition{
{
Type: v1.No
deReady,
Status: v1.Co
nditionUnknown,
LastHeartbeatTime: metav
1.Date(2015, 1, 1, 12, 0, 0, 0, time.UTC),
LastTransitionTime: metav
1.Date(2015, 1, 1, 12, 0, 0, 0, time.UTC),
},
},
},
Spec: v1.NodeSpec{
Taints: []v1.Taint{
{
Key: schedulerapi.Tain
tExternalCloudProvider,
Value: "true",
Effect: v1.TaintEffectNoS
chedule,
},
},
},
},
},
Clientset: fake.NewSimpleClientset(&v1.PodList{}),
DeleteWaitChan: make(chan struct{}),
}
factory := informers.NewSharedInformerFactory(fnh, 0)
fakeCloud := &fakecloud.Cloud{
InstanceTypes: map[types.NodeName]string{},
Addresses: []v1.NodeAddress{
{
Type: v1.NodeHostName,
Address: "node0.cloud.internal",
},
{
Type: v1.NodeInternalIP,
Address: "10.0.0.1",
},
{
Type: v1.NodeExternalIP,
Address: "132.143.154.163",
},
},
Provider: "test",
ExtID: map[types.NodeName]string{},
ExtIDErr: map[types.NodeName]error{
types.NodeName("node0"): cloudprovider.NotImplemented,
},
Err: nil,
}
eventBroadcaster := record.NewBroadcaster()
cloudNodeController := &CloudNodeController{
kubeClient: fnh,
nodeInformer: factory.Core().V1().Nodes(),
cloud: fakeCloud,
nodeStatusUpdateFrequency: 1 * time.Second,
recorder: eventBroadcaster.NewRecorder(scheme.Sc
heme, v1.EventSource{Component: "cloud-node-controller"}),
}
eventBroadcaster.StartLogging(klog.Infof)
cloudNodeController.AddCloudNode(fnh.Existing[0])
assert.Equal(t, 1, len(fnh.UpdatedNodes), "Node was not updated")
assert.Equal(t, "node0", fnh.UpdatedNodes[0].Name, "Node was not updated"
)
assert.Equal(t, "", fnh.UpdatedNodes[0].Spec.ProviderID, "Node ProviderID
set to unexpected value")
}
 End of changes. 2 change blocks. 
0 lines changed or deleted 1 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)