@@ -159,6 +159,7 @@ type Proxier struct {
159
159
// updating iptables with some partial data after kube-proxy restart.
160
160
endpointSlicesSynced bool
161
161
servicesSynced bool
162
+ lastFullSync time.Time
162
163
needFullSync bool
163
164
initialized int32
164
165
syncRunner * async.BoundedFrequencyRunner // governs calls to syncProxyRules
@@ -325,7 +326,7 @@ func NewProxier(ctx context.Context,
325
326
// We pass syncPeriod to ipt.Monitor, which will call us only if it needs to.
326
327
// We need to pass *some* maxInterval to NewBoundedFrequencyRunner anyway though.
327
328
// time.Hour is arbitrary.
328
- proxier .syncRunner = async .NewBoundedFrequencyRunner ("sync-runner" , proxier .syncProxyRules , minSyncPeriod , time . Hour , burstSyncs )
329
+ proxier .syncRunner = async .NewBoundedFrequencyRunner ("sync-runner" , proxier .syncProxyRules , minSyncPeriod , proxyutil . FullSyncPeriod , burstSyncs )
329
330
330
331
go ipt .Monitor (kubeProxyCanaryChain , []utiliptables.Table {utiliptables .TableMangle , utiliptables .TableNAT , utiliptables .TableFilter },
331
332
proxier .forceSyncProxyRules , syncPeriod , wait .NeverStop )
@@ -541,6 +542,7 @@ func (proxier *Proxier) SyncLoop() {
541
542
// synthesize "last change queued" time as the informers are syncing.
542
543
metrics .SyncProxyRulesLastQueuedTimestamp .WithLabelValues (string (proxier .ipFamily )).SetToCurrentTime ()
543
544
proxier .syncRunner .Loop (wait .NeverStop )
545
+
544
546
}
545
547
546
548
func (proxier * Proxier ) setInitialized (value bool ) {
@@ -806,15 +808,14 @@ func (proxier *Proxier) syncProxyRules() {
806
808
return
807
809
}
808
810
809
- // The value of proxier.needFullSync may change before the defer funcs run, so
810
- // we need to keep track of whether it was set at the *start* of the sync.
811
- tryPartialSync := ! proxier .needFullSync
812
-
813
811
// Keep track of how long syncs take.
814
812
start := time .Now ()
813
+
814
+ doFullSync := proxier .needFullSync || (time .Since (proxier .lastFullSync ) > proxyutil .FullSyncPeriod )
815
+
815
816
defer func () {
816
817
metrics .SyncProxyRulesLatency .WithLabelValues (string (proxier .ipFamily )).Observe (metrics .SinceInSeconds (start ))
817
- if tryPartialSync {
818
+ if ! doFullSync {
818
819
metrics .SyncPartialProxyRulesLatency .WithLabelValues (string (proxier .ipFamily )).Observe (metrics .SinceInSeconds (start ))
819
820
} else {
820
821
metrics .SyncFullProxyRulesLatency .WithLabelValues (string (proxier .ipFamily )).Observe (metrics .SinceInSeconds (start ))
@@ -825,24 +826,26 @@ func (proxier *Proxier) syncProxyRules() {
825
826
serviceUpdateResult := proxier .svcPortMap .Update (proxier .serviceChanges )
826
827
endpointUpdateResult := proxier .endpointsMap .Update (proxier .endpointsChanges )
827
828
828
- proxier .logger .V (2 ).Info ("Syncing iptables rules" )
829
+ proxier .logger .V (2 ).Info ("Syncing iptables rules" , "fullSync" , doFullSync )
829
830
830
831
success := false
831
832
defer func () {
832
833
if ! success {
833
834
proxier .logger .Info ("Sync failed" , "retryingTime" , proxier .syncPeriod )
834
835
proxier .syncRunner .RetryAfter (proxier .syncPeriod )
835
- if tryPartialSync {
836
+ if ! doFullSync {
836
837
metrics .IPTablesPartialRestoreFailuresTotal .WithLabelValues (string (proxier .ipFamily )).Inc ()
837
838
}
838
839
// proxier.serviceChanges and proxier.endpointChanges have already
839
840
// been flushed, so we've lost the state needed to be able to do
840
841
// a partial sync.
841
842
proxier .needFullSync = true
843
+ } else if doFullSync {
844
+ proxier .lastFullSync = time .Now ()
842
845
}
843
846
}()
844
847
845
- if ! tryPartialSync {
848
+ if doFullSync {
846
849
// Ensure that our jump rules (eg from PREROUTING to KUBE-SERVICES) exist.
847
850
// We can't do this as part of the iptables-restore because we don't want
848
851
// to specify/replace *all* of the rules in PREROUTING, etc.
@@ -1235,7 +1238,7 @@ func (proxier *Proxier) syncProxyRules() {
1235
1238
// then we can omit them from the restore input. However, we have to still
1236
1239
// figure out how many chains we _would_ have written, to make the metrics
1237
1240
// come out right, so we just compute them and throw them away.
1238
- if tryPartialSync && ! serviceUpdateResult .UpdatedServices .Has (svcName .NamespacedName ) && ! endpointUpdateResult .UpdatedServices .Has (svcName .NamespacedName ) {
1241
+ if ! doFullSync && ! serviceUpdateResult .UpdatedServices .Has (svcName .NamespacedName ) && ! endpointUpdateResult .UpdatedServices .Has (svcName .NamespacedName ) {
1239
1242
natChains = skippedNatChains
1240
1243
natRules = skippedNatRules
1241
1244
}
0 commit comments