mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-25 12:43:23 +00:00
Update TargetProxy to use generated code
This commit is contained in:
parent
b682e1bc1e
commit
67c34edbb3
@ -17,9 +17,13 @@ limitations under the License.
|
|||||||
package gce
|
package gce
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
compute "google.golang.org/api/compute/v1"
|
compute "google.golang.org/api/compute/v1"
|
||||||
|
|
||||||
|
"k8s.io/kubernetes/pkg/cloudprovider/providers/gce/cloud/filter"
|
||||||
|
"k8s.io/kubernetes/pkg/cloudprovider/providers/gce/cloud/meta"
|
||||||
)
|
)
|
||||||
|
|
||||||
func newTargetProxyMetricContext(request string) *metricContext {
|
func newTargetProxyMetricContext(request string) *metricContext {
|
||||||
@ -29,49 +33,37 @@ func newTargetProxyMetricContext(request string) *metricContext {
|
|||||||
// GetTargetHttpProxy returns the UrlMap by name.
|
// GetTargetHttpProxy returns the UrlMap by name.
|
||||||
func (gce *GCECloud) GetTargetHttpProxy(name string) (*compute.TargetHttpProxy, error) {
|
func (gce *GCECloud) GetTargetHttpProxy(name string) (*compute.TargetHttpProxy, error) {
|
||||||
mc := newTargetProxyMetricContext("get")
|
mc := newTargetProxyMetricContext("get")
|
||||||
v, err := gce.service.TargetHttpProxies.Get(gce.projectID, name).Do()
|
v, err := gce.c.TargetHttpProxies().Get(context.Background(), meta.GlobalKey(name))
|
||||||
return v, mc.Observe(err)
|
return v, mc.Observe(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// CreateTargetHttpProxy creates a TargetHttpProxy
|
// CreateTargetHttpProxy creates a TargetHttpProxy
|
||||||
func (gce *GCECloud) CreateTargetHttpProxy(proxy *compute.TargetHttpProxy) error {
|
func (gce *GCECloud) CreateTargetHttpProxy(proxy *compute.TargetHttpProxy) error {
|
||||||
mc := newTargetProxyMetricContext("create")
|
mc := newTargetProxyMetricContext("create")
|
||||||
op, err := gce.service.TargetHttpProxies.Insert(gce.projectID, proxy).Do()
|
return mc.Observe(gce.c.TargetHttpProxies().Insert(context.Background(), meta.GlobalKey(proxy.Name), proxy))
|
||||||
if err != nil {
|
|
||||||
return mc.Observe(err)
|
|
||||||
}
|
|
||||||
return gce.waitForGlobalOp(op, mc)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetUrlMapForTargetHttpProxy sets the given UrlMap for the given TargetHttpProxy.
|
// SetUrlMapForTargetHttpProxy sets the given UrlMap for the given TargetHttpProxy.
|
||||||
func (gce *GCECloud) SetUrlMapForTargetHttpProxy(proxy *compute.TargetHttpProxy, urlMap *compute.UrlMap) error {
|
func (gce *GCECloud) SetUrlMapForTargetHttpProxy(proxy *compute.TargetHttpProxy, urlMap *compute.UrlMap) error {
|
||||||
|
ref := &compute.UrlMapReference{UrlMap: urlMap.SelfLink}
|
||||||
mc := newTargetProxyMetricContext("set_url_map")
|
mc := newTargetProxyMetricContext("set_url_map")
|
||||||
op, err := gce.service.TargetHttpProxies.SetUrlMap(
|
return mc.Observe(gce.c.TargetHttpProxies().SetUrlMap(context.Background(), meta.GlobalKey(proxy.Name), ref))
|
||||||
gce.projectID, proxy.Name, &compute.UrlMapReference{UrlMap: urlMap.SelfLink}).Do()
|
|
||||||
if err != nil {
|
|
||||||
return mc.Observe(err)
|
|
||||||
}
|
|
||||||
return gce.waitForGlobalOp(op, mc)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// DeleteTargetHttpProxy deletes the TargetHttpProxy by name.
|
// DeleteTargetHttpProxy deletes the TargetHttpProxy by name.
|
||||||
func (gce *GCECloud) DeleteTargetHttpProxy(name string) error {
|
func (gce *GCECloud) DeleteTargetHttpProxy(name string) error {
|
||||||
mc := newTargetProxyMetricContext("delete")
|
mc := newTargetProxyMetricContext("delete")
|
||||||
op, err := gce.service.TargetHttpProxies.Delete(gce.projectID, name).Do()
|
err := gce.c.TargetHttpProxies().Delete(context.Background(), meta.GlobalKey(name))
|
||||||
if err != nil {
|
|
||||||
if isHTTPErrorCode(err, http.StatusNotFound) {
|
if isHTTPErrorCode(err, http.StatusNotFound) {
|
||||||
return nil
|
err = nil
|
||||||
}
|
}
|
||||||
return mc.Observe(err)
|
return mc.Observe(err)
|
||||||
}
|
}
|
||||||
return gce.waitForGlobalOp(op, mc)
|
|
||||||
}
|
|
||||||
|
|
||||||
// ListTargetHttpProxies lists all TargetHttpProxies in the project.
|
// ListTargetHttpProxies lists all TargetHttpProxies in the project.
|
||||||
func (gce *GCECloud) ListTargetHttpProxies() (*compute.TargetHttpProxyList, error) {
|
func (gce *GCECloud) ListTargetHttpProxies() ([]*compute.TargetHttpProxy, error) {
|
||||||
mc := newTargetProxyMetricContext("list")
|
mc := newTargetProxyMetricContext("list")
|
||||||
// TODO: use PageToken to list all not just the first 500
|
v, err := gce.c.TargetHttpProxies().List(context.Background(), filter.None)
|
||||||
v, err := gce.service.TargetHttpProxies.List(gce.projectID).Do()
|
|
||||||
return v, mc.Observe(err)
|
return v, mc.Observe(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -80,59 +72,45 @@ func (gce *GCECloud) ListTargetHttpProxies() (*compute.TargetHttpProxyList, erro
|
|||||||
// GetTargetHttpsProxy returns the UrlMap by name.
|
// GetTargetHttpsProxy returns the UrlMap by name.
|
||||||
func (gce *GCECloud) GetTargetHttpsProxy(name string) (*compute.TargetHttpsProxy, error) {
|
func (gce *GCECloud) GetTargetHttpsProxy(name string) (*compute.TargetHttpsProxy, error) {
|
||||||
mc := newTargetProxyMetricContext("get")
|
mc := newTargetProxyMetricContext("get")
|
||||||
v, err := gce.service.TargetHttpsProxies.Get(gce.projectID, name).Do()
|
v, err := gce.c.TargetHttpsProxies().Get(context.Background(), meta.GlobalKey(name))
|
||||||
return v, mc.Observe(err)
|
return v, mc.Observe(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// CreateTargetHttpsProxy creates a TargetHttpsProxy
|
// CreateTargetHttpsProxy creates a TargetHttpsProxy
|
||||||
func (gce *GCECloud) CreateTargetHttpsProxy(proxy *compute.TargetHttpsProxy) error {
|
func (gce *GCECloud) CreateTargetHttpsProxy(proxy *compute.TargetHttpsProxy) error {
|
||||||
mc := newTargetProxyMetricContext("create")
|
mc := newTargetProxyMetricContext("create")
|
||||||
op, err := gce.service.TargetHttpsProxies.Insert(gce.projectID, proxy).Do()
|
return mc.Observe(gce.c.TargetHttpsProxies().Insert(context.Background(), meta.GlobalKey(proxy.Name), proxy))
|
||||||
if err != nil {
|
|
||||||
return mc.Observe(err)
|
|
||||||
}
|
|
||||||
return gce.waitForGlobalOp(op, mc)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetUrlMapForTargetHttpsProxy sets the given UrlMap for the given TargetHttpsProxy.
|
// SetUrlMapForTargetHttpsProxy sets the given UrlMap for the given TargetHttpsProxy.
|
||||||
func (gce *GCECloud) SetUrlMapForTargetHttpsProxy(proxy *compute.TargetHttpsProxy, urlMap *compute.UrlMap) error {
|
func (gce *GCECloud) SetUrlMapForTargetHttpsProxy(proxy *compute.TargetHttpsProxy, urlMap *compute.UrlMap) error {
|
||||||
mc := newTargetProxyMetricContext("set_url_map")
|
mc := newTargetProxyMetricContext("set_url_map")
|
||||||
op, err := gce.service.TargetHttpsProxies.SetUrlMap(
|
ref := &compute.UrlMapReference{UrlMap: urlMap.SelfLink}
|
||||||
gce.projectID, proxy.Name, &compute.UrlMapReference{UrlMap: urlMap.SelfLink}).Do()
|
return mc.Observe(gce.c.TargetHttpsProxies().SetUrlMap(context.Background(), meta.GlobalKey(proxy.Name), ref))
|
||||||
if err != nil {
|
|
||||||
return mc.Observe(err)
|
|
||||||
}
|
|
||||||
return gce.waitForGlobalOp(op, mc)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetSslCertificateForTargetHttpsProxy sets the given SslCertificate for the given TargetHttpsProxy.
|
// SetSslCertificateForTargetHttpsProxy sets the given SslCertificate for the given TargetHttpsProxy.
|
||||||
func (gce *GCECloud) SetSslCertificateForTargetHttpsProxy(proxy *compute.TargetHttpsProxy, sslCert *compute.SslCertificate) error {
|
func (gce *GCECloud) SetSslCertificateForTargetHttpsProxy(proxy *compute.TargetHttpsProxy, sslCert *compute.SslCertificate) error {
|
||||||
mc := newTargetProxyMetricContext("set_ssl_cert")
|
mc := newTargetProxyMetricContext("set_ssl_cert")
|
||||||
op, err := gce.service.TargetHttpsProxies.SetSslCertificates(
|
req := &compute.TargetHttpsProxiesSetSslCertificatesRequest{
|
||||||
gce.projectID, proxy.Name, &compute.TargetHttpsProxiesSetSslCertificatesRequest{SslCertificates: []string{sslCert.SelfLink}}).Do()
|
SslCertificates: []string{sslCert.SelfLink},
|
||||||
if err != nil {
|
|
||||||
return mc.Observe(err)
|
|
||||||
}
|
}
|
||||||
return gce.waitForGlobalOp(op, mc)
|
return mc.Observe(gce.c.TargetHttpsProxies().SetSslCertificates(context.Background(), meta.GlobalKey(proxy.Name), req))
|
||||||
}
|
}
|
||||||
|
|
||||||
// DeleteTargetHttpsProxy deletes the TargetHttpsProxy by name.
|
// DeleteTargetHttpsProxy deletes the TargetHttpsProxy by name.
|
||||||
func (gce *GCECloud) DeleteTargetHttpsProxy(name string) error {
|
func (gce *GCECloud) DeleteTargetHttpsProxy(name string) error {
|
||||||
mc := newTargetProxyMetricContext("delete")
|
mc := newTargetProxyMetricContext("delete")
|
||||||
op, err := gce.service.TargetHttpsProxies.Delete(gce.projectID, name).Do()
|
err := gce.c.TargetHttpsProxies().Delete(context.Background(), meta.GlobalKey(name))
|
||||||
if err != nil {
|
|
||||||
if isHTTPErrorCode(err, http.StatusNotFound) {
|
if isHTTPErrorCode(err, http.StatusNotFound) {
|
||||||
return nil
|
err = nil
|
||||||
}
|
}
|
||||||
return mc.Observe(err)
|
return mc.Observe(err)
|
||||||
}
|
}
|
||||||
return gce.waitForGlobalOp(op, mc)
|
|
||||||
}
|
|
||||||
|
|
||||||
// ListTargetHttpsProxies lists all TargetHttpsProxies in the project.
|
// ListTargetHttpsProxies lists all TargetHttpsProxies in the project.
|
||||||
func (gce *GCECloud) ListTargetHttpsProxies() (*compute.TargetHttpsProxyList, error) {
|
func (gce *GCECloud) ListTargetHttpsProxies() ([]*compute.TargetHttpsProxy, error) {
|
||||||
mc := newTargetProxyMetricContext("list")
|
mc := newTargetProxyMetricContext("list")
|
||||||
// TODO: use PageToken to list all not just the first 500
|
v, err := gce.c.TargetHttpsProxies().List(context.Background(), filter.None)
|
||||||
v, err := gce.service.TargetHttpsProxies.List(gce.projectID).Do()
|
|
||||||
return v, mc.Observe(err)
|
return v, mc.Observe(err)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user