Skip to content

Commit

Permalink
Merge pull request #811 from spencerhance/fix-backends-cast
Browse files Browse the repository at this point in the history
Add cloud pointer to neg linker and backend syncer
  • Loading branch information
k8s-ci-robot authored Aug 5, 2019
2 parents 211659a + 5752113 commit ede0840
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 17 deletions.
2 changes: 1 addition & 1 deletion pkg/backends/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func newTestJig(fakeGCE *gce.Cloud) *Jig {
return &Jig{
fakeInstancePool: fakeInstancePool,
linker: NewInstanceGroupLinker(fakeInstancePool, fakeBackendPool, defaultNamer),
syncer: NewBackendSyncer(fakeBackendPool, fakeHealthChecks, defaultNamer),
syncer: NewBackendSyncer(fakeBackendPool, fakeHealthChecks, defaultNamer, fakeGCE),
pool: fakeBackendPool,
}
}
Expand Down
13 changes: 8 additions & 5 deletions pkg/backends/neg_linker.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,15 @@ import (
befeatures "k8s.io/ingress-gce/pkg/backends/features"
"k8s.io/ingress-gce/pkg/composite"
"k8s.io/ingress-gce/pkg/utils"
"k8s.io/legacy-cloud-providers/gce"
)

// negLinker handles linking backends to NEG's.
type negLinker struct {
backendPool Pool
negGetter NEGGetter
namer *utils.Namer
cloud *gce.Cloud
}

// negLinker is a Linker
Expand All @@ -34,11 +36,13 @@ var _ Linker = (*negLinker)(nil)
func NewNEGLinker(
backendPool Pool,
negGetter NEGGetter,
namer *utils.Namer) Linker {
namer *utils.Namer,
cloud *gce.Cloud) Linker {
return &negLinker{
backendPool: backendPool,
negGetter: negGetter,
namer: namer,
cloud: cloud,
}
}

Expand All @@ -60,17 +64,16 @@ func (l *negLinker) Link(sp utils.ServicePort, groups []GroupKey) error {
negs = append(negs, neg)
}

cloud := l.backendPool.(*Backends).cloud
beName := sp.BackendName(l.namer)

version := befeatures.VersionFromServicePort(&sp)
scope := befeatures.ScopeFromServicePort(&sp)

key, err := composite.CreateKey(cloud, beName, scope)
key, err := composite.CreateKey(l.cloud, beName, scope)
if err != nil {
return err
}
backendService, err := composite.GetBackendService(cloud, key, version)
backendService, err := composite.GetBackendService(l.cloud, key, version)
if err != nil {
return err
}
Expand All @@ -90,7 +93,7 @@ func (l *negLinker) Link(sp utils.ServicePort, groups []GroupKey) error {

if !oldBackends.Equal(newBackends) {
backendService.Backends = targetBackends
return composite.UpdateBackendService(cloud, key, backendService)
return composite.UpdateBackendService(l.cloud, key, backendService)
}
return nil
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/backends/neg_linker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func newTestNEGLinker(fakeNEG negtypes.NetworkEndpointGroupCloud, fakeGCE *gce.C
(fakeGCE.Compute().(*cloud.MockGCE)).MockBetaBackendServices.UpdateHook = mock.UpdateBetaBackendServiceHook
(fakeGCE.Compute().(*cloud.MockGCE)).MockBackendServices.UpdateHook = mock.UpdateBackendServiceHook

return &negLinker{fakeBackendPool, fakeNEG, defaultNamer}
return &negLinker{fakeBackendPool, fakeNEG, defaultNamer, fakeGCE}
}

func TestLinkBackendServiceToNEG(t *testing.T) {
Expand Down
15 changes: 7 additions & 8 deletions pkg/backends/syncer.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ type backendSyncer struct {
healthChecker healthchecks.HealthChecker
prober ProbeProvider
namer *utils.Namer
cloud *gce.Cloud
}

// backendSyncer is a Syncer
Expand All @@ -43,11 +44,13 @@ var _ Syncer = (*backendSyncer)(nil)
func NewBackendSyncer(
backendPool Pool,
healthChecker healthchecks.HealthChecker,
namer *utils.Namer) Syncer {
namer *utils.Namer,
cloud *gce.Cloud) Syncer {
return &backendSyncer{
backendPool: backendPool,
healthChecker: healthChecker,
namer: namer,
cloud: cloud,
}
}

Expand Down Expand Up @@ -125,8 +128,7 @@ func (s *backendSyncer) ensureBackendService(sp utils.ServicePort) error {
}

if sp.BackendConfig != nil {
cloud := s.backendPool.(*Backends).cloud
if err := features.EnsureSecurityPolicy(cloud, sp, be, beName); err != nil {
if err := features.EnsureSecurityPolicy(s.cloud, sp, be, beName); err != nil {
return err
}
}
Expand All @@ -136,10 +138,7 @@ func (s *backendSyncer) ensureBackendService(sp utils.ServicePort) error {

// GC implements Syncer.
func (s *backendSyncer) GC(svcPorts []utils.ServicePort) error {
// TODO: (shance) fix the interface so we don't have this cast
cloud := s.backendPool.(*Backends).cloud

knownPorts, err := knownPortsFromServicePorts(cloud, s.namer, svcPorts)
knownPorts, err := knownPortsFromServicePorts(s.cloud, s.namer, svcPorts)
if err != nil {
return err
}
Expand All @@ -156,7 +155,7 @@ func (s *backendSyncer) GC(svcPorts []utils.ServicePort) error {
if err != nil {
return err
}
if key, err = composite.CreateKey(cloud, name, scope); err != nil {
if key, err = composite.CreateKey(s.cloud, name, scope); err != nil {
return err
}
if knownPorts.Has(key.String()) {
Expand Down
4 changes: 2 additions & 2 deletions pkg/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,8 @@ func NewLoadBalancerController(
nodes: NewNodeController(ctx, instancePool),
instancePool: instancePool,
l7Pool: loadbalancers.NewLoadBalancerPool(ctx.Cloud, ctx.ClusterNamer, ctx),
backendSyncer: backends.NewBackendSyncer(backendPool, healthChecker, ctx.ClusterNamer),
negLinker: backends.NewNEGLinker(backendPool, negtypes.NewAdapter(ctx.Cloud), ctx.ClusterNamer),
backendSyncer: backends.NewBackendSyncer(backendPool, healthChecker, ctx.ClusterNamer, ctx.Cloud),
negLinker: backends.NewNEGLinker(backendPool, negtypes.NewAdapter(ctx.Cloud), ctx.ClusterNamer, ctx.Cloud),
igLinker: backends.NewInstanceGroupLinker(instancePool, backendPool, ctx.ClusterNamer),
}
lbc.ingSyncer = ingsync.NewIngressSyncer(&lbc)
Expand Down

0 comments on commit ede0840

Please sign in to comment.