Skip to content

Commit

Permalink
Merge pull request #362 from freehan/vendor-cloud
Browse files Browse the repository at this point in the history
Revendor GCE go client, cloud provider and fixes to make it work
  • Loading branch information
bowei authored Jun 25, 2018
2 parents 230c102 + a633b05 commit 7931e59
Show file tree
Hide file tree
Showing 76 changed files with 57,574 additions and 27,723 deletions.
14 changes: 7 additions & 7 deletions pkg/backends/backends.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (

"github.com/golang/glog"

computealpha "google.golang.org/api/compute/v0.alpha"
computebeta "google.golang.org/api/compute/v0.beta"
compute "google.golang.org/api/compute/v1"

v1 "k8s.io/api/core/v1"
Expand Down Expand Up @@ -450,10 +450,10 @@ func getBackendsForIGs(igLinks []string, bm BalancingMode) []*composite.Backend
return backends
}

func getBackendsForNEGs(negs []*computealpha.NetworkEndpointGroup) []*computealpha.Backend {
var backends []*computealpha.Backend
func getBackendsForNEGs(negs []*computebeta.NetworkEndpointGroup) []*computebeta.Backend {
var backends []*computebeta.Backend
for _, neg := range negs {
b := &computealpha.Backend{
b := &computebeta.Backend{
Group: neg.SelfLink,
BalancingMode: string(Rate),
MaxRatePerEndpoint: maxRPS,
Expand Down Expand Up @@ -543,7 +543,7 @@ func (b *Backends) Link(sp utils.ServicePort, zones []string) error {
return nil
}
negName := sp.BackendName(b.namer)
var negs []*computealpha.NetworkEndpointGroup
var negs []*computebeta.NetworkEndpointGroup
var err error
for _, zone := range zones {
neg, err := b.negGetter.GetNetworkEndpointGroup(negName, zone)
Expand All @@ -554,7 +554,7 @@ func (b *Backends) Link(sp utils.ServicePort, zones []string) error {
}

beName := sp.BackendName(b.namer)
backendService, err := b.cloud.GetAlphaGlobalBackendService(beName)
backendService, err := b.cloud.GetBetaGlobalBackendService(beName)
if err != nil {
return err
}
Expand All @@ -574,7 +574,7 @@ func (b *Backends) Link(sp utils.ServicePort, zones []string) error {

if !oldBackends.Equal(newBackends) {
backendService.Backends = targetBackends
return b.cloud.UpdateAlphaGlobalBackendService(backendService)
return b.cloud.UpdateBetaGlobalBackendService(backendService)
}
return nil
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/backends/backends_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
"strings"
"testing"

computealpha "google.golang.org/api/compute/v0.alpha"
computebeta "google.golang.org/api/compute/v0.beta"
compute "google.golang.org/api/compute/v1"
"google.golang.org/api/googleapi"
api_v1 "k8s.io/api/core/v1"
Expand Down Expand Up @@ -845,7 +845,7 @@ func TestLinkBackendServiceToNEG(t *testing.T) {
bp := NewBackendPool(fakeGCE, fakeNEG, healthChecks, nodePool, defaultNamer, false, false)

// Add standard hooks for mocking update calls. Each test can set a update different hook if it chooses to.
(fakeGCE.Compute().(*cloud.MockGCE)).MockAlphaBackendServices.UpdateHook = mock.UpdateAlphaBackendServiceHook
(fakeGCE.Compute().(*cloud.MockGCE)).MockBetaBackendServices.UpdateHook = mock.UpdateBetaBackendServiceHook
(fakeGCE.Compute().(*cloud.MockGCE)).MockBackendServices.UpdateHook = mock.UpdateBackendServiceHook

svcPort := utils.ServicePort{
Expand All @@ -866,7 +866,7 @@ func TestLinkBackendServiceToNEG(t *testing.T) {
}

for _, zone := range zones {
err := fakeNEG.CreateNetworkEndpointGroup(&computealpha.NetworkEndpointGroup{
err := fakeNEG.CreateNetworkEndpointGroup(&computebeta.NetworkEndpointGroup{
Name: defaultNamer.NEG(namespace, name, svcPort.Port),
}, zone)
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions pkg/backends/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ limitations under the License.
package backends

import (
computealpha "google.golang.org/api/compute/v0.alpha"
computebeta "google.golang.org/api/compute/v0.beta"
api_v1 "k8s.io/api/core/v1"
"k8s.io/ingress-gce/pkg/composite"
"k8s.io/ingress-gce/pkg/utils"
Expand Down Expand Up @@ -45,5 +45,5 @@ type BackendPool interface {

// NEGGetter is an interface to retrieve NEG object
type NEGGetter interface {
GetNetworkEndpointGroup(name string, zone string) (*computealpha.NetworkEndpointGroup, error)
GetNetworkEndpointGroup(name string, zone string) (*computebeta.NetworkEndpointGroup, error)
}
21 changes: 15 additions & 6 deletions pkg/composite/composite.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,12 +173,21 @@ type Backend struct {
}

type BackendServiceIAP struct {
Enabled bool `json:"enabled,omitempty"`
Oauth2ClientId string `json:"oauth2ClientId,omitempty"`
Oauth2ClientSecret string `json:"oauth2ClientSecret,omitempty"`
Oauth2ClientSecretSha256 string `json:"oauth2ClientSecretSha256,omitempty"`
ForceSendFields []string `json:"-"`
NullFields []string `json:"-"`
Enabled bool `json:"enabled,omitempty"`
Oauth2ClientId string `json:"oauth2ClientId,omitempty"`
Oauth2ClientSecret string `json:"oauth2ClientSecret,omitempty"`
Oauth2ClientSecretSha256 string `json:"oauth2ClientSecretSha256,omitempty"`
ForceSendFields []string `json:"-"`
NullFields []string `json:"-"`
Oauth2ClientInfo *BackendServiceIAPOAuth2ClientInfo `json:"oauth2ClientInfo,omitempty"`
}

type BackendServiceIAPOAuth2ClientInfo struct {
ApplicationName string `json:"applicationName,omitempty"`
ClientName string `json:"clientName,omitempty"`
DeveloperEmailAddress string `json:"developerEmailAddress,omitempty"`
ForceSendFields []string `json:"-"`
NullFields []string `json:"-"`
}

type BackendServiceCdnPolicy struct {
Expand Down
10 changes: 9 additions & 1 deletion pkg/composite/composite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,14 @@ func TestBackendServiceIAP(t *testing.T) {
}
}

func TestBackendServiceIAPOAuth2ClientInfo(t *testing.T) {
compositeType := reflect.TypeOf(BackendServiceIAPOAuth2ClientInfo{})
alphaType := reflect.TypeOf(computealpha.BackendServiceIAPOAuth2ClientInfo{})
if err := typeEquality(compositeType, alphaType); err != nil {
t.Fatal(err)
}
}

func TestBackendServiceCdnPolicy(t *testing.T) {
compositeType := reflect.TypeOf(BackendServiceCdnPolicy{})
alphaType := reflect.TypeOf(computealpha.BackendServiceCdnPolicy{})
Expand Down Expand Up @@ -190,7 +198,7 @@ func typeEquality(t1, t2 reflect.Type) error {
if !reflect.DeepEqual(t1Fields, t2Fields) {
return fmt.Errorf("type = %+v, want %+v", t1Fields, t2Fields)
}
for n, _ := range t1Fields {
for n := range t1Fields {
f1, _ := t1.FieldByName(n)
f2, _ := t2.FieldByName(n)
if err := compareFields(f1, f2); err != nil {
Expand Down
8 changes: 4 additions & 4 deletions pkg/loadbalancers/fakes.go
Original file line number Diff line number Diff line change
Expand Up @@ -277,11 +277,11 @@ func (f *FakeLoadBalancers) DeleteTargetHttpProxy(name string) error {
}

// SetUrlMapForTargetHttpProxy fakes setting an url-map for a target http proxy.
func (f *FakeLoadBalancers) SetUrlMapForTargetHttpProxy(proxy *compute.TargetHttpProxy, urlMap *compute.UrlMap) error {
func (f *FakeLoadBalancers) SetUrlMapForTargetHttpProxy(proxy *compute.TargetHttpProxy, urlMapLink string) error {
f.calls = append(f.calls, "SetUrlMapForTargetHttpProxy")
for i := range f.Tp {
if f.Tp[i].Name == proxy.Name {
f.Tp[i].UrlMap = urlMap.SelfLink
f.Tp[i].UrlMap = urlMapLink
}
}
return nil
Expand Down Expand Up @@ -326,11 +326,11 @@ func (f *FakeLoadBalancers) DeleteTargetHttpsProxy(name string) error {
}

// SetUrlMapForTargetHttpsProxy fakes setting an url-map for a target http proxy.
func (f *FakeLoadBalancers) SetUrlMapForTargetHttpsProxy(proxy *compute.TargetHttpsProxy, urlMap *compute.UrlMap) error {
func (f *FakeLoadBalancers) SetUrlMapForTargetHttpsProxy(proxy *compute.TargetHttpsProxy, urlMapLink string) error {
f.calls = append(f.calls, "SetUrlMapForTargetHttpsProxy")
for i := range f.Tps {
if f.Tps[i].Name == proxy.Name {
f.Tps[i].UrlMap = urlMap.SelfLink
f.Tps[i].UrlMap = urlMapLink
}
}
return nil
Expand Down
4 changes: 2 additions & 2 deletions pkg/loadbalancers/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,13 @@ type LoadBalancers interface {
GetTargetHttpProxy(name string) (*compute.TargetHttpProxy, error)
CreateTargetHttpProxy(proxy *compute.TargetHttpProxy) error
DeleteTargetHttpProxy(name string) error
SetUrlMapForTargetHttpProxy(proxy *compute.TargetHttpProxy, urlMap *compute.UrlMap) error
SetUrlMapForTargetHttpProxy(proxy *compute.TargetHttpProxy, urlMapLink string) error

// TargetHttpsProxies
GetTargetHttpsProxy(name string) (*compute.TargetHttpsProxy, error)
CreateTargetHttpsProxy(proxy *compute.TargetHttpsProxy) error
DeleteTargetHttpsProxy(name string) error
SetUrlMapForTargetHttpsProxy(proxy *compute.TargetHttpsProxy, urlMap *compute.UrlMap) error
SetUrlMapForTargetHttpsProxy(proxy *compute.TargetHttpsProxy, urlMapLink string) error
SetSslCertificateForTargetHttpsProxy(proxy *compute.TargetHttpsProxy, sslCertURLs []string) error

// SslCertificates
Expand Down
4 changes: 2 additions & 2 deletions pkg/loadbalancers/target_proxies.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func (l *L7) checkProxy() (err error) {
if !utils.EqualResourceIDs(proxy.UrlMap, l.um.SelfLink) {
glog.V(3).Infof("Proxy %v has the wrong url map, setting %v overwriting %v",
proxy.Name, l.um, proxy.UrlMap)
if err := l.cloud.SetUrlMapForTargetHttpProxy(proxy, l.um); err != nil {
if err := l.cloud.SetUrlMapForTargetHttpProxy(proxy, l.um.SelfLink); err != nil {
return err
}
}
Expand Down Expand Up @@ -99,7 +99,7 @@ func (l *L7) checkHttpsProxy() (err error) {
if !utils.EqualResourceIDs(proxy.UrlMap, l.um.SelfLink) {
glog.V(3).Infof("Https proxy %v has the wrong url map, setting %v overwriting %v",
proxy.Name, l.um, proxy.UrlMap)
if err := l.cloud.SetUrlMapForTargetHttpsProxy(proxy, l.um); err != nil {
if err := l.cloud.SetUrlMapForTargetHttpsProxy(proxy, l.um.SelfLink); err != nil {
return err
}
}
Expand Down
36 changes: 18 additions & 18 deletions pkg/neg/fakes.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
"reflect"
"sync"

computealpha "google.golang.org/api/compute/v0.alpha"
computebeta "google.golang.org/api/compute/v0.beta"
"k8s.io/apimachinery/pkg/util/sets"
"k8s.io/kubernetes/pkg/cloudprovider/providers/gce/cloud"
"k8s.io/kubernetes/pkg/cloudprovider/providers/gce/cloud/meta"
Expand Down Expand Up @@ -66,8 +66,8 @@ func (f *fakeZoneGetter) GetZoneForNode(name string) (string, error) {
}

type FakeNetworkEndpointGroupCloud struct {
NetworkEndpointGroups map[string][]*computealpha.NetworkEndpointGroup
NetworkEndpoints map[string][]*computealpha.NetworkEndpoint
NetworkEndpointGroups map[string][]*computebeta.NetworkEndpointGroup
NetworkEndpoints map[string][]*computebeta.NetworkEndpoint
Subnetwork string
Network string
mu sync.Mutex
Expand All @@ -77,14 +77,14 @@ func NewFakeNetworkEndpointGroupCloud(subnetwork, network string) networkEndpoin
return &FakeNetworkEndpointGroupCloud{
Subnetwork: subnetwork,
Network: network,
NetworkEndpointGroups: map[string][]*computealpha.NetworkEndpointGroup{},
NetworkEndpoints: map[string][]*computealpha.NetworkEndpoint{},
NetworkEndpointGroups: map[string][]*computebeta.NetworkEndpointGroup{},
NetworkEndpoints: map[string][]*computebeta.NetworkEndpoint{},
}
}

var NotFoundError = fmt.Errorf("Not Found")

func (f *FakeNetworkEndpointGroupCloud) GetNetworkEndpointGroup(name string, zone string) (*computealpha.NetworkEndpointGroup, error) {
func (f *FakeNetworkEndpointGroupCloud) GetNetworkEndpointGroup(name string, zone string) (*computebeta.NetworkEndpointGroup, error) {
f.mu.Lock()
defer f.mu.Unlock()
negs, ok := f.NetworkEndpointGroups[zone]
Expand All @@ -102,27 +102,27 @@ func networkEndpointKey(name, zone string) string {
return fmt.Sprintf("%s-%s", zone, name)
}

func (f *FakeNetworkEndpointGroupCloud) ListNetworkEndpointGroup(zone string) ([]*computealpha.NetworkEndpointGroup, error) {
func (f *FakeNetworkEndpointGroupCloud) ListNetworkEndpointGroup(zone string) ([]*computebeta.NetworkEndpointGroup, error) {
f.mu.Lock()
defer f.mu.Unlock()
return f.NetworkEndpointGroups[zone], nil
}

func (f *FakeNetworkEndpointGroupCloud) AggregatedListNetworkEndpointGroup() (map[string][]*computealpha.NetworkEndpointGroup, error) {
func (f *FakeNetworkEndpointGroupCloud) AggregatedListNetworkEndpointGroup() (map[string][]*computebeta.NetworkEndpointGroup, error) {
f.mu.Lock()
defer f.mu.Unlock()
return f.NetworkEndpointGroups, nil
}

func (f *FakeNetworkEndpointGroupCloud) CreateNetworkEndpointGroup(neg *computealpha.NetworkEndpointGroup, zone string) error {
func (f *FakeNetworkEndpointGroupCloud) CreateNetworkEndpointGroup(neg *computebeta.NetworkEndpointGroup, zone string) error {
f.mu.Lock()
defer f.mu.Unlock()
neg.SelfLink = cloud.NewNetworkEndpointGroupsResourceID("mock-project", zone, neg.Name).SelfLink(meta.VersionAlpha)
if _, ok := f.NetworkEndpointGroups[zone]; !ok {
f.NetworkEndpointGroups[zone] = []*computealpha.NetworkEndpointGroup{}
f.NetworkEndpointGroups[zone] = []*computebeta.NetworkEndpointGroup{}
}
f.NetworkEndpointGroups[zone] = append(f.NetworkEndpointGroups[zone], neg)
f.NetworkEndpoints[networkEndpointKey(neg.Name, zone)] = []*computealpha.NetworkEndpoint{}
f.NetworkEndpoints[networkEndpointKey(neg.Name, zone)] = []*computebeta.NetworkEndpoint{}
return nil
}

Expand All @@ -131,7 +131,7 @@ func (f *FakeNetworkEndpointGroupCloud) DeleteNetworkEndpointGroup(name string,
defer f.mu.Unlock()
delete(f.NetworkEndpoints, networkEndpointKey(name, zone))
negs := f.NetworkEndpointGroups[zone]
newList := []*computealpha.NetworkEndpointGroup{}
newList := []*computebeta.NetworkEndpointGroup{}
found := false
for _, neg := range negs {
if neg.Name == name {
Expand All @@ -147,17 +147,17 @@ func (f *FakeNetworkEndpointGroupCloud) DeleteNetworkEndpointGroup(name string,
return nil
}

func (f *FakeNetworkEndpointGroupCloud) AttachNetworkEndpoints(name, zone string, endpoints []*computealpha.NetworkEndpoint) error {
func (f *FakeNetworkEndpointGroupCloud) AttachNetworkEndpoints(name, zone string, endpoints []*computebeta.NetworkEndpoint) error {
f.mu.Lock()
defer f.mu.Unlock()
f.NetworkEndpoints[networkEndpointKey(name, zone)] = append(f.NetworkEndpoints[networkEndpointKey(name, zone)], endpoints...)
return nil
}

func (f *FakeNetworkEndpointGroupCloud) DetachNetworkEndpoints(name, zone string, endpoints []*computealpha.NetworkEndpoint) error {
func (f *FakeNetworkEndpointGroupCloud) DetachNetworkEndpoints(name, zone string, endpoints []*computebeta.NetworkEndpoint) error {
f.mu.Lock()
defer f.mu.Unlock()
newList := []*computealpha.NetworkEndpoint{}
newList := []*computebeta.NetworkEndpoint{}
for _, ne := range f.NetworkEndpoints[networkEndpointKey(name, zone)] {
found := false
for _, remove := range endpoints {
Expand All @@ -175,16 +175,16 @@ func (f *FakeNetworkEndpointGroupCloud) DetachNetworkEndpoints(name, zone string
return nil
}

func (f *FakeNetworkEndpointGroupCloud) ListNetworkEndpoints(name, zone string, showHealthStatus bool) ([]*computealpha.NetworkEndpointWithHealthStatus, error) {
func (f *FakeNetworkEndpointGroupCloud) ListNetworkEndpoints(name, zone string, showHealthStatus bool) ([]*computebeta.NetworkEndpointWithHealthStatus, error) {
f.mu.Lock()
defer f.mu.Unlock()
ret := []*computealpha.NetworkEndpointWithHealthStatus{}
ret := []*computebeta.NetworkEndpointWithHealthStatus{}
nes, ok := f.NetworkEndpoints[networkEndpointKey(name, zone)]
if !ok {
return nil, NotFoundError
}
for _, ne := range nes {
ret = append(ret, &computealpha.NetworkEndpointWithHealthStatus{NetworkEndpoint: ne})
ret = append(ret, &computebeta.NetworkEndpointWithHealthStatus{NetworkEndpoint: ne})
}
return ret, nil
}
Expand Down
16 changes: 8 additions & 8 deletions pkg/neg/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,19 @@ limitations under the License.
package neg

import (
computealpha "google.golang.org/api/compute/v0.alpha"
computebeta "google.golang.org/api/compute/v0.beta"
)

// networkEndpointGroupCloud is an interface for managing gce network endpoint group.
type networkEndpointGroupCloud interface {
GetNetworkEndpointGroup(name string, zone string) (*computealpha.NetworkEndpointGroup, error)
ListNetworkEndpointGroup(zone string) ([]*computealpha.NetworkEndpointGroup, error)
AggregatedListNetworkEndpointGroup() (map[string][]*computealpha.NetworkEndpointGroup, error)
CreateNetworkEndpointGroup(neg *computealpha.NetworkEndpointGroup, zone string) error
GetNetworkEndpointGroup(name string, zone string) (*computebeta.NetworkEndpointGroup, error)
ListNetworkEndpointGroup(zone string) ([]*computebeta.NetworkEndpointGroup, error)
AggregatedListNetworkEndpointGroup() (map[string][]*computebeta.NetworkEndpointGroup, error)
CreateNetworkEndpointGroup(neg *computebeta.NetworkEndpointGroup, zone string) error
DeleteNetworkEndpointGroup(name string, zone string) error
AttachNetworkEndpoints(name, zone string, endpoints []*computealpha.NetworkEndpoint) error
DetachNetworkEndpoints(name, zone string, endpoints []*computealpha.NetworkEndpoint) error
ListNetworkEndpoints(name, zone string, showHealthStatus bool) ([]*computealpha.NetworkEndpointWithHealthStatus, error)
AttachNetworkEndpoints(name, zone string, endpoints []*computebeta.NetworkEndpoint) error
DetachNetworkEndpoints(name, zone string, endpoints []*computebeta.NetworkEndpoint) error
ListNetworkEndpoints(name, zone string, showHealthStatus bool) ([]*computebeta.NetworkEndpointWithHealthStatus, error)
NetworkURL() string
SubnetworkURL() string
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/neg/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
"testing"
"time"

compute "google.golang.org/api/compute/v0.alpha"
compute "google.golang.org/api/compute/v0.beta"
apiv1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/util/wait"
"k8s.io/client-go/kubernetes"
Expand Down
3 changes: 1 addition & 2 deletions pkg/neg/syncer.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (
"time"

"github.com/golang/glog"
compute "google.golang.org/api/compute/v0.alpha"
compute "google.golang.org/api/compute/v0.beta"
apiv1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/clock"
Expand Down Expand Up @@ -272,7 +272,6 @@ func (s *syncer) ensureNetworkEndpointGroups() error {
glog.V(2).Infof("Creating NEG %q for %s in %q.", s.negName, s.formattedName(), zone)
err = s.cloud.CreateNetworkEndpointGroup(&compute.NetworkEndpointGroup{
Name: s.negName,
Type: gce.NEGLoadBalancerType,
NetworkEndpointType: gce.NEGIPPortNetworkEndpointType,
LoadBalancer: &compute.NetworkEndpointGroupLbNetworkEndpointGroup{
Network: s.cloud.NetworkURL(),
Expand Down
1 change: 1 addition & 0 deletions vendor/google.golang.org/api/CONTRIBUTORS

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 7931e59

Please sign in to comment.