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

remove transaction syncer reconciliation #925

Merged
merged 1 commit into from
Nov 1, 2019
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
71 changes: 3 additions & 68 deletions pkg/neg/syncers/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,6 @@ func (s *transactionSyncer) syncInternal() error {
// Merge the current state from cloud with the transaction table together
// The combined state represents the eventual result when all transactions completed
mergeTransactionIntoZoneEndpointMap(currentMap, s.transactions)
// Find transaction entries that needs to be reconciled
reconcileTransactions(targetMap, s.transactions)
// Calculate the endpoints to add and delete to transform the current state to desire state
addEndpoints, removeEndpoints := calculateNetworkEndpointDifference(targetMap, currentMap)
// Calculate Pods that are already in the NEG
Expand Down Expand Up @@ -203,9 +201,8 @@ func (s *transactionSyncer) syncNetworkEndpoints(addEndpoints, removeEndpoints m
}

transEntry := transactionEntry{
Operation: operation,
NeedReconcile: false,
Zone: zone,
Operation: operation,
Zone: zone,
}

// Insert networkEndpoint into transaction table
Expand Down Expand Up @@ -299,16 +296,12 @@ func (s *transactionSyncer) commitTransaction(err error, networkEndpointMap map[
}

for networkEndpoint := range networkEndpointMap {
entry, ok := s.transactions.Get(networkEndpoint)
_, ok := s.transactions.Get(networkEndpoint)
// clear transaction
if !ok {
klog.Errorf("Endpoint %q was not found in the transaction table.", networkEndpoint)
continue
}
// TODO: Remove NeedReconcile in the transation entry (freehan)
if entry.NeedReconcile == true {
klog.Errorf("Endpoint %q in NEG %q need to be reconciled.", networkEndpoint, s.NegSyncerKey.String())
}
s.transactions.Delete(networkEndpoint)
}

Expand Down Expand Up @@ -378,61 +371,3 @@ func mergeTransactionIntoZoneEndpointMap(endpointMap map[string]negtypes.Network
}
return
}

// reconcileTransactions compares the endpoint map with existing transaction entries in transaction table
// if transaction does not cu
func reconcileTransactions(endpointMap map[string]negtypes.NetworkEndpointSet, transactions networkEndpointTransactionTable) {
// Identify endpoints that should be in NEG but the current transaction does not match the intention
for zone, endpointSet := range endpointMap {
for _, endpointKey := range endpointSet.List() {
entry, ok := transactions.Get(endpointKey)
// if transaction does not contain endpoints, it will be handled in this sync
if !ok {
continue
}
needReconcile := false
// if zone does not match, need to reconcile
if entry.Zone != zone {
needReconcile = true
}
// if the endpoint entry is in detach transaction but shows up endpointMap
if entry.Operation == detachOp {
needReconcile = true
}

if needReconcile {
entry.NeedReconcile = true
transactions.Put(endpointKey, entry)
}
}
}

// Identify endpoints that should not to be in NEG but the current transaction does not match the intention
for _, endpointKey := range transactions.Keys() {
entry, ok := transactions.Get(endpointKey)
if !ok {
continue
}
needReconcile := false
if entry.Operation == attachOp {
endpointSet, ok := endpointMap[entry.Zone]
// If zone is not in endpointMap, then the endpoint must not exist in the endpointMap
if !ok {
needReconcile = true
}

// If the endpoint that is in attach transaction does not exists in the endpointMap,
// Then it means the endpoint needs to be reconciled after attach operation completes.
if !endpointSet.Has(endpointKey) {
needReconcile = true
}
}

if needReconcile {
entry.NeedReconcile = true
transactions.Put(endpointKey, entry)
}
}

return
}
2 changes: 0 additions & 2 deletions pkg/neg/syncers/transaction_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,6 @@ func (op transactionOp) String() string {
type transactionEntry struct {
// Operation represents the operation type associated with each transaction
Operation transactionOp
// NeedReconcile indicates whether the entry needs to be reconciled.
NeedReconcile bool
// Zone represents the zone of the transaction
Zone string
}
Expand Down
2 changes: 0 additions & 2 deletions pkg/neg/syncers/transaction_table_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ func TestTransactionTable(t *testing.T) {
key := negtypes.NetworkEndpoint{IP: fmt.Sprintf("%s%d", ipPrefix, i), Port: fmt.Sprintf("%s%d", portPrefix, i), Node: fmt.Sprintf("%s%d", nodePrefix, i)}
entry := transactionEntry{
attachOp,
false,
fmt.Sprintf("%s%d", zonePrefix, i),
}
table.Put(key, entry)
Expand All @@ -63,7 +62,6 @@ func TestTransactionTable(t *testing.T) {
key := negtypes.NetworkEndpoint{IP: fmt.Sprintf("%s%d", ipPrefix, i), Port: fmt.Sprintf("%s%d", portPrefix, i), Node: fmt.Sprintf("%s%d", nodePrefix, i)}
newEntry := transactionEntry{
detachOp,
true,
fmt.Sprintf("%s%d", zonePrefix, i),
}
table.Put(key, newEntry)
Expand Down
Loading