Commit ab3d36b9 authored by Kubernetes Submit Queue's avatar Kubernetes Submit Queue Committed by GitHub

Merge pull request #48989 from nicksardo/gce-api-changes

Automatic merge from submit-queue (batch tested with PRs 49081, 49318, 49219, 48989, 48486) GCE: Remove resource Get function calls from Create functions **What this PR does / why we need it**: Consistency. This PR removes the GetXXX from the CreateXXX functions of the GCE cloudprovider. Consumers (specifically the ingress controller) will need to call the Get resource funcs separately when updating their vendored versions. **Release note**: ```release-note NONE ``` /assign @bowei
parents e87f809d 9b29f42f
...@@ -29,27 +29,14 @@ func newForwardingRuleMetricContext(request, region string) *metricContext { ...@@ -29,27 +29,14 @@ func newForwardingRuleMetricContext(request, region string) *metricContext {
} }
} }
// CreateGlobalForwardingRule creates and returns a // CreateGlobalForwardingRule creates the passed GlobalForwardingRule
// GlobalForwardingRule that points to the given TargetHttp(s)Proxy. func (gce *GCECloud) CreateGlobalForwardingRule(rule *compute.ForwardingRule) error {
// targetProxyLink is the SelfLink of a TargetHttp(s)Proxy.
func (gce *GCECloud) CreateGlobalForwardingRule(targetProxyLink, ip, name, portRange string) (*compute.ForwardingRule, error) {
mc := newForwardingRuleMetricContext("create", "") mc := newForwardingRuleMetricContext("create", "")
rule := &compute.ForwardingRule{
Name: name,
IPAddress: ip,
Target: targetProxyLink,
PortRange: portRange,
IPProtocol: "TCP",
}
op, err := gce.service.GlobalForwardingRules.Insert(gce.projectID, rule).Do() op, err := gce.service.GlobalForwardingRules.Insert(gce.projectID, rule).Do()
if err != nil { if err != nil {
return nil, mc.Observe(err) return mc.Observe(err)
}
if err = gce.waitForGlobalOp(op, mc); err != nil {
return nil, err
} }
return gce.waitForGlobalOp(op, mc)
return gce.GetGlobalForwardingRule(name)
} }
// SetProxyForGlobalForwardingRule links the given TargetHttp(s)Proxy with the given GlobalForwardingRule. // SetProxyForGlobalForwardingRule links the given TargetHttp(s)Proxy with the given GlobalForwardingRule.
......
...@@ -31,20 +31,14 @@ func newInstanceGroupMetricContext(request string, zone string) *metricContext { ...@@ -31,20 +31,14 @@ func newInstanceGroupMetricContext(request string, zone string) *metricContext {
// CreateInstanceGroup creates an instance group with the given // CreateInstanceGroup creates an instance group with the given
// instances. It is the callers responsibility to add named ports. // instances. It is the callers responsibility to add named ports.
func (gce *GCECloud) CreateInstanceGroup(name string, zone string) (*compute.InstanceGroup, error) { func (gce *GCECloud) CreateInstanceGroup(ig *compute.InstanceGroup, zone string) error {
mc := newInstanceGroupMetricContext("create", zone) mc := newInstanceGroupMetricContext("create", zone)
op, err := gce.service.InstanceGroups.Insert( op, err := gce.service.InstanceGroups.Insert(gce.projectID, zone, ig).Do()
gce.projectID, zone, &compute.InstanceGroup{Name: name}).Do()
if err != nil { if err != nil {
mc.Observe(err) return mc.Observe(err)
return nil, err
}
if err = gce.waitForZoneOp(op, zone, mc); err != nil {
return nil, err
} }
return gce.GetInstanceGroup(name, zone) return gce.waitForZoneOp(op, zone, mc)
} }
// DeleteInstanceGroup deletes an instance group. // DeleteInstanceGroup deletes an instance group.
......
...@@ -494,7 +494,7 @@ func (gce *GCECloud) createTargetPool(name, serviceName, ipAddress, region, clus ...@@ -494,7 +494,7 @@ func (gce *GCECloud) createTargetPool(name, serviceName, ipAddress, region, clus
HealthChecks: hcLinks, HealthChecks: hcLinks,
} }
if _, err := gce.CreateTargetPool(pool, region); err != nil && !isHTTPErrorCode(err, http.StatusConflict) { if err := gce.CreateTargetPool(pool, region); err != nil && !isHTTPErrorCode(err, http.StatusConflict) {
return err return err
} }
return nil return nil
......
...@@ -376,7 +376,12 @@ func (gce *GCECloud) ensureInternalInstanceGroup(name, zone string, nodes []*v1. ...@@ -376,7 +376,12 @@ func (gce *GCECloud) ensureInternalInstanceGroup(name, zone string, nodes []*v1.
gceNodes := sets.NewString() gceNodes := sets.NewString()
if ig == nil { if ig == nil {
glog.V(2).Infof("ensureInternalInstanceGroup(%v, %v): creating instance group", name, zone) glog.V(2).Infof("ensureInternalInstanceGroup(%v, %v): creating instance group", name, zone)
ig, err = gce.CreateInstanceGroup(name, zone) newIG := &compute.InstanceGroup{Name: name}
if err = gce.CreateInstanceGroup(newIG, zone); err != nil {
return "", err
}
ig, err = gce.GetInstanceGroup(name, zone)
if err != nil { if err != nil {
return "", err return "", err
} }
......
...@@ -37,18 +37,14 @@ func (gce *GCECloud) GetTargetPool(name, region string) (*compute.TargetPool, er ...@@ -37,18 +37,14 @@ func (gce *GCECloud) GetTargetPool(name, region string) (*compute.TargetPool, er
} }
// CreateTargetPool creates the passed TargetPool // CreateTargetPool creates the passed TargetPool
func (gce *GCECloud) CreateTargetPool(tp *compute.TargetPool, region string) (*compute.TargetPool, error) { func (gce *GCECloud) CreateTargetPool(tp *compute.TargetPool, region string) error {
mc := newTargetPoolMetricContext("create", region) mc := newTargetPoolMetricContext("create", region)
op, err := gce.service.TargetPools.Insert(gce.projectID, region, tp).Do() op, err := gce.service.TargetPools.Insert(gce.projectID, region, tp).Do()
if err != nil { if err != nil {
return nil, mc.Observe(err) return mc.Observe(err)
}
if err := gce.waitForRegionOp(op, region, mc); err != nil {
return nil, err
} }
return gce.GetTargetPool(tp.Name, region) return gce.waitForRegionOp(op, region, mc)
} }
// DeleteTargetPool deletes TargetPool by name. // DeleteTargetPool deletes TargetPool by name.
......
...@@ -37,22 +37,14 @@ func (gce *GCECloud) GetTargetHttpProxy(name string) (*compute.TargetHttpProxy, ...@@ -37,22 +37,14 @@ func (gce *GCECloud) GetTargetHttpProxy(name string) (*compute.TargetHttpProxy,
return v, mc.Observe(err) return v, mc.Observe(err)
} }
// CreateTargetHttpProxy creates and returns a TargetHttpProxy with the given UrlMap. // CreateTargetHttpProxy creates a TargetHttpProxy
func (gce *GCECloud) CreateTargetHttpProxy(urlMap *compute.UrlMap, name string) (*compute.TargetHttpProxy, error) { func (gce *GCECloud) CreateTargetHttpProxy(proxy *compute.TargetHttpProxy) error {
proxy := &compute.TargetHttpProxy{
Name: name,
UrlMap: urlMap.SelfLink,
}
mc := newTargetProxyMetricContext("create") mc := newTargetProxyMetricContext("create")
op, err := gce.service.TargetHttpProxies.Insert(gce.projectID, proxy).Do() op, err := gce.service.TargetHttpProxies.Insert(gce.projectID, proxy).Do()
if err != nil { if err != nil {
return nil, mc.Observe(err) return mc.Observe(err)
}
if err = gce.waitForGlobalOp(op, mc); err != nil {
return nil, err
} }
return gce.GetTargetHttpProxy(name) return gce.waitForGlobalOp(op, mc)
} }
// SetUrlMapForTargetHttpProxy sets the given UrlMap for the given TargetHttpProxy. // SetUrlMapForTargetHttpProxy sets the given UrlMap for the given TargetHttpProxy.
...@@ -96,22 +88,14 @@ func (gce *GCECloud) GetTargetHttpsProxy(name string) (*compute.TargetHttpsProxy ...@@ -96,22 +88,14 @@ func (gce *GCECloud) GetTargetHttpsProxy(name string) (*compute.TargetHttpsProxy
return v, mc.Observe(err) return v, mc.Observe(err)
} }
// CreateTargetHttpsProxy creates and returns a TargetHttpsProxy with the given UrlMap and SslCertificate. // CreateTargetHttpsProxy creates a TargetHttpsProxy
func (gce *GCECloud) CreateTargetHttpsProxy(urlMap *compute.UrlMap, sslCert *compute.SslCertificate, name string) (*compute.TargetHttpsProxy, error) { func (gce *GCECloud) CreateTargetHttpsProxy(proxy *compute.TargetHttpsProxy) error {
mc := newTargetProxyMetricContext("create") mc := newTargetProxyMetricContext("create")
proxy := &compute.TargetHttpsProxy{
Name: name,
UrlMap: urlMap.SelfLink,
SslCertificates: []string{sslCert.SelfLink},
}
op, err := gce.service.TargetHttpsProxies.Insert(gce.projectID, proxy).Do() op, err := gce.service.TargetHttpsProxies.Insert(gce.projectID, proxy).Do()
if err != nil { if err != nil {
return nil, mc.Observe(err) return mc.Observe(err)
}
if err = gce.waitForGlobalOp(op, mc); err != nil {
return nil, err
} }
return gce.GetTargetHttpsProxy(name) return gce.waitForGlobalOp(op, mc)
} }
// SetUrlMapForTargetHttpsProxy sets the given UrlMap for the given TargetHttpsProxy. // SetUrlMapForTargetHttpsProxy sets the given UrlMap for the given TargetHttpsProxy.
......
...@@ -37,34 +37,24 @@ func (gce *GCECloud) GetUrlMap(name string) (*compute.UrlMap, error) { ...@@ -37,34 +37,24 @@ func (gce *GCECloud) GetUrlMap(name string) (*compute.UrlMap, error) {
return v, mc.Observe(err) return v, mc.Observe(err)
} }
// CreateUrlMap creates an url map, using the given backend service as the default service. // CreateUrlMap creates a url map
func (gce *GCECloud) CreateUrlMap(backend *compute.BackendService, name string) (*compute.UrlMap, error) { func (gce *GCECloud) CreateUrlMap(urlMap *compute.UrlMap) error {
urlMap := &compute.UrlMap{
Name: name,
DefaultService: backend.SelfLink,
}
mc := newUrlMapMetricContext("create") mc := newUrlMapMetricContext("create")
op, err := gce.service.UrlMaps.Insert(gce.projectID, urlMap).Do() op, err := gce.service.UrlMaps.Insert(gce.projectID, urlMap).Do()
if err != nil { if err != nil {
return nil, mc.Observe(err) return mc.Observe(err)
}
if err = gce.waitForGlobalOp(op, mc); err != nil {
return nil, err
} }
return gce.GetUrlMap(name) return gce.waitForGlobalOp(op, mc)
} }
// UpdateUrlMap applies the given UrlMap as an update, and returns the new UrlMap. // UpdateUrlMap applies the given UrlMap as an update
func (gce *GCECloud) UpdateUrlMap(urlMap *compute.UrlMap) (*compute.UrlMap, error) { func (gce *GCECloud) UpdateUrlMap(urlMap *compute.UrlMap) error {
mc := newUrlMapMetricContext("update") mc := newUrlMapMetricContext("update")
op, err := gce.service.UrlMaps.Update(gce.projectID, urlMap.Name, urlMap).Do() op, err := gce.service.UrlMaps.Update(gce.projectID, urlMap.Name, urlMap).Do()
if err != nil { if err != nil {
return nil, mc.Observe(err) return mc.Observe(err)
}
if err = gce.waitForGlobalOp(op, mc); err != nil {
return nil, err
} }
return gce.service.UrlMaps.Get(gce.projectID, urlMap.Name).Do() return gce.waitForGlobalOp(op, mc)
} }
// DeleteUrlMap deletes a url map by name. // DeleteUrlMap deletes a url map by name.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment