2017-03-15 22:28:03 +00:00
|
|
|
/*
|
|
|
|
Copyright 2017 The Kubernetes Authors.
|
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
package gce
|
|
|
|
|
|
|
|
import (
|
2018-01-18 05:58:45 +00:00
|
|
|
"context"
|
2017-03-15 22:28:03 +00:00
|
|
|
|
|
|
|
compute "google.golang.org/api/compute/v1"
|
2018-01-18 05:58:45 +00:00
|
|
|
|
|
|
|
"k8s.io/kubernetes/pkg/cloudprovider/providers/gce/cloud/filter"
|
|
|
|
"k8s.io/kubernetes/pkg/cloudprovider/providers/gce/cloud/meta"
|
2017-03-15 22:28:03 +00:00
|
|
|
)
|
|
|
|
|
2017-04-12 18:57:20 +00:00
|
|
|
func newTargetProxyMetricContext(request string) *metricContext {
|
2017-08-22 23:13:46 +00:00
|
|
|
return newGenericMetricContext("targetproxy", request, unusedMetricLabel, unusedMetricLabel, computeV1Version)
|
2017-04-12 18:57:20 +00:00
|
|
|
}
|
2017-03-15 22:28:03 +00:00
|
|
|
|
|
|
|
// GetTargetHttpProxy returns the UrlMap by name.
|
|
|
|
func (gce *GCECloud) GetTargetHttpProxy(name string) (*compute.TargetHttpProxy, error) {
|
2017-05-05 01:04:34 +00:00
|
|
|
mc := newTargetProxyMetricContext("get")
|
2018-01-18 05:58:45 +00:00
|
|
|
v, err := gce.c.TargetHttpProxies().Get(context.Background(), meta.GlobalKey(name))
|
2017-05-05 01:04:34 +00:00
|
|
|
return v, mc.Observe(err)
|
2017-03-15 22:28:03 +00:00
|
|
|
}
|
|
|
|
|
2017-07-16 02:41:21 +00:00
|
|
|
// CreateTargetHttpProxy creates a TargetHttpProxy
|
|
|
|
func (gce *GCECloud) CreateTargetHttpProxy(proxy *compute.TargetHttpProxy) error {
|
2017-04-12 18:57:20 +00:00
|
|
|
mc := newTargetProxyMetricContext("create")
|
2018-01-18 05:58:45 +00:00
|
|
|
return mc.Observe(gce.c.TargetHttpProxies().Insert(context.Background(), meta.GlobalKey(proxy.Name), proxy))
|
2017-03-15 22:28:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// SetUrlMapForTargetHttpProxy sets the given UrlMap for the given TargetHttpProxy.
|
|
|
|
func (gce *GCECloud) SetUrlMapForTargetHttpProxy(proxy *compute.TargetHttpProxy, urlMap *compute.UrlMap) error {
|
2018-01-18 05:58:45 +00:00
|
|
|
ref := &compute.UrlMapReference{UrlMap: urlMap.SelfLink}
|
2017-04-12 18:57:20 +00:00
|
|
|
mc := newTargetProxyMetricContext("set_url_map")
|
2018-01-18 05:58:45 +00:00
|
|
|
return mc.Observe(gce.c.TargetHttpProxies().SetUrlMap(context.Background(), meta.GlobalKey(proxy.Name), ref))
|
2017-03-15 22:28:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// DeleteTargetHttpProxy deletes the TargetHttpProxy by name.
|
|
|
|
func (gce *GCECloud) DeleteTargetHttpProxy(name string) error {
|
2017-04-12 18:57:20 +00:00
|
|
|
mc := newTargetProxyMetricContext("delete")
|
2018-01-19 01:48:01 +00:00
|
|
|
return mc.Observe(gce.c.TargetHttpProxies().Delete(context.Background(), meta.GlobalKey(name)))
|
2017-03-15 22:28:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ListTargetHttpProxies lists all TargetHttpProxies in the project.
|
2018-01-18 05:58:45 +00:00
|
|
|
func (gce *GCECloud) ListTargetHttpProxies() ([]*compute.TargetHttpProxy, error) {
|
2017-05-05 01:04:34 +00:00
|
|
|
mc := newTargetProxyMetricContext("list")
|
2018-01-18 05:58:45 +00:00
|
|
|
v, err := gce.c.TargetHttpProxies().List(context.Background(), filter.None)
|
2017-05-05 01:04:34 +00:00
|
|
|
return v, mc.Observe(err)
|
2017-03-15 22:28:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// TargetHttpsProxy management
|
|
|
|
|
|
|
|
// GetTargetHttpsProxy returns the UrlMap by name.
|
|
|
|
func (gce *GCECloud) GetTargetHttpsProxy(name string) (*compute.TargetHttpsProxy, error) {
|
2017-05-05 01:04:34 +00:00
|
|
|
mc := newTargetProxyMetricContext("get")
|
2018-01-18 05:58:45 +00:00
|
|
|
v, err := gce.c.TargetHttpsProxies().Get(context.Background(), meta.GlobalKey(name))
|
2017-05-05 01:04:34 +00:00
|
|
|
return v, mc.Observe(err)
|
2017-03-15 22:28:03 +00:00
|
|
|
}
|
|
|
|
|
2017-07-16 02:41:21 +00:00
|
|
|
// CreateTargetHttpsProxy creates a TargetHttpsProxy
|
|
|
|
func (gce *GCECloud) CreateTargetHttpsProxy(proxy *compute.TargetHttpsProxy) error {
|
2017-05-05 01:04:34 +00:00
|
|
|
mc := newTargetProxyMetricContext("create")
|
2018-01-18 05:58:45 +00:00
|
|
|
return mc.Observe(gce.c.TargetHttpsProxies().Insert(context.Background(), meta.GlobalKey(proxy.Name), proxy))
|
2017-03-15 22:28:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// SetUrlMapForTargetHttpsProxy sets the given UrlMap for the given TargetHttpsProxy.
|
|
|
|
func (gce *GCECloud) SetUrlMapForTargetHttpsProxy(proxy *compute.TargetHttpsProxy, urlMap *compute.UrlMap) error {
|
2017-04-12 18:57:20 +00:00
|
|
|
mc := newTargetProxyMetricContext("set_url_map")
|
2018-01-18 05:58:45 +00:00
|
|
|
ref := &compute.UrlMapReference{UrlMap: urlMap.SelfLink}
|
|
|
|
return mc.Observe(gce.c.TargetHttpsProxies().SetUrlMap(context.Background(), meta.GlobalKey(proxy.Name), ref))
|
2017-03-15 22:28:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// SetSslCertificateForTargetHttpsProxy sets the given SslCertificate for the given TargetHttpsProxy.
|
2018-04-03 06:34:08 +00:00
|
|
|
func (gce *GCECloud) SetSslCertificateForTargetHttpsProxy(proxy *compute.TargetHttpsProxy, sslCerts []*compute.SslCertificate) error {
|
2017-04-12 18:57:20 +00:00
|
|
|
mc := newTargetProxyMetricContext("set_ssl_cert")
|
2018-04-03 06:34:08 +00:00
|
|
|
var allCerts []string
|
|
|
|
for _, cert := range sslCerts {
|
|
|
|
allCerts = append(allCerts, cert.SelfLink)
|
|
|
|
}
|
2018-01-18 05:58:45 +00:00
|
|
|
req := &compute.TargetHttpsProxiesSetSslCertificatesRequest{
|
2018-04-03 06:34:08 +00:00
|
|
|
SslCertificates: allCerts,
|
2017-03-15 22:28:03 +00:00
|
|
|
}
|
2018-01-18 05:58:45 +00:00
|
|
|
return mc.Observe(gce.c.TargetHttpsProxies().SetSslCertificates(context.Background(), meta.GlobalKey(proxy.Name), req))
|
2017-03-15 22:28:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// DeleteTargetHttpsProxy deletes the TargetHttpsProxy by name.
|
|
|
|
func (gce *GCECloud) DeleteTargetHttpsProxy(name string) error {
|
2017-04-12 18:57:20 +00:00
|
|
|
mc := newTargetProxyMetricContext("delete")
|
2018-01-19 01:48:01 +00:00
|
|
|
return mc.Observe(gce.c.TargetHttpsProxies().Delete(context.Background(), meta.GlobalKey(name)))
|
2017-03-15 22:28:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ListTargetHttpsProxies lists all TargetHttpsProxies in the project.
|
2018-01-18 05:58:45 +00:00
|
|
|
func (gce *GCECloud) ListTargetHttpsProxies() ([]*compute.TargetHttpsProxy, error) {
|
2017-05-05 01:04:34 +00:00
|
|
|
mc := newTargetProxyMetricContext("list")
|
2018-01-18 05:58:45 +00:00
|
|
|
v, err := gce.c.TargetHttpsProxies().List(context.Background(), filter.None)
|
2017-05-05 01:04:34 +00:00
|
|
|
return v, mc.Observe(err)
|
2017-03-15 22:28:03 +00:00
|
|
|
}
|