Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial cloud interface for DigitalOcean #3188

Merged
merged 2 commits into from
Aug 12, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions hack/.packages
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
24 changes: 21 additions & 3 deletions pkg/resources/digitalocean/cloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand All @@ -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")
Expand All @@ -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")
}
4 changes: 4 additions & 0 deletions upup/pkg/fi/cloudup/apply_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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:
Expand Down
42 changes: 42 additions & 0 deletions upup/pkg/fi/cloudup/do/api_target.go
Original file line number Diff line number Diff line change
@@ -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
}
26 changes: 26 additions & 0 deletions upup/pkg/fi/cloudup/do/cloud.go
Original file line number Diff line number Diff line change
@@ -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)
}