Skip to content

Commit

Permalink
Merge pull request #35 from skriss/server_config_validation
Browse files Browse the repository at this point in the history
validate cloud-provider config at startup & make PVProvider optional
  • Loading branch information
ncdc authored Aug 14, 2017
2 parents a865cb8 + 726bbbb commit c088470
Show file tree
Hide file tree
Showing 10 changed files with 653 additions and 7 deletions.
5 changes: 5 additions & 0 deletions Godeps/Godeps.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 16 additions & 1 deletion pkg/cloudprovider/aws/storage_adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ limitations under the License.
package aws

import (
"fmt"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/ec2"
Expand All @@ -42,9 +44,22 @@ func NewStorageAdapter(config *aws.Config, availabilityZone string, kmsKeyID str
return nil, err
}

// validate the availabilityZone
var (
ec2Client = ec2.New(sess)
azReq = &ec2.DescribeAvailabilityZonesInput{ZoneNames: []*string{&availabilityZone}}
)
res, err := ec2Client.DescribeAvailabilityZones(azReq)
if err != nil {
return nil, err
}
if len(res.AvailabilityZones) == 0 {
return nil, fmt.Errorf("availability zone %q not found", availabilityZone)
}

return &storageAdapter{
blockStorage: &blockStorageAdapter{
ec2: ec2.New(sess),
ec2: ec2Client,
az: availabilityZone,
},
objectStorage: &objectStorageAdapter{
Expand Down
27 changes: 27 additions & 0 deletions pkg/cloudprovider/azure/storage_adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,14 @@ limitations under the License.
package azure

import (
"errors"
"fmt"
"os"
"time"

"github.com/Azure/azure-sdk-for-go/arm/disk"
"github.com/Azure/azure-sdk-for-go/arm/examples/helpers"
"github.com/Azure/azure-sdk-for-go/arm/resources/subscriptions"
"github.com/Azure/azure-sdk-for-go/storage"
"github.com/Azure/go-autorest/autorest/azure"

Expand Down Expand Up @@ -79,6 +81,31 @@ func NewStorageAdapter(location string, apiTimeout time.Duration) (cloudprovider
apiTimeout = time.Minute
}

// validate the location
groupClient := subscriptions.NewGroupClient()
groupClient.Authorizer = spt

locs, err := groupClient.ListLocations(cfg[azureSubscriptionIDKey])
if err != nil {
return nil, err
}

if locs.Value == nil {
return nil, errors.New("no locations returned from Azure API")
}

locationExists := false
for _, loc := range *locs.Value {
if (loc.Name != nil && *loc.Name == location) || (loc.DisplayName != nil && *loc.DisplayName == location) {
locationExists = true
break
}
}

if !locationExists {
return nil, fmt.Errorf("location %q not found", location)
}

return &storageAdapter{
objectStorage: &objectStorageAdapter{
blobClient: &blobClient,
Expand Down
4 changes: 1 addition & 3 deletions pkg/cloudprovider/gcp/object_storage_adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,7 @@ import (
)

type objectStorageAdapter struct {
project string
zone string
gcs *storage.Service
gcs *storage.Service
}

var _ cloudprovider.ObjectStorageAdapter = &objectStorageAdapter{}
Expand Down
16 changes: 13 additions & 3 deletions pkg/cloudprovider/gcp/storage_adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ limitations under the License.
package gcp

import (
"fmt"

"golang.org/x/oauth2"
"golang.org/x/oauth2/google"
"google.golang.org/api/compute/v0.beta"
Expand Down Expand Up @@ -44,16 +46,24 @@ func NewStorageAdapter(project string, zone string) (cloudprovider.StorageAdapte
return nil, err
}

// validate project & zone
res, err := gce.Zones.Get(project, zone).Do()
if err != nil {
return nil, err
}

if res == nil {
return nil, fmt.Errorf("zone %q not found for project %q", project, zone)
}

gcs, err := storage.New(client)
if err != nil {
return nil, err
}

return &storageAdapter{
objectStorage: &objectStorageAdapter{
gcs: gcs,
project: project,
zone: zone,
gcs: gcs,
},
blockStorage: &blockStorageAdapter{
gce: gce,
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit c088470

Please sign in to comment.