Skip to content

Commit

Permalink
Merge pull request #1199 from swetharepakula/refactor-neg-crd-manager
Browse files Browse the repository at this point in the history
Ignore deletion timestamp when ensuring NEG CR
  • Loading branch information
k8s-ci-robot committed Jul 31, 2020
2 parents 390f683 + 727a50e commit 332d3e0
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 10 deletions.
16 changes: 7 additions & 9 deletions pkg/neg/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,13 @@ func (manager *syncerManager) EnsureSyncers(namespace, name string, newPorts neg
syncerKey := getSyncerKey(namespace, name, svcPort, portInfo)
syncer, ok := manager.syncerMap[syncerKey]
if !ok {

// To ensure that a NEG CR always exists during the lifecyle of a NEG, do not create a syncer for the NEG until the NEG CR is successfully created. This will reduce the possibility of invalid states and reduces complexity of garbage collection
if err := manager.ensureSvcNegCR(key, portInfo); err != nil {
errList = append(errList, err)
continue
}

// determine the implementation that calculates NEG endpoints on each sync.
epc := negsyncer.GetEndpointsCalculator(manager.nodeLister, manager.podLister, manager.zoneGetter,
syncerKey, portInfo.RandomizeEndpoints)
Expand All @@ -163,10 +170,6 @@ func (manager *syncerManager) EnsureSyncers(namespace, name string, newPorts neg
manager.syncerMap[syncerKey] = syncer
}

if err := manager.ensureSvcNegCR(key, portInfo); err != nil {
errList = append(errList, err)
}

if syncer.IsStopped() {
if err := syncer.Start(); err != nil {
errList = append(errList, err)
Expand Down Expand Up @@ -430,11 +433,6 @@ func (manager *syncerManager) ensureSvcNegCR(svcKey serviceKey, portInfo negtype
return err
}

if !negCR.GetDeletionTimestamp().IsZero() {
// Allow GC to complete
return fmt.Errorf("Neg CR already exists with this name and is marked for deletion. Allow GC to complete before recreating.")
}

needUpdate, err := ensureNegCRLabels(negCR, labels)
if err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion pkg/neg/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -842,7 +842,7 @@ func TestNegCRDuplicateCreations(t *testing.T) {
svc: svc1,
svcTuple: svcTuple1,
markedForDeletion: true,
expectErr: true,
expectErr: false,
crExists: true,
},
{desc: "same service, different port configuration, original cr is not marked for deletion",
Expand Down

0 comments on commit 332d3e0

Please sign in to comment.