Skip to content

Commit

Permalink
Use a dedicated name function for PRIMARY_IP NEG
Browse files Browse the repository at this point in the history
Also using a dedicated PortMap function.
  • Loading branch information
prameshj committed Jan 6, 2020
1 parent 0edea3d commit f76730d
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 2 deletions.
5 changes: 3 additions & 2 deletions pkg/neg/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ func NewController(
reflector: reflector,
}

if ctx.Cloud.AlphaFeatureGate != nil && ctx.Cloud.AlphaFeatureGate.Enabled("ILBSubsets") {
if ctx.Cloud.AlphaFeatureGate != nil && ctx.Cloud.AlphaFeatureGate.Enabled(gce.AlphaFeatureILBSubsets) {
runL4 = true
}

Expand Down Expand Up @@ -503,7 +503,8 @@ func (c *Controller) mergeVmPrimaryIpNEGsPortInfo(service *apiv1.Service, name t
// Insert Empty PortTuple for VmPrimaryIp NEGs.
negtypes.SvcPortTuple{},
)
return portInfoMap.Merge(negtypes.NewPortInfoMap(name.Namespace, name.Name, svcPortSet, c.namer, false, !helpers.RequestsOnlyLocalTraffic(service)))
return portInfoMap.Merge(negtypes.NewPortInfoMapForPrimaryIPNEG(name.Namespace, name.Name, c.namer,
!helpers.RequestsOnlyLocalTraffic(service)))
}

// mergeDefaultBackendServicePortInfoMap merge the PortInfoMap for the default backend service into portInfoMap
Expand Down
1 change: 1 addition & 0 deletions pkg/neg/types/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ type NetworkEndpointGroupCloud interface {
// NetworkEndpointGroupNamer is an interface for generating network endpoint group name.
type NetworkEndpointGroupNamer interface {
NEG(namespace, name string, port int32) string
PrimaryIPNEG(namespace, name string) string
NEGWithSubset(namespace, name, subset string, port int32) string
IsNEG(name string) bool
}
Expand Down
19 changes: 19 additions & 0 deletions pkg/neg/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,25 @@ func NewPortInfoMap(namespace, name string, svcPortTupleSet SvcPortTupleSet, nam
return ret
}

// NewPortInfoMapForPrimaryIPNEG creates PortInfoMap with empty port tuple. Since PRIMARY_VM_IP NEGs target
// the node instead of the pod, there is no port info to be stored.
func NewPortInfoMapForPrimaryIPNEG(namespace, name string, namer NetworkEndpointGroupNamer, randomize bool) PortInfoMap {
ret := PortInfoMap{}
svcPortSet := make(SvcPortTupleSet)
svcPortSet.Insert(
// Insert Empty PortTuple for VmPrimaryIp NEGs.
SvcPortTuple{},
)
for svcPortTuple := range svcPortSet {
ret[PortInfoMapKey{svcPortTuple.Port, ""}] = PortInfo{
PortTuple: svcPortTuple,
NegName: namer.PrimaryIPNEG(namespace, name),
RandomizeEndpoints: randomize,
}
}
return ret
}

// NewPortInfoMapWithDestinationRule create PortInfoMap based on a gaven DesinationRule.
// Return error message if the DestinationRule contains duplicated subsets.
func NewPortInfoMapWithDestinationRule(namespace, name string, svcPortTupleSet SvcPortTupleSet, namer NetworkEndpointGroupNamer, readinessGate bool,
Expand Down
8 changes: 8 additions & 0 deletions pkg/utils/namer/namer.go
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,14 @@ func (n *Namer) NEGWithSubset(namespace, name, subset string, port int32) string
return fmt.Sprintf("%s-%s-%s-%s-%s-%s", n.negPrefix(), truncNamespace, truncName, truncPort, truncSubset, negSuffix(n.shortUID(), namespace, name, portStr, subset))
}

func (n *Namer) PrimaryIPNEG(namespace, name string) string {
truncFields := TrimFieldsEvenly(maxNEGDescriptiveLabel, namespace, name)
truncNamespace := truncFields[0]
truncName := truncFields[1]
// Use the full cluster UID in the suffix to reduce chance of collision.
return fmt.Sprintf("%s-%s-%s-%s", n.negPrefix(), truncNamespace, truncName, negSuffix(n.UID(), namespace, name, "", ""))
}

// IsNEG returns true if the name is a NEG owned by this cluster.
// It checks that the UID is present and a substring of the
// cluster uid, since the NEG naming schema truncates it to 8 characters.
Expand Down

0 comments on commit f76730d

Please sign in to comment.