forked from kubernetes/kops
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gce_cloud.go
65 lines (51 loc) · 1.58 KB
/
gce_cloud.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package gce
import (
"fmt"
"golang.org/x/net/context"
"golang.org/x/oauth2/google"
"google.golang.org/api/compute/v1"
"google.golang.org/api/storage/v1"
"k8s.io/kops/upup/pkg/fi"
"k8s.io/kubernetes/federation/pkg/dnsprovider"
"k8s.io/kubernetes/federation/pkg/dnsprovider/providers/google/clouddns"
)
type GCECloud struct {
Compute *compute.Service
Storage *storage.Service
Region string
Project string
//tags map[string]string
}
var _ fi.Cloud = &GCECloud{}
func (c *GCECloud) ProviderID() fi.CloudProviderID {
return fi.CloudProviderGCE
}
func NewGCECloud(region string, project string) (*GCECloud, error) {
c := &GCECloud{Region: region, Project: project}
ctx := context.Background()
client, err := google.DefaultClient(ctx, compute.ComputeScope)
if err != nil {
return nil, fmt.Errorf("error building google API client: %v", err)
}
computeService, err := compute.New(client)
if err != nil {
return nil, fmt.Errorf("error building compute API client: %v", err)
}
c.Compute = computeService
storageService, err := storage.New(client)
if err != nil {
return nil, fmt.Errorf("error building storage API client: %v", err)
}
c.Storage = storageService
return c, nil
}
func (c *GCECloud) FindDNSHostedZone(clusterDNSName string) (string, error) {
return "", fmt.Errorf("FindDNSHostedZone not yet implemented on GCE")
}
func (c *GCECloud) DNS() (dnsprovider.Interface, error) {
provider, err := dnsprovider.GetDnsProvider(clouddns.ProviderName, nil)
if err != nil {
return nil, fmt.Errorf("Error building (k8s) DNS provider: %v", err)
}
return provider, nil
}