Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow local zone override for NonGCP NEG #1077

Merged
merged 2 commits into from
Apr 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion cmd/glbc/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,9 +231,21 @@ func runControllers(ctx *ingctx.ControllerContext) {
go l4Controller.Run()
klog.V(0).Infof("L4 controller started")
}
var zoneGetter negtypes.ZoneGetter
zoneGetter = lbc.Translator
// In NonGCP mode, use the zone specified in gce.conf directly.
// This overrides the zone/fault-domain label on nodes for NEG controller.
if flags.F.EnableNonGCPMode {
zone, err := ctx.Cloud.GetZone(context.Background())
if err != nil {
klog.Errorf("Failed to retrieve zone information from Cloud provider: %v; Please check if local-zone is specified in gce.conf.", err)
} else {
zoneGetter = negtypes.NewSimpleZoneGetter(zone.FailureDomain)
}
}

// TODO: Refactor NEG to use cloud mocks so ctx.Cloud can be referenced within NewController.
negController := neg.NewController(negtypes.NewAdapter(ctx.Cloud), ctx, lbc.Translator, ctx.ClusterNamer, flags.F.ResyncPeriod, flags.F.NegGCPeriod, flags.F.EnableReadinessReflector, flags.F.RunIngressController, flags.F.RunL4Controller)
negController := neg.NewController(negtypes.NewAdapter(ctx.Cloud), ctx, zoneGetter, ctx.ClusterNamer, flags.F.ResyncPeriod, flags.F.NegGCPeriod, flags.F.EnableReadinessReflector, flags.F.RunIngressController, flags.F.RunL4Controller)

go negController.Run(stopCh)
klog.V(0).Infof("negController started")
Expand Down
2 changes: 1 addition & 1 deletion pkg/neg/syncers/endpoints_calculator.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,5 +164,5 @@ func (l *L7EndpointsCalculator) Mode() types.EndpointsCalculatorMode {

// CalculateEndpoints determines the endpoints in the NEGs based on the current service endpoints and the current NEGs.
func (l *L7EndpointsCalculator) CalculateEndpoints(ep *v1.Endpoints, currentMap map[string]types.NetworkEndpointSet) (map[string]types.NetworkEndpointSet, types.EndpointPodMap, error) {
return toZoneNetworkEndpointMap(ep, l.zoneGetter, l.servicePortName, l.podLister, l.subsetLabels, "")
return toZoneNetworkEndpointMap(ep, l.zoneGetter, l.servicePortName, l.podLister, l.subsetLabels, l.networkEndpointType)
}
35 changes: 35 additions & 0 deletions pkg/neg/types/simple_zone_getter.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
Copyright 2020 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 types

// simpleZoneGetter implements ZoneGetter interface
// It always return its one single stored zone
type simpleZoneGetter struct {
zone string
}

func (s *simpleZoneGetter) GetZoneForNode(string) (string, error) {
return s.zone, nil
}

func (s *simpleZoneGetter) ListZones() ([]string, error) {
return []string{s.zone}, nil
}

func NewSimpleZoneGetter(zone string) ZoneGetter {
return &simpleZoneGetter{zone: zone}
}
49 changes: 49 additions & 0 deletions pkg/neg/types/simple_zone_getter_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
Copyright 2020 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 types

import (
"reflect"
"testing"
)

func TestSimpleZoneGetter(t *testing.T) {
zone := "foo"
zoneGetter := NewSimpleZoneGetter(zone)
ret, err := zoneGetter.ListZones()
if err != nil {
t.Errorf("expect err = nil, but got %v", err)
}
expectZones := []string{zone}
if !reflect.DeepEqual(expectZones, ret) {
t.Errorf("expect list zones = %v, but got %v", expectZones, ret)
}

validateGetZoneForNode := func(node string) {
retZone, err := zoneGetter.GetZoneForNode(node)
if err != nil {
t.Errorf("expect err = nil, but got %v", err)
}

if retZone != zone {
t.Errorf("expect zone = %q, but got %q", zone, retZone)
}
}

validateGetZoneForNode("foo-node")
validateGetZoneForNode("bar-node")
}