Merge pull request #64709 from gnufied/fix-node-alpha-tests

Automatic merge from submit-queue (batch tested with PRs 64344, 64709, 64717, 63631, 58647). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>.

Fix panic caused by no cloudprovider in test

We should not panic when no cloudprovider is present

Fixes https://github.com/kubernetes/kubernetes/issues/64704

Also added a test to cover the panic.

/sig storage
/sig node

```release-note
None
```
pull/8/head
Kubernetes Submit Queue 2018-06-05 02:16:08 -07:00 committed by GitHub
commit 3b6c2472c3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 70 additions and 24 deletions

View File

@ -1648,6 +1648,12 @@ func TestSetVolumeLimits(t *testing.T) {
expectedVolumeKey: util.AzureVolumeLimitKey,
expectedLimit: 16,
},
{
name: "when no cloudprovider is present",
cloudProviderName: "",
expectedVolumeKey: util.AzureVolumeLimitKey,
expectedLimit: -1,
},
}
for _, test := range testcases {
node := &v1.Node{
@ -1655,28 +1661,42 @@ func TestSetVolumeLimits(t *testing.T) {
Spec: v1.NodeSpec{},
}
fakeCloud := &fakecloud.FakeCloud{
Provider: test.cloudProviderName,
Err: nil,
if test.cloudProviderName != "" {
fakeCloud := &fakecloud.FakeCloud{
Provider: test.cloudProviderName,
Err: nil,
}
kubelet.cloud = fakeCloud
kubelet.cloudproviderRequestParallelism = make(chan int, 1)
kubelet.cloudproviderRequestSync = make(chan int)
kubelet.cloudproviderRequestTimeout = 10 * time.Second
} else {
kubelet.cloud = nil
}
kubelet.cloud = fakeCloud
kubelet.cloudproviderRequestParallelism = make(chan int, 1)
kubelet.cloudproviderRequestSync = make(chan int)
kubelet.cloudproviderRequestTimeout = 10 * time.Second
kubelet.setVolumeLimits(node)
nodeLimits := []v1.ResourceList{}
nodeLimits = append(nodeLimits, node.Status.Allocatable)
nodeLimits = append(nodeLimits, node.Status.Capacity)
for _, volumeLimits := range nodeLimits {
fl, ok := volumeLimits[v1.ResourceName(test.expectedVolumeKey)]
if !ok {
t.Errorf("Expected to found volume limit for %s found none", test.expectedVolumeKey)
}
foundLimit, _ := fl.AsInt64()
expectedValue := resource.NewQuantity(test.expectedLimit, resource.DecimalSI)
if expectedValue.Cmp(fl) != 0 {
t.Errorf("Expected volume limit for %s to be %v found %v", test.expectedVolumeKey, test.expectedLimit, foundLimit)
if test.expectedLimit == -1 {
_, ok := volumeLimits[v1.ResourceName(test.expectedVolumeKey)]
if ok {
t.Errorf("Expected no volume limit found for %s", test.expectedVolumeKey)
}
} else {
fl, ok := volumeLimits[v1.ResourceName(test.expectedVolumeKey)]
if !ok {
t.Errorf("Expected to found volume limit for %s found none", test.expectedVolumeKey)
}
foundLimit, _ := fl.AsInt64()
expectedValue := resource.NewQuantity(test.expectedLimit, resource.DecimalSI)
if expectedValue.Cmp(fl) != 0 {
t.Errorf("Expected volume limit for %s to be %v found %v", test.expectedVolumeKey, test.expectedLimit, foundLimit)
}
}
}
}

View File

@ -98,15 +98,23 @@ func (plugin *awsElasticBlockStorePlugin) SupportsBulkVolumeVerification() bool
}
func (plugin *awsElasticBlockStorePlugin) GetVolumeLimits() (map[string]int64, error) {
volumeLimits := map[string]int64{
util.EBSVolumeLimitKey: 39,
}
cloud := plugin.host.GetCloudProvider()
// if we can't fetch cloudprovider we return an error
// hoping external CCM or admin can set it. Returning
// default values from here will mean, no one can
// override them.
if cloud == nil {
return nil, fmt.Errorf("No cloudprovider present")
}
if cloud.ProviderName() != aws.ProviderName {
return nil, fmt.Errorf("Expected aws cloud, found %s", cloud.ProviderName())
}
volumeLimits := map[string]int64{
util.EBSVolumeLimitKey: 39,
}
instances, ok := cloud.Instances()
if !ok {
glog.V(3).Infof("Failed to get instances from cloud provider")

View File

@ -117,14 +117,24 @@ func (plugin *azureDataDiskPlugin) SupportsBulkVolumeVerification() bool {
}
func (plugin *azureDataDiskPlugin) GetVolumeLimits() (map[string]int64, error) {
volumeLimits := map[string]int64{
util.AzureVolumeLimitKey: 16,
}
cloud := plugin.host.GetCloudProvider()
// if we can't fetch cloudprovider we return an error
// hoping external CCM or admin can set it. Returning
// default values from here will mean, no one can
// override them.
if cloud == nil {
return nil, fmt.Errorf("No cloudprovider present")
}
if cloud.ProviderName() != azure.CloudProviderName {
return nil, fmt.Errorf("Expected Azure cloudprovider, got %s", cloud.ProviderName())
}
volumeLimits := map[string]int64{
util.AzureVolumeLimitKey: 16,
}
return volumeLimits, nil
}

View File

@ -103,15 +103,23 @@ func (plugin *gcePersistentDiskPlugin) GetAccessModes() []v1.PersistentVolumeAcc
}
func (plugin *gcePersistentDiskPlugin) GetVolumeLimits() (map[string]int64, error) {
volumeLimits := map[string]int64{
util.GCEVolumeLimitKey: 16,
}
cloud := plugin.host.GetCloudProvider()
// if we can't fetch cloudprovider we return an error
// hoping external CCM or admin can set it. Returning
// default values from here will mean, no one can
// override them.
if cloud == nil {
return nil, fmt.Errorf("No cloudprovider present")
}
if cloud.ProviderName() != gcecloud.ProviderName {
return nil, fmt.Errorf("Expected gce cloud got %s", cloud.ProviderName())
}
volumeLimits := map[string]int64{
util.GCEVolumeLimitKey: 16,
}
return volumeLimits, nil
}