diff --git a/pkg/cloudprovider/providers/gce/gce_backendservice.go b/pkg/cloudprovider/providers/gce/gce_backendservice.go index 7bf3d73e0d8..f5f5c4e114e 100644 --- a/pkg/cloudprovider/providers/gce/gce_backendservice.go +++ b/pkg/cloudprovider/providers/gce/gce_backendservice.go @@ -19,11 +19,16 @@ package gce import ( "net/http" + computealpha "google.golang.org/api/compute/v0.alpha" compute "google.golang.org/api/compute/v1" ) func newBackendServiceMetricContext(request, region string) *metricContext { - return newGenericMetricContext("backendservice", request, region, unusedMetricLabel, computeV1Version) + return newBackendServiceMetricContextWithVersion(request, region, computeV1Version) +} + +func newBackendServiceMetricContextWithVersion(request, region, version string) *metricContext { + return newGenericMetricContext("backendservice", request, region, unusedMetricLabel, version) } // GetGlobalBackendService retrieves a backend by name. @@ -44,6 +49,17 @@ func (gce *GCECloud) UpdateGlobalBackendService(bg *compute.BackendService) erro return gce.waitForGlobalOp(op, mc) } +// UpdateAlphaGlobalBackendService applies the given alpha BackendService as an update to an existing service. +func (gce *GCECloud) UpdateAlphaGlobalBackendService(bg *computealpha.BackendService) error { + mc := newBackendServiceMetricContextWithVersion("update", "", computeAlphaVersion) + op, err := gce.serviceAlpha.BackendServices.Update(gce.projectID, bg.Name, bg).Do() + if err != nil { + return mc.Observe(err) + } + + return gce.waitForGlobalOp(op, mc) +} + // DeleteGlobalBackendService deletes the given BackendService by name. func (gce *GCECloud) DeleteGlobalBackendService(name string) error { mc := newBackendServiceMetricContext("delete", "") @@ -69,6 +85,17 @@ func (gce *GCECloud) CreateGlobalBackendService(bg *compute.BackendService) erro return gce.waitForGlobalOp(op, mc) } +// CreateAlphaGlobalBackendService creates the given alpha BackendService. +func (gce *GCECloud) CreateAlphaGlobalBackendService(bg *computealpha.BackendService) error { + mc := newBackendServiceMetricContextWithVersion("create", "", computeAlphaVersion) + op, err := gce.serviceAlpha.BackendServices.Insert(gce.projectID, bg).Do() + if err != nil { + return mc.Observe(err) + } + + return gce.waitForGlobalOp(op, mc) +} + // ListGlobalBackendServices lists all backend services in the project. func (gce *GCECloud) ListGlobalBackendServices() (*compute.BackendServiceList, error) { mc := newBackendServiceMetricContext("list", "") diff --git a/pkg/cloudprovider/providers/gce/gce_healthchecks.go b/pkg/cloudprovider/providers/gce/gce_healthchecks.go index 85f077f0007..7c71f5ae391 100644 --- a/pkg/cloudprovider/providers/gce/gce_healthchecks.go +++ b/pkg/cloudprovider/providers/gce/gce_healthchecks.go @@ -22,6 +22,7 @@ import ( utilversion "k8s.io/kubernetes/pkg/util/version" "github.com/golang/glog" + computealpha "google.golang.org/api/compute/v0.alpha" compute "google.golang.org/api/compute/v1" ) @@ -43,7 +44,11 @@ func init() { } func newHealthcheckMetricContext(request string) *metricContext { - return newGenericMetricContext("healthcheck", request, unusedMetricLabel, unusedMetricLabel, computeV1Version) + return newHealthcheckMetricContextWithVersion(request, computeV1Version) +} + +func newHealthcheckMetricContextWithVersion(request, version string) *metricContext { + return newGenericMetricContext("healthcheck", request, unusedMetricLabel, unusedMetricLabel, version) } // GetHttpHealthCheck returns the given HttpHealthCheck by name. @@ -155,6 +160,13 @@ func (gce *GCECloud) GetHealthCheck(name string) (*compute.HealthCheck, error) { return v, mc.Observe(err) } +// GetAlphaHealthCheck returns the given alpha HealthCheck by name. +func (gce *GCECloud) GetAlphaHealthCheck(name string) (*computealpha.HealthCheck, error) { + mc := newHealthcheckMetricContextWithVersion("get", computeAlphaVersion) + v, err := gce.serviceAlpha.HealthChecks.Get(gce.projectID, name).Do() + return v, mc.Observe(err) +} + // UpdateHealthCheck applies the given HealthCheck as an update. func (gce *GCECloud) UpdateHealthCheck(hc *compute.HealthCheck) error { mc := newHealthcheckMetricContext("update") @@ -166,6 +178,17 @@ func (gce *GCECloud) UpdateHealthCheck(hc *compute.HealthCheck) error { return gce.waitForGlobalOp(op, mc) } +// UpdateAlphaHealthCheck applies the given alpha HealthCheck as an update. +func (gce *GCECloud) UpdateAlphaHealthCheck(hc *computealpha.HealthCheck) error { + mc := newHealthcheckMetricContextWithVersion("update", computeAlphaVersion) + op, err := gce.serviceAlpha.HealthChecks.Update(gce.projectID, hc.Name, hc).Do() + if err != nil { + return mc.Observe(err) + } + + return gce.waitForGlobalOp(op, mc) +} + // DeleteHealthCheck deletes the given HealthCheck by name. func (gce *GCECloud) DeleteHealthCheck(name string) error { mc := newHealthcheckMetricContext("delete") @@ -188,6 +211,17 @@ func (gce *GCECloud) CreateHealthCheck(hc *compute.HealthCheck) error { return gce.waitForGlobalOp(op, mc) } +// CreateAlphaHealthCheck creates the given alpha HealthCheck. +func (gce *GCECloud) CreateAlphaHealthCheck(hc *computealpha.HealthCheck) error { + mc := newHealthcheckMetricContextWithVersion("create", computeAlphaVersion) + op, err := gce.serviceAlpha.HealthChecks.Insert(gce.projectID, hc).Do() + if err != nil { + return mc.Observe(err) + } + + return gce.waitForGlobalOp(op, mc) +} + // ListHealthChecks lists all HealthCheck in the project. func (gce *GCECloud) ListHealthChecks() (*compute.HealthCheckList, error) { mc := newHealthcheckMetricContext("list")