Skip to content

Commit

Permalink
Ensure volume GetCloudProvider code uses cloud config
Browse files Browse the repository at this point in the history
  • Loading branch information
saad-ali committed Apr 4, 2016
1 parent 1521aa8 commit e7b14e7
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 23 deletions.
28 changes: 17 additions & 11 deletions pkg/volume/aws_ebs/aws_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (
"time"

"github.com/golang/glog"
"k8s.io/kubernetes/pkg/cloudprovider"
"k8s.io/kubernetes/pkg/cloudprovider/providers/aws"
"k8s.io/kubernetes/pkg/util/keymutex"
"k8s.io/kubernetes/pkg/util/runtime"
Expand Down Expand Up @@ -108,7 +107,7 @@ func (util *AWSDiskUtil) DetachDisk(c *awsElasticBlockStoreUnmounter) error {
}

func (util *AWSDiskUtil) DeleteVolume(d *awsElasticBlockStoreDeleter) error {
cloud, err := getCloudProvider()
cloud, err := getCloudProvider(d.awsElasticBlockStore.plugin)
if err != nil {
return err
}
Expand All @@ -129,7 +128,7 @@ func (util *AWSDiskUtil) DeleteVolume(d *awsElasticBlockStoreDeleter) error {
// CreateVolume creates an AWS EBS volume.
// Returns: volumeID, volumeSizeGB, labels, error
func (util *AWSDiskUtil) CreateVolume(c *awsElasticBlockStoreProvisioner) (string, int, map[string]string, error) {
cloud, err := getCloudProvider()
cloud, err := getCloudProvider(c.awsElasticBlockStore.plugin)
if err != nil {
return "", 0, nil, err
}
Expand Down Expand Up @@ -175,7 +174,7 @@ func attachDiskAndVerify(b *awsElasticBlockStoreMounter, xvdBeforeSet sets.Strin
for numRetries := 0; numRetries < maxRetries; numRetries++ {
var err error
if awsCloud == nil {
awsCloud, err = getCloudProvider()
awsCloud, err = getCloudProvider(b.awsElasticBlockStore.plugin)
if err != nil || awsCloud == nil {
// Retry on error. See issue #11321
glog.Errorf("Error getting AWSCloudProvider while detaching PD %q: %v", b.volumeID, err)
Expand Down Expand Up @@ -250,7 +249,7 @@ func detachDiskAndVerify(c *awsElasticBlockStoreUnmounter) {
for numRetries := 0; numRetries < maxRetries; numRetries++ {
var err error
if awsCloud == nil {
awsCloud, err = getCloudProvider()
awsCloud, err = getCloudProvider(c.awsElasticBlockStore.plugin)
if err != nil || awsCloud == nil {
// Retry on error. See issue #11321
glog.Errorf("Error getting AWSCloudProvider while detaching PD %q: %v", c.volumeID, err)
Expand Down Expand Up @@ -348,12 +347,19 @@ func pathExists(path string) (bool, error) {
}

// Return cloud provider
func getCloudProvider() (*aws.AWSCloud, error) {
awsCloudProvider, err := cloudprovider.GetCloudProvider("aws", nil)
if err != nil || awsCloudProvider == nil {
return nil, err
func getCloudProvider(plugin *awsElasticBlockStorePlugin) (*aws.AWSCloud, error) {
if plugin == nil {
return nil, fmt.Errorf("Failed to get AWS Cloud Provider. plugin object is nil.")
}
if plugin.host == nil {
return nil, fmt.Errorf("Failed to get AWS Cloud Provider. plugin.host object is nil.")
}

cloudProvider := plugin.host.GetCloudProvider()
awsCloudProvider, ok := cloudProvider.(*aws.AWSCloud)
if !ok || awsCloudProvider == nil {
return nil, fmt.Errorf("Failed to get AWS Cloud Provider. plugin.host.GetCloudProvider returned %v instead", cloudProvider)
}

// The conversion must be safe otherwise bug in GetCloudProvider()
return awsCloudProvider.(*aws.AWSCloud), nil
return awsCloudProvider, nil
}
28 changes: 17 additions & 11 deletions pkg/volume/gce_pd/gce_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import (
"time"

"github.com/golang/glog"
"k8s.io/kubernetes/pkg/cloudprovider"
gcecloud "k8s.io/kubernetes/pkg/cloudprovider/providers/gce"
"k8s.io/kubernetes/pkg/util/exec"
"k8s.io/kubernetes/pkg/util/keymutex"
Expand Down Expand Up @@ -114,7 +113,7 @@ func (util *GCEDiskUtil) DetachDisk(c *gcePersistentDiskUnmounter) error {
}

func (util *GCEDiskUtil) DeleteVolume(d *gcePersistentDiskDeleter) error {
cloud, err := getCloudProvider()
cloud, err := getCloudProvider(d.gcePersistentDisk.plugin)
if err != nil {
return err
}
Expand All @@ -130,7 +129,7 @@ func (util *GCEDiskUtil) DeleteVolume(d *gcePersistentDiskDeleter) error {
// CreateVolume creates a GCE PD.
// Returns: volumeID, volumeSizeGB, labels, error
func (gceutil *GCEDiskUtil) CreateVolume(c *gcePersistentDiskProvisioner) (string, int, map[string]string, error) {
cloud, err := getCloudProvider()
cloud, err := getCloudProvider(c.gcePersistentDisk.plugin)
if err != nil {
return "", 0, nil, err
}
Expand Down Expand Up @@ -171,7 +170,7 @@ func attachDiskAndVerify(b *gcePersistentDiskMounter, sdBeforeSet sets.String) (
for numRetries := 0; numRetries < maxRetries; numRetries++ {
var err error
if gceCloud == nil {
gceCloud, err = getCloudProvider()
gceCloud, err = getCloudProvider(b.gcePersistentDisk.plugin)
if err != nil || gceCloud == nil {
// Retry on error. See issue #11321
glog.Errorf("Error getting GCECloudProvider while detaching PD %q: %v", b.pdName, err)
Expand Down Expand Up @@ -245,7 +244,7 @@ func detachDiskAndVerify(c *gcePersistentDiskUnmounter) {
for numRetries := 0; numRetries < maxRetries; numRetries++ {
var err error
if gceCloud == nil {
gceCloud, err = getCloudProvider()
gceCloud, err = getCloudProvider(c.gcePersistentDisk.plugin)
if err != nil || gceCloud == nil {
// Retry on error. See issue #11321
glog.Errorf("Error getting GCECloudProvider while detaching PD %q: %v", c.pdName, err)
Expand Down Expand Up @@ -342,14 +341,21 @@ func pathExists(path string) (bool, error) {
}

// Return cloud provider
func getCloudProvider() (*gcecloud.GCECloud, error) {
gceCloudProvider, err := cloudprovider.GetCloudProvider("gce", nil)
if err != nil || gceCloudProvider == nil {
return nil, err
func getCloudProvider(plugin *gcePersistentDiskPlugin) (*gcecloud.GCECloud, error) {
if plugin == nil {
return nil, fmt.Errorf("Failed to get GCE Cloud Provider. plugin object is nil.")
}
if plugin.host == nil {
return nil, fmt.Errorf("Failed to get GCE Cloud Provider. plugin.host object is nil.")
}

cloudProvider := plugin.host.GetCloudProvider()
gceCloudProvider, ok := cloudProvider.(*gcecloud.GCECloud)
if !ok || gceCloudProvider == nil {
return nil, fmt.Errorf("Failed to get GCE Cloud Provider. plugin.host.GetCloudProvider returned %v instead", cloudProvider)
}

// The conversion must be safe otherwise bug in GetCloudProvider()
return gceCloudProvider.(*gcecloud.GCECloud), nil
return gceCloudProvider, nil
}

// Calls "udevadm trigger --action=change" for newly created "/dev/sd*" drives (exist only in after set).
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/volume_provisioning.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ var _ = KubeDescribe("Dynamic provisioning", func() {

KubeDescribe("DynamicProvisioner", func() {
It("should create and delete persistent volumes", func() {
SkipUnlessProviderIs("openstack", "gce", "aws")
SkipUnlessProviderIs("openstack", "gce", "aws", "gke")
By("creating a claim with a dynamic provisioning annotation")
claim := createClaim(ns)
defer func() {
Expand Down

1 comment on commit e7b14e7

@k8s-teamcity-mesosphere

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TeamCity OSS :: Kubernetes Mesos :: 4 - Smoke Tests Build 20511 outcome was SUCCESS
Summary: Tests passed: 1, ignored: 267 Build time: 00:05:31

Please sign in to comment.