mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-02 00:07:50 +00:00
Update UrlMap to use generated code
This commit is contained in:
parent
dc9dd59a45
commit
fa3e0af5ac
@ -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 newUrlMapMetricContext(request string) *metricContext {
|
func newUrlMapMetricContext(request string) *metricContext {
|
||||||
@ -29,47 +33,35 @@ func newUrlMapMetricContext(request string) *metricContext {
|
|||||||
// GetUrlMap returns the UrlMap by name.
|
// GetUrlMap returns the UrlMap by name.
|
||||||
func (gce *GCECloud) GetUrlMap(name string) (*compute.UrlMap, error) {
|
func (gce *GCECloud) GetUrlMap(name string) (*compute.UrlMap, error) {
|
||||||
mc := newUrlMapMetricContext("get")
|
mc := newUrlMapMetricContext("get")
|
||||||
v, err := gce.service.UrlMaps.Get(gce.projectID, name).Do()
|
v, err := gce.c.UrlMaps().Get(context.Background(), meta.GlobalKey(name))
|
||||||
return v, mc.Observe(err)
|
return v, mc.Observe(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// CreateUrlMap creates a url map
|
// CreateUrlMap creates a url map
|
||||||
func (gce *GCECloud) CreateUrlMap(urlMap *compute.UrlMap) error {
|
func (gce *GCECloud) CreateUrlMap(urlMap *compute.UrlMap) error {
|
||||||
mc := newUrlMapMetricContext("create")
|
mc := newUrlMapMetricContext("create")
|
||||||
op, err := gce.service.UrlMaps.Insert(gce.projectID, urlMap).Do()
|
return mc.Observe(gce.c.UrlMaps().Insert(context.Background(), meta.GlobalKey(urlMap.Name), urlMap))
|
||||||
if err != nil {
|
|
||||||
return mc.Observe(err)
|
|
||||||
}
|
|
||||||
return gce.waitForGlobalOp(op, mc)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// UpdateUrlMap applies the given UrlMap as an update
|
// UpdateUrlMap applies the given UrlMap as an update
|
||||||
func (gce *GCECloud) UpdateUrlMap(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()
|
return mc.Observe(gce.c.UrlMaps().Update(context.Background(), meta.GlobalKey(urlMap.Name), urlMap))
|
||||||
if err != nil {
|
|
||||||
return mc.Observe(err)
|
|
||||||
}
|
|
||||||
return gce.waitForGlobalOp(op, mc)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// DeleteUrlMap deletes a url map by name.
|
// DeleteUrlMap deletes a url map by name.
|
||||||
func (gce *GCECloud) DeleteUrlMap(name string) error {
|
func (gce *GCECloud) DeleteUrlMap(name string) error {
|
||||||
mc := newUrlMapMetricContext("delete")
|
mc := newUrlMapMetricContext("delete")
|
||||||
op, err := gce.service.UrlMaps.Delete(gce.projectID, name).Do()
|
err := gce.c.UrlMaps().Delete(context.Background(), meta.GlobalKey(name))
|
||||||
if err != nil {
|
if isHTTPErrorCode(err, http.StatusNotFound) {
|
||||||
if isHTTPErrorCode(err, http.StatusNotFound) {
|
err = nil
|
||||||
return nil
|
|
||||||
}
|
|
||||||
return mc.Observe(err)
|
|
||||||
}
|
}
|
||||||
return gce.waitForGlobalOp(op, mc)
|
return mc.Observe(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ListUrlMaps lists all UrlMaps in the project.
|
// ListUrlMaps lists all UrlMaps in the project.
|
||||||
func (gce *GCECloud) ListUrlMaps() (*compute.UrlMapList, error) {
|
func (gce *GCECloud) ListUrlMaps() ([]*compute.UrlMap, error) {
|
||||||
mc := newUrlMapMetricContext("list")
|
mc := newUrlMapMetricContext("list")
|
||||||
// TODO: use PageToken to list all not just the first 500
|
v, err := gce.c.UrlMaps().List(context.Background(), filter.None)
|
||||||
v, err := gce.service.UrlMaps.List(gce.projectID).Do()
|
|
||||||
return v, mc.Observe(err)
|
return v, mc.Observe(err)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user