Skip to content

Commit

Permalink
Skip adding NEGs in to-be-deleted state when querying from Svcneg.
Browse files Browse the repository at this point in the history
* Backend Service updates are performed by providing a new list of
  backends every time. Thus, if we skip adding NEGs in to-be-delated
  state, they will be detached from Backend Services when a sync
  triggers.
* Currently, in fail-safe situation we get NEGs by querying GCE. Once
  CRD is ready, we will make sure to get the subnet information and also
  include NEGs from non-default subnet.
  • Loading branch information
sawsa307 committed Aug 21, 2024
1 parent f7dc7a0 commit 3f58299
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
3 changes: 3 additions & 0 deletions pkg/backends/neg_linker.go
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,9 @@ func getNegUrlsFromSvcneg(key string, svcNegLister cache.Indexer, logger klog.Lo
svcneg := obj.(*negv1beta1.ServiceNetworkEndpointGroup)

for _, negRef := range svcneg.Status.NetworkEndpointGroups {
if flags.F.EnableMultiSubnetClusterPhase1 && negRef.State == negv1beta1.ToBeDeletedState {
continue
}
negUrls = append(negUrls, negRef.SelfLink)
}
return negUrls, true
Expand Down
12 changes: 12 additions & 0 deletions pkg/backends/neg_linker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ func TestLinkBackendServiceToNEG(t *testing.T) {

func TestGetNegSelfLinks(t *testing.T) {
t.Parallel()
flags.F.EnableMultiSubnetClusterPhase1 = true

groupKeys := []GroupKey{{Zone: testZone1}, {Zone: testZone2}}
namespace, svcName, port := "ns", "name", "port"
Expand Down Expand Up @@ -268,6 +269,17 @@ func TestGetNegSelfLinks(t *testing.T) {
},
expectedNegCount: 4,
},
{
desc: "Get NEGs from SvcNeg, all NEGs are in active state, and containing NEGs from non-default subnet",
populateSvcNeg: true,
testNegRef: []v1beta1.NegObjectReference{
createNegRef(testZone1, defaultSubnetNegName, v1beta1.ActiveState),
createNegRef(testZone1, nonDefaultSubnetNegName, v1beta1.ToBeDeletedState),
createNegRef(testZone2, defaultSubnetNegName, v1beta1.ActiveState),
createNegRef(testZone2, nonDefaultSubnetNegName, v1beta1.ToBeDeletedState),
},
expectedNegCount: 2,
},
{
desc: "Get NEGs from GCE",
populateSvcNeg: false,
Expand Down

0 comments on commit 3f58299

Please sign in to comment.