Merge pull request #3188 from andrewsykim/docloud

Automatic merge from submit-queue

Initial cloud interface for DigitalOcean

Just setup code for DigitalOcean and trying to keep my PRs as small as possible. Upcoming PRs will include tasks to create droplets, block storage (for etcd), etc.
This commit is contained in:
Kubernetes Submit Queue 2017-08-12 07:36:35 -07:00 committed by GitHub
commit 96c6050597
5 changed files with 94 additions and 3 deletions

View File

@ -100,6 +100,7 @@ k8s.io/kops/upup/pkg/fi/cloudup/awstasks
k8s.io/kops/upup/pkg/fi/cloudup/awsup
k8s.io/kops/upup/pkg/fi/cloudup/cloudformation
k8s.io/kops/upup/pkg/fi/cloudup/dnstasks
k8s.io/kops/upup/pkg/fi/cloudup/do
k8s.io/kops/upup/pkg/fi/cloudup/gce
k8s.io/kops/upup/pkg/fi/cloudup/gcetasks
k8s.io/kops/upup/pkg/fi/cloudup/terraform

View File

@ -22,7 +22,10 @@ import (
"github.com/digitalocean/godo"
"golang.org/x/oauth2"
"k8s.io/kops/pkg/apis/kops"
"k8s.io/kops/pkg/resources/digitalocean/dns"
"k8s.io/kops/upup/pkg/fi"
"k8s.io/kubernetes/federation/pkg/dnsprovider"
)
@ -43,13 +46,17 @@ func (t *TokenSource) Token() (*oauth2.Token, error) {
type Cloud struct {
client *godo.Client
dns dnsprovider.Interface
Region string
tags map[string]string
}
var _ fi.Cloud = &Cloud{}
// NewCloud returns a Cloud, expecting the env var DO_ACCESS_TOKEN
// NewCloud will return an err if DO_ACCESS_TOKEN is not defined
func NewCloud() (*Cloud, error) {
func NewCloud(region string) (*Cloud, error) {
accessToken := os.Getenv("DO_ACCESS_TOKEN")
if accessToken == "" {
return nil, errors.New("DO_ACCESS_TOKEN is required")
@ -64,11 +71,22 @@ func NewCloud() (*Cloud, error) {
return &Cloud{
client: client,
dns: dns.NewProvider(client),
Region: region,
}, nil
}
// ProviderID returns the kops api identifier for DigitalOcean cloud provider
func (c *Cloud) ProviderID() kops.CloudProviderID {
return kops.CloudProviderDO
}
// DNS returns a DO implementation for dnsprovider.Interface
func (c *Cloud) DNS() (dnsprovider.Interface, error) {
provider := dns.NewProvider(c.client)
return provider, nil
return c.dns, nil
}
// FindVPCInfo is not implemented, it's only here to satisfy the fi.Cloud interface
func (c *Cloud) FindVPCInfo(id string) (*fi.VPCInfo, error) {
return nil, errors.New("not implemented")
}

View File

@ -38,12 +38,14 @@ import (
"k8s.io/kops/pkg/model/components"
"k8s.io/kops/pkg/model/gcemodel"
"k8s.io/kops/pkg/model/vspheremodel"
"k8s.io/kops/pkg/resources/digitalocean"
"k8s.io/kops/pkg/templates"
"k8s.io/kops/upup/models"
"k8s.io/kops/upup/pkg/fi"
"k8s.io/kops/upup/pkg/fi/cloudup/awstasks"
"k8s.io/kops/upup/pkg/fi/cloudup/awsup"
"k8s.io/kops/upup/pkg/fi/cloudup/cloudformation"
"k8s.io/kops/upup/pkg/fi/cloudup/do"
"k8s.io/kops/upup/pkg/fi/cloudup/gce"
"k8s.io/kops/upup/pkg/fi/cloudup/gcetasks"
"k8s.io/kops/upup/pkg/fi/cloudup/terraform"
@ -690,6 +692,8 @@ func (c *ApplyClusterCmd) Run() error {
target = gce.NewGCEAPITarget(cloud.(*gce.GCECloud))
case "aws":
target = awsup.NewAWSAPITarget(cloud.(awsup.AWSCloud))
case "digitalocean":
target = do.NewDOAPITarget(cloud.(*digitalocean.Cloud))
case "vsphere":
target = vsphere.NewVSphereAPITarget(cloud.(*vsphere.VSphereCloud))
default:

View File

@ -0,0 +1,42 @@
/*
Copyright 2016 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package do
import (
"k8s.io/kops/pkg/resources/digitalocean"
"k8s.io/kops/upup/pkg/fi"
)
type DOAPITarget struct {
Cloud *digitalocean.Cloud
}
var _ fi.Target = &DOAPITarget{}
func NewDOAPITarget(cloud *digitalocean.Cloud) *DOAPITarget {
return &DOAPITarget{
Cloud: cloud,
}
}
func (t *DOAPITarget) Finish(taskMap map[string]fi.Task) error {
return nil
}
func (t *DOAPITarget) ProcessDeletions() bool {
return true
}

View File

@ -0,0 +1,26 @@
/*
Copyright 2016 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package do
import (
"k8s.io/kops/pkg/resources/digitalocean"
"k8s.io/kops/upup/pkg/fi"
)
func NewDOCloud(region string) (fi.Cloud, error) {
return digitalocean.NewCloud(region)
}