Skip to content

Commit

Permalink
switch Ingress controller to use GA NEG API
Browse files Browse the repository at this point in the history
  • Loading branch information
freehan committed Jun 13, 2019
1 parent 460b84f commit 94af48d
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 15 deletions.
3 changes: 2 additions & 1 deletion cmd/glbc/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import (
ingctx "k8s.io/ingress-gce/pkg/context"
"k8s.io/ingress-gce/pkg/controller"
neg "k8s.io/ingress-gce/pkg/neg"
negtypes "k8s.io/ingress-gce/pkg/neg/types"

"k8s.io/ingress-gce/cmd/glbc/app"
"k8s.io/ingress-gce/pkg/backendconfig"
Expand Down Expand Up @@ -196,7 +197,7 @@ func runControllers(ctx *ingctx.ControllerContext) {
fwc := firewalls.NewFirewallController(ctx, flags.F.NodePortRanges.Values())

// TODO: Refactor NEG to use cloud mocks so ctx.Cloud can be referenced within NewController.
negController := neg.NewController(neg.NewAdapter(ctx.Cloud), ctx, lbc.Translator, ctx.ClusterNamer, flags.F.ResyncPeriod, flags.F.NegGCPeriod, neg.NegSyncerType(flags.F.NegSyncerType))
negController := neg.NewController(negtypes.NewAdapter(ctx.Cloud), ctx, lbc.Translator, ctx.ClusterNamer, flags.F.ResyncPeriod, flags.F.NegGCPeriod, neg.NegSyncerType(flags.F.NegSyncerType))
go negController.Run(stopCh)
klog.V(0).Infof("negController started")

Expand Down
2 changes: 1 addition & 1 deletion pkg/backends/features/features.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ var (
// version to feature names.
versionToFeatures = map[meta.Version][]string{
meta.VersionAlpha: []string{},
meta.VersionBeta: []string{FeatureSecurityPolicy, FeatureNEG, FeatureHTTP2},
meta.VersionBeta: []string{FeatureSecurityPolicy, FeatureHTTP2},
}
)

Expand Down
2 changes: 1 addition & 1 deletion pkg/backends/features/features_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ func TestVersionFromFeatures(t *testing.T) {
{
desc: "NEG",
features: []string{FeatureNEG},
expectedVersion: meta.VersionBeta,
expectedVersion: meta.VersionGA,
},
{
desc: "HTTP2 + SecurityPolicy",
Expand Down
4 changes: 2 additions & 2 deletions pkg/backends/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ package backends

import (
"github.com/GoogleCloudPlatform/k8s-cloud-provider/pkg/cloud/meta"
computebeta "google.golang.org/api/compute/v0.beta"
compute "google.golang.org/api/compute/v1"
api_v1 "k8s.io/api/core/v1"
"k8s.io/ingress-gce/pkg/composite"
"k8s.io/ingress-gce/pkg/utils"
Expand Down Expand Up @@ -71,7 +71,7 @@ type Linker interface {

// NEGGetter is an interface to retrieve NEG object
type NEGGetter interface {
GetNetworkEndpointGroup(name string, zone string) (*computebeta.NetworkEndpointGroup, error)
GetNetworkEndpointGroup(name string, zone string) (*compute.NetworkEndpointGroup, error)
}

// ProbeProvider retrieves a probe struct given a nodePort
Expand Down
14 changes: 7 additions & 7 deletions pkg/backends/neg_linker.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ limitations under the License.
package backends

import (
computebeta "google.golang.org/api/compute/v0.beta"
compute "google.golang.org/api/compute/v1"
"k8s.io/apimachinery/pkg/util/sets"
"k8s.io/ingress-gce/pkg/utils"
)
Expand Down Expand Up @@ -42,7 +42,7 @@ func NewNEGLinker(

// Link implements Link.
func (l *negLinker) Link(sp utils.ServicePort, groups []GroupKey) error {
var negs []*computebeta.NetworkEndpointGroup
var negs []*compute.NetworkEndpointGroup
var err error
for _, group := range groups {
// If the group key contains a name, then use that.
Expand All @@ -60,7 +60,7 @@ func (l *negLinker) Link(sp utils.ServicePort, groups []GroupKey) error {

cloud := l.backendPool.(*Backends).cloud
beName := sp.BackendName(l.namer)
backendService, err := cloud.GetBetaGlobalBackendService(beName)
backendService, err := cloud.GetGlobalBackendService(beName)
if err != nil {
return err
}
Expand All @@ -80,15 +80,15 @@ func (l *negLinker) Link(sp utils.ServicePort, groups []GroupKey) error {

if !oldBackends.Equal(newBackends) {
backendService.Backends = targetBackends
return cloud.UpdateBetaGlobalBackendService(backendService)
return cloud.UpdateGlobalBackendService(backendService)
}
return nil
}

func getBackendsForNEGs(negs []*computebeta.NetworkEndpointGroup) []*computebeta.Backend {
var backends []*computebeta.Backend
func getBackendsForNEGs(negs []*compute.NetworkEndpointGroup) []*compute.Backend {
var backends []*compute.Backend
for _, neg := range negs {
b := &computebeta.Backend{
b := &compute.Backend{
Group: neg.SelfLink,
BalancingMode: string(Rate),
MaxRatePerEndpoint: maxRPS,
Expand Down
4 changes: 2 additions & 2 deletions pkg/backends/neg_linker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (

"github.com/GoogleCloudPlatform/k8s-cloud-provider/pkg/cloud"
"github.com/GoogleCloudPlatform/k8s-cloud-provider/pkg/cloud/mock"
computebeta "google.golang.org/api/compute/v0.beta"
compute "google.golang.org/api/compute/v1"
"k8s.io/apimachinery/pkg/types"
"k8s.io/ingress-gce/pkg/annotations"
negtypes "k8s.io/ingress-gce/pkg/neg/types"
Expand Down Expand Up @@ -64,7 +64,7 @@ func TestLinkBackendServiceToNEG(t *testing.T) {
linker.backendPool.Create(svcPort, "fake-healthcheck-link")

for _, key := range zones {
err := fakeNEG.CreateNetworkEndpointGroup(&computebeta.NetworkEndpointGroup{
err := fakeNEG.CreateNetworkEndpointGroup(&compute.NetworkEndpointGroup{
Name: defaultNamer.NEG(namespace, name, svcPort.Port),
}, key.Zone)
if err != nil {
Expand Down
3 changes: 2 additions & 1 deletion pkg/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ import (
"k8s.io/ingress-gce/pkg/controller/translator"
"k8s.io/ingress-gce/pkg/flags"
"k8s.io/ingress-gce/pkg/loadbalancers"
negtypes "k8s.io/ingress-gce/pkg/neg/types"
ingsync "k8s.io/ingress-gce/pkg/sync"
"k8s.io/ingress-gce/pkg/tls"
"k8s.io/ingress-gce/pkg/utils"
Expand Down Expand Up @@ -117,7 +118,7 @@ func NewLoadBalancerController(
instancePool: instancePool,
l7Pool: loadbalancers.NewLoadBalancerPool(ctx.Cloud, ctx.ClusterNamer, ctx),
backendSyncer: backends.NewBackendSyncer(backendPool, healthChecker, ctx.ClusterNamer),
negLinker: backends.NewNEGLinker(backendPool, ctx.Cloud, ctx.ClusterNamer),
negLinker: backends.NewNEGLinker(backendPool, negtypes.NewAdapter(ctx.Cloud), ctx.ClusterNamer),
igLinker: backends.NewInstanceGroupLinker(instancePool, backendPool, ctx.ClusterNamer),
}
lbc.ingSyncer = ingsync.NewIngressSyncer(&lbc)
Expand Down

0 comments on commit 94af48d

Please sign in to comment.