Update gce cloud calls after api changes
This commit is contained in:
parent
9b22796383
commit
8dc3d4764f
6 changed files with 76 additions and 53 deletions
|
@ -81,10 +81,11 @@ func (f *FakeInstanceGroups) GetInstanceGroup(name, zone string) (*compute.Insta
|
||||||
}
|
}
|
||||||
|
|
||||||
// CreateInstanceGroup fakes instance group creation.
|
// CreateInstanceGroup fakes instance group creation.
|
||||||
func (f *FakeInstanceGroups) CreateInstanceGroup(name, zone string) (*compute.InstanceGroup, error) {
|
func (f *FakeInstanceGroups) CreateInstanceGroup(ig *compute.InstanceGroup, zone string) error {
|
||||||
newGroup := &compute.InstanceGroup{Name: name, SelfLink: name, Zone: zone}
|
ig.SelfLink = ig.Name
|
||||||
f.instanceGroups = append(f.instanceGroups, newGroup)
|
ig.Zone = zone
|
||||||
return newGroup, nil
|
f.instanceGroups = append(f.instanceGroups, ig)
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// DeleteInstanceGroup fakes instance group deletion.
|
// DeleteInstanceGroup fakes instance group deletion.
|
||||||
|
|
|
@ -77,7 +77,10 @@ func (i *Instances) AddInstanceGroup(name string, port int64) ([]*compute.Instan
|
||||||
var err error
|
var err error
|
||||||
if ig == nil {
|
if ig == nil {
|
||||||
glog.Infof("Creating instance group %v in zone %v", name, zone)
|
glog.Infof("Creating instance group %v in zone %v", name, zone)
|
||||||
ig, err = i.cloud.CreateInstanceGroup(name, zone)
|
if err = i.cloud.CreateInstanceGroup(&compute.InstanceGroup{Name: name}, zone); err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
ig, err = i.cloud.GetInstanceGroup(name, zone)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,7 +45,7 @@ type NodePool interface {
|
||||||
// InstanceGroups is an interface for managing gce instances groups, and the instances therein.
|
// InstanceGroups is an interface for managing gce instances groups, and the instances therein.
|
||||||
type InstanceGroups interface {
|
type InstanceGroups interface {
|
||||||
GetInstanceGroup(name, zone string) (*compute.InstanceGroup, error)
|
GetInstanceGroup(name, zone string) (*compute.InstanceGroup, error)
|
||||||
CreateInstanceGroup(name, zone string) (*compute.InstanceGroup, error)
|
CreateInstanceGroup(ig *compute.InstanceGroup, zone string) error
|
||||||
DeleteInstanceGroup(name, zone string) error
|
DeleteInstanceGroup(name, zone string) error
|
||||||
|
|
||||||
// TODO: Refactor for modulatiry.
|
// TODO: Refactor for modulatiry.
|
||||||
|
|
|
@ -114,21 +114,14 @@ func (f *FakeLoadBalancers) GetGlobalForwardingRule(name string) (*compute.Forwa
|
||||||
}
|
}
|
||||||
|
|
||||||
// CreateGlobalForwardingRule fakes forwarding rule creation.
|
// CreateGlobalForwardingRule fakes forwarding rule creation.
|
||||||
func (f *FakeLoadBalancers) CreateGlobalForwardingRule(proxyLink, ip, name, portRange string) (*compute.ForwardingRule, error) {
|
func (f *FakeLoadBalancers) CreateGlobalForwardingRule(rule *compute.ForwardingRule) error {
|
||||||
f.calls = append(f.calls, "CreateGlobalForwardingRule")
|
f.calls = append(f.calls, "CreateGlobalForwardingRule")
|
||||||
if ip == "" {
|
if rule.IPAddress == "" {
|
||||||
ip = fmt.Sprintf(testIPManager.ip())
|
rule.IPAddress = fmt.Sprintf(testIPManager.ip())
|
||||||
}
|
|
||||||
rule := &compute.ForwardingRule{
|
|
||||||
Name: name,
|
|
||||||
IPAddress: ip,
|
|
||||||
Target: proxyLink,
|
|
||||||
PortRange: portRange,
|
|
||||||
IPProtocol: "TCP",
|
|
||||||
SelfLink: name,
|
|
||||||
}
|
}
|
||||||
|
rule.SelfLink = rule.Name
|
||||||
f.Fw = append(f.Fw, rule)
|
f.Fw = append(f.Fw, rule)
|
||||||
return rule, nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetProxyForGlobalForwardingRule fakes setting a global forwarding rule.
|
// SetProxyForGlobalForwardingRule fakes setting a global forwarding rule.
|
||||||
|
@ -181,27 +174,23 @@ func (f *FakeLoadBalancers) GetUrlMap(name string) (*compute.UrlMap, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// CreateUrlMap fakes url-map creation.
|
// CreateUrlMap fakes url-map creation.
|
||||||
func (f *FakeLoadBalancers) CreateUrlMap(backend *compute.BackendService, name string) (*compute.UrlMap, error) {
|
func (f *FakeLoadBalancers) CreateUrlMap(urlMap *compute.UrlMap) error {
|
||||||
f.calls = append(f.calls, "CreateUrlMap")
|
f.calls = append(f.calls, "CreateUrlMap")
|
||||||
urlMap := &compute.UrlMap{
|
urlMap.SelfLink = f.umName()
|
||||||
Name: name,
|
|
||||||
DefaultService: backend.SelfLink,
|
|
||||||
SelfLink: f.umName(),
|
|
||||||
}
|
|
||||||
f.Um = append(f.Um, urlMap)
|
f.Um = append(f.Um, urlMap)
|
||||||
return urlMap, nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// UpdateUrlMap fakes updating url-maps.
|
// UpdateUrlMap fakes updating url-maps.
|
||||||
func (f *FakeLoadBalancers) UpdateUrlMap(urlMap *compute.UrlMap) (*compute.UrlMap, error) {
|
func (f *FakeLoadBalancers) UpdateUrlMap(urlMap *compute.UrlMap) error {
|
||||||
f.calls = append(f.calls, "UpdateUrlMap")
|
f.calls = append(f.calls, "UpdateUrlMap")
|
||||||
for i := range f.Um {
|
for i := range f.Um {
|
||||||
if f.Um[i].Name == urlMap.Name {
|
if f.Um[i].Name == urlMap.Name {
|
||||||
f.Um[i] = urlMap
|
f.Um[i] = urlMap
|
||||||
return urlMap, nil
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil, nil
|
return fmt.Errorf("url map %v not found", urlMap.Name)
|
||||||
}
|
}
|
||||||
|
|
||||||
// DeleteUrlMap fakes url-map deletion.
|
// DeleteUrlMap fakes url-map deletion.
|
||||||
|
@ -231,15 +220,11 @@ func (f *FakeLoadBalancers) GetTargetHttpProxy(name string) (*compute.TargetHttp
|
||||||
}
|
}
|
||||||
|
|
||||||
// CreateTargetHttpProxy fakes creating a target http proxy.
|
// CreateTargetHttpProxy fakes creating a target http proxy.
|
||||||
func (f *FakeLoadBalancers) CreateTargetHttpProxy(urlMap *compute.UrlMap, name string) (*compute.TargetHttpProxy, error) {
|
func (f *FakeLoadBalancers) CreateTargetHttpProxy(proxy *compute.TargetHttpProxy) error {
|
||||||
f.calls = append(f.calls, "CreateTargetHttpProxy")
|
f.calls = append(f.calls, "CreateTargetHttpProxy")
|
||||||
proxy := &compute.TargetHttpProxy{
|
proxy.SelfLink = proxy.Name
|
||||||
Name: name,
|
|
||||||
UrlMap: urlMap.SelfLink,
|
|
||||||
SelfLink: name,
|
|
||||||
}
|
|
||||||
f.Tp = append(f.Tp, proxy)
|
f.Tp = append(f.Tp, proxy)
|
||||||
return proxy, nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// DeleteTargetHttpProxy fakes deleting a target http proxy.
|
// DeleteTargetHttpProxy fakes deleting a target http proxy.
|
||||||
|
@ -280,16 +265,11 @@ func (f *FakeLoadBalancers) GetTargetHttpsProxy(name string) (*compute.TargetHtt
|
||||||
}
|
}
|
||||||
|
|
||||||
// CreateTargetHttpsProxy fakes creating a target http proxy.
|
// CreateTargetHttpsProxy fakes creating a target http proxy.
|
||||||
func (f *FakeLoadBalancers) CreateTargetHttpsProxy(urlMap *compute.UrlMap, cert *compute.SslCertificate, name string) (*compute.TargetHttpsProxy, error) {
|
func (f *FakeLoadBalancers) CreateTargetHttpsProxy(proxy *compute.TargetHttpsProxy) error {
|
||||||
f.calls = append(f.calls, "CreateTargetHttpsProxy")
|
f.calls = append(f.calls, "CreateTargetHttpsProxy")
|
||||||
proxy := &compute.TargetHttpsProxy{
|
proxy.SelfLink = proxy.Name
|
||||||
Name: name,
|
|
||||||
UrlMap: urlMap.SelfLink,
|
|
||||||
SslCertificates: []string{cert.SelfLink},
|
|
||||||
SelfLink: name,
|
|
||||||
}
|
|
||||||
f.Tps = append(f.Tps, proxy)
|
f.Tps = append(f.Tps, proxy)
|
||||||
return proxy, nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// DeleteTargetHttpsProxy fakes deleting a target http proxy.
|
// DeleteTargetHttpsProxy fakes deleting a target http proxy.
|
||||||
|
|
|
@ -28,25 +28,25 @@ import (
|
||||||
type LoadBalancers interface {
|
type LoadBalancers interface {
|
||||||
// Forwarding Rules
|
// Forwarding Rules
|
||||||
GetGlobalForwardingRule(name string) (*compute.ForwardingRule, error)
|
GetGlobalForwardingRule(name string) (*compute.ForwardingRule, error)
|
||||||
CreateGlobalForwardingRule(proxyLink, ip, name, portRange string) (*compute.ForwardingRule, error)
|
CreateGlobalForwardingRule(rule *compute.ForwardingRule) error
|
||||||
DeleteGlobalForwardingRule(name string) error
|
DeleteGlobalForwardingRule(name string) error
|
||||||
SetProxyForGlobalForwardingRule(fw, proxy string) error
|
SetProxyForGlobalForwardingRule(fw, proxy string) error
|
||||||
|
|
||||||
// UrlMaps
|
// UrlMaps
|
||||||
GetUrlMap(name string) (*compute.UrlMap, error)
|
GetUrlMap(name string) (*compute.UrlMap, error)
|
||||||
CreateUrlMap(backend *compute.BackendService, name string) (*compute.UrlMap, error)
|
CreateUrlMap(urlMap *compute.UrlMap) error
|
||||||
UpdateUrlMap(urlMap *compute.UrlMap) (*compute.UrlMap, error)
|
UpdateUrlMap(urlMap *compute.UrlMap) error
|
||||||
DeleteUrlMap(name string) error
|
DeleteUrlMap(name string) error
|
||||||
|
|
||||||
// TargetProxies
|
// TargetProxies
|
||||||
GetTargetHttpProxy(name string) (*compute.TargetHttpProxy, error)
|
GetTargetHttpProxy(name string) (*compute.TargetHttpProxy, error)
|
||||||
CreateTargetHttpProxy(urlMap *compute.UrlMap, name string) (*compute.TargetHttpProxy, error)
|
CreateTargetHttpProxy(proxy *compute.TargetHttpProxy) error
|
||||||
DeleteTargetHttpProxy(name string) error
|
DeleteTargetHttpProxy(name string) error
|
||||||
SetUrlMapForTargetHttpProxy(proxy *compute.TargetHttpProxy, urlMap *compute.UrlMap) error
|
SetUrlMapForTargetHttpProxy(proxy *compute.TargetHttpProxy, urlMap *compute.UrlMap) error
|
||||||
|
|
||||||
// TargetHttpsProxies
|
// TargetHttpsProxies
|
||||||
GetTargetHttpsProxy(name string) (*compute.TargetHttpsProxy, error)
|
GetTargetHttpsProxy(name string) (*compute.TargetHttpsProxy, error)
|
||||||
CreateTargetHttpsProxy(urlMap *compute.UrlMap, SSLCerts *compute.SslCertificate, name string) (*compute.TargetHttpsProxy, error)
|
CreateTargetHttpsProxy(proxy *compute.TargetHttpsProxy) error
|
||||||
DeleteTargetHttpsProxy(name string) error
|
DeleteTargetHttpsProxy(name string) error
|
||||||
SetUrlMapForTargetHttpsProxy(proxy *compute.TargetHttpsProxy, urlMap *compute.UrlMap) error
|
SetUrlMapForTargetHttpsProxy(proxy *compute.TargetHttpsProxy, urlMap *compute.UrlMap) error
|
||||||
SetSslCertificateForTargetHttpsProxy(proxy *compute.TargetHttpsProxy, SSLCerts *compute.SslCertificate) error
|
SetSslCertificateForTargetHttpsProxy(proxy *compute.TargetHttpsProxy, SSLCerts *compute.SslCertificate) error
|
||||||
|
|
|
@ -309,7 +309,14 @@ func (l *L7) checkUrlMap(backend *compute.BackendService) (err error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
glog.Infof("Creating url map %v for backend %v", urlMapName, l.glbcDefaultBackend.Name)
|
glog.Infof("Creating url map %v for backend %v", urlMapName, l.glbcDefaultBackend.Name)
|
||||||
urlMap, err = l.cloud.CreateUrlMap(l.glbcDefaultBackend, urlMapName)
|
newUrlMap := &compute.UrlMap{
|
||||||
|
Name: urlMapName,
|
||||||
|
DefaultService: l.glbcDefaultBackend.SelfLink,
|
||||||
|
}
|
||||||
|
if err = l.cloud.CreateUrlMap(newUrlMap); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
urlMap, err = l.cloud.GetUrlMap(urlMapName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -325,7 +332,14 @@ func (l *L7) checkProxy() (err error) {
|
||||||
proxy, _ := l.cloud.GetTargetHttpProxy(proxyName)
|
proxy, _ := l.cloud.GetTargetHttpProxy(proxyName)
|
||||||
if proxy == nil {
|
if proxy == nil {
|
||||||
glog.Infof("Creating new http proxy for urlmap %v", l.um.Name)
|
glog.Infof("Creating new http proxy for urlmap %v", l.um.Name)
|
||||||
proxy, err = l.cloud.CreateTargetHttpProxy(l.um, proxyName)
|
newProxy := &compute.TargetHttpProxy{
|
||||||
|
Name: proxyName,
|
||||||
|
UrlMap: l.um.SelfLink,
|
||||||
|
}
|
||||||
|
if err = l.cloud.CreateTargetHttpProxy(newProxy); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
proxy, err = l.cloud.GetTargetHttpProxy(proxyName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -493,10 +507,20 @@ func (l *L7) checkHttpsProxy() (err error) {
|
||||||
proxy, _ := l.cloud.GetTargetHttpsProxy(proxyName)
|
proxy, _ := l.cloud.GetTargetHttpsProxy(proxyName)
|
||||||
if proxy == nil {
|
if proxy == nil {
|
||||||
glog.Infof("Creating new https proxy for urlmap %v", l.um.Name)
|
glog.Infof("Creating new https proxy for urlmap %v", l.um.Name)
|
||||||
proxy, err = l.cloud.CreateTargetHttpsProxy(l.um, l.sslCert, proxyName)
|
newProxy := &compute.TargetHttpsProxy{
|
||||||
|
Name: proxyName,
|
||||||
|
UrlMap: l.um.SelfLink,
|
||||||
|
SslCertificates: []string{l.sslCert.SelfLink},
|
||||||
|
}
|
||||||
|
if err = l.cloud.CreateTargetHttpsProxy(newProxy); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
proxy, err = l.cloud.GetTargetHttpsProxy(proxyName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
l.tps = proxy
|
l.tps = proxy
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -533,7 +557,17 @@ func (l *L7) checkForwardingRule(name, proxyLink, ip, portRange string) (fw *com
|
||||||
if fw == nil {
|
if fw == nil {
|
||||||
parts := strings.Split(proxyLink, "/")
|
parts := strings.Split(proxyLink, "/")
|
||||||
glog.Infof("Creating forwarding rule for proxy %v and ip %v:%v", parts[len(parts)-1:], ip, portRange)
|
glog.Infof("Creating forwarding rule for proxy %v and ip %v:%v", parts[len(parts)-1:], ip, portRange)
|
||||||
fw, err = l.cloud.CreateGlobalForwardingRule(proxyLink, ip, name, portRange)
|
rule := &compute.ForwardingRule{
|
||||||
|
Name: name,
|
||||||
|
IPAddress: ip,
|
||||||
|
Target: proxyLink,
|
||||||
|
PortRange: portRange,
|
||||||
|
IPProtocol: "TCP",
|
||||||
|
}
|
||||||
|
if err = l.cloud.CreateGlobalForwardingRule(rule); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
fw, err = l.cloud.GetGlobalForwardingRule(name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -817,10 +851,15 @@ func (l *L7) UpdateUrlMap(ingressRules utils.GCEURLMap) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
glog.V(3).Infof("Updating URLMap: %q", l.Name)
|
glog.V(3).Infof("Updating URLMap: %q", l.Name)
|
||||||
um, err := l.cloud.UpdateUrlMap(l.um)
|
if err := l.cloud.UpdateUrlMap(l.um); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
um, err := l.cloud.GetUrlMap(l.um.Name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
l.um = um
|
l.um = um
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue