Skip to content

Commit

Permalink
Populate subnet values for nodes in NEG syncers.
Browse files Browse the repository at this point in the history
* NEG syncer will partition endpoints based on zone and subnet using
  EndpointGroupInfo.
* Dual stack migration occurs on a per-NEG basis, so it will also happen
  in one subnet and zone at a time.
* Currently, L4 endpoint calculators only subsetting nodes by zones in
  the default subnet. Subsetting in additional subnet will be included
  in a follow-up PR.
  • Loading branch information
sawsa307 committed Oct 21, 2024
1 parent 6a02d24 commit 5c2ba6a
Show file tree
Hide file tree
Showing 13 changed files with 295 additions and 239 deletions.
2 changes: 1 addition & 1 deletion pkg/instancegroups/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ func (m *manager) List(logger klog.Logger) ([]string, error) {
func (m *manager) splitNodesByZone(names []string, logger klog.Logger) map[string][]string {
nodesByZone := map[string][]string{}
for _, name := range names {
zone, err := m.ZoneGetter.ZoneForNode(name, logger)
zone, _, err := m.ZoneGetter.ZoneAndSubnetForNode(name, logger)
if err != nil {
logger.Error(err, "Failed to get zones for instance node, skipping", "name", name)
continue
Expand Down
15 changes: 11 additions & 4 deletions pkg/l4lb/l4netlbcontroller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ const (

shortSessionAffinityIdleTimeout = int32(20) // 20 sec could be used for regular Session Affinity
longSessionAffinityIdleTimeout = int32(2 * 60) // 2 min or 120 sec for Strong Session Affinity

defaultTestSubnetURL = "https://www.googleapis.com/compute/v1/projects/proj/regions/us-central1/subnetworks/default"
)

var (
Expand Down Expand Up @@ -323,8 +325,13 @@ func buildContext(vals gce.TestClusterValues) *ingctx.ControllerContext {
}

func newL4NetLBServiceController() *L4NetLBController {
stopCh := make(chan struct{})
vals := gce.DefaultTestClusterValues()
vals.SubnetworkURL = defaultTestSubnetURL
return createL4NetLBServiceController(vals)
}

func createL4NetLBServiceController(vals gce.TestClusterValues) *L4NetLBController {
stopCh := make(chan struct{})
ctx := buildContext(vals)
nodes, err := test.CreateAndInsertNodes(ctx.Cloud, []string{"instance-1", "instance-2"}, vals.ZoneName)
if err != nil {
Expand Down Expand Up @@ -1663,7 +1670,7 @@ func TestDualStackServiceNeedsUpdate(t *testing.T) {
t.Run(tc.desc, func(t *testing.T) {
t.Parallel()

controller := newL4NetLBServiceController()
controller := createL4NetLBServiceController(gce.DefaultTestClusterValues())
controller.enableDualStack = true
oldSvc := test.NewL4NetLBRBSService(8080)
oldSvc.Spec.IPFamilies = tc.initialIPFamilies
Expand Down Expand Up @@ -1862,7 +1869,7 @@ func TestCreateDeleteDualStackNetLBService(t *testing.T) {

for _, tc := range testCases {
t.Run(tc.desc, func(t *testing.T) {
controller := newL4NetLBServiceController()
controller := createL4NetLBServiceController(gce.DefaultTestClusterValues())
controller.enableDualStack = true
svc := test.NewL4NetLBRBSService(8080)
svc.Spec.IPFamilies = tc.ipFamilies
Expand Down Expand Up @@ -1907,7 +1914,7 @@ func TestCreateDeleteDualStackNetLBService(t *testing.T) {
}
func TestProcessDualStackNetLBServiceOnUserError(t *testing.T) {
t.Parallel()
controller := newL4NetLBServiceController()
controller := createL4NetLBServiceController(gce.DefaultTestClusterValues())
controller.enableDualStack = true
svc := test.NewL4NetLBRBSService(8080)
svc.Spec.IPFamilies = []v1.IPFamily{v1.IPv6Protocol, v1.IPv4Protocol}
Expand Down
1 change: 1 addition & 0 deletions pkg/neg/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ const (
labelValue2 = "v2"
negName1 = "neg1"

defaultTestSubnet = "default"
defaultTestSubnetURL = "https://www.googleapis.com/compute/v1/projects/proj/regions/us-central1/subnetworks/default"
)

Expand Down
162 changes: 82 additions & 80 deletions pkg/neg/syncers/dualstack/migrator_test.go

Large diffs are not rendered by default.

10 changes: 8 additions & 2 deletions pkg/neg/syncers/endpoints_calculator.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ func NewLocalL4EndpointsCalculator(nodeLister listers.NodeLister, zoneGetter *zo
if lbType == negtypes.L4ExternalLB {
subsetSize = maxSubsetSizeNetLBLocal
}

return &LocalL4EndpointsCalculator{
nodeLister: nodeLister,
zoneGetter: zoneGetter,
Expand Down Expand Up @@ -106,7 +107,7 @@ func (l *LocalL4EndpointsCalculator) CalculateEndpoints(eds []types.EndpointsDat
l.logger.Info("Node not connected to service network", "nodeName", node.Name, "network", l.networkInfo.K8sNetwork)
continue
}
zone, err := l.zoneGetter.ZoneForNode(node.Name, l.logger)
zone, _, err := l.zoneGetter.ZoneAndSubnetForNode(node.Name, l.logger)
if err != nil {
l.logger.Error(err, "Unable to find zone for node, skipping", "nodeName", node.Name)
metrics.PublishNegControllerErrorCountMetrics(err, true)
Expand All @@ -121,7 +122,10 @@ func (l *LocalL4EndpointsCalculator) CalculateEndpoints(eds []types.EndpointsDat
}
// Compute the networkEndpoints, with total endpoints count <= l.subsetSizeLimit
l.logger.V(2).Info("Got zoneNodeMap as input for service", "zoneNodeMap", nodeMapToString(zoneNodeMap), "serviceID", l.svcId)
// TODO(sawsa307): Make sure to include logic for subsetting endpoints in non-default subnets.
// Currently we only select endpoints from the default subnet.
subsetMap, err := getSubsetPerZone(zoneNodeMap, l.subsetSizeLimit, l.svcId, currentMap, l.logger, l.networkInfo)

return subsetMap, nil, 0, err
}

Expand Down Expand Up @@ -182,7 +186,7 @@ func (l *ClusterL4EndpointsCalculator) CalculateEndpoints(_ []types.EndpointsDat
l.logger.Info("Node not connected to service network", "nodeName", node.Name, "network", l.networkInfo.K8sNetwork)
continue
}
zone, err := l.zoneGetter.ZoneForNode(node.Name, l.logger)
zone, _, err := l.zoneGetter.ZoneAndSubnetForNode(node.Name, l.logger)
if err != nil {
l.logger.Error(err, "Unable to find zone for node skipping", "nodeName", node.Name)
metrics.PublishNegControllerErrorCountMetrics(err, true)
Expand All @@ -192,6 +196,8 @@ func (l *ClusterL4EndpointsCalculator) CalculateEndpoints(_ []types.EndpointsDat
}
l.logger.V(2).Info("Got zoneNodeMap as input for service", "zoneNodeMap", nodeMapToString(zoneNodeMap), "serviceID", l.svcId)
// Compute the networkEndpoints, with total endpoints <= l.subsetSizeLimit.
// TODO(sawsa307): Make sure to include logic for subsetting endpoints in non-default subnets.
// Currently we only select endpoints from the default subnet.
subsetMap, err := getSubsetPerZone(zoneNodeMap, l.subsetSizeLimit, l.svcId, currentMap, l.logger, l.networkInfo)
return subsetMap, nil, 0, err
}
Expand Down
Loading

0 comments on commit 5c2ba6a

Please sign in to comment.