Skip to content

Commit

Permalink
daemon: Add hidden --k8s-sync-timeout option
Browse files Browse the repository at this point in the history
[ upstream commit bd89e83 ]

This option governs how long Cilium agent will wait to synchronize local
caches with global Kubernetes state before exiting. The default is 3
minutes. Don't expose it by default, this is for advanced tweaking.

Signed-off-by: Joe Stringer <joe@cilium.io>
  • Loading branch information
joestringer authored and tklauser committed Aug 8, 2020
1 parent 599b49c commit d9886df
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 2 deletions.
4 changes: 4 additions & 0 deletions daemon/daemon_main.go
Original file line number Diff line number Diff line change
Expand Up @@ -643,6 +643,10 @@ func init() {
option.KVStoreOpt, "Key-value store options")
option.BindEnv(option.KVStoreOpt)

flags.Duration(option.K8sSyncTimeoutName, defaults.K8sSyncTimeout, "Timeout for synchronizing k8s resources before exiting")
flags.MarkHidden(option.K8sSyncTimeoutName)
option.BindEnv(option.K8sSyncTimeoutName)

flags.Uint(option.K8sWatcherQueueSize, 1024, "Queue size used to serialize each k8s event type")
option.BindEnv(option.K8sWatcherQueueSize)

Expand Down
3 changes: 1 addition & 2 deletions daemon/k8s_watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ const (
k8sAPIGroupCiliumNetworkPolicyV2 = "cilium/v2::CiliumNetworkPolicy"
k8sAPIGroupCiliumNodeV2 = "cilium/v2::CiliumNode"
k8sAPIGroupCiliumEndpointV2 = "cilium/v2::CiliumEndpoint"
cacheSyncTimeout = time.Duration(3 * time.Minute)

metricCNP = "CiliumNetworkPolicy"
metricEndpoint = "Endpoint"
Expand Down Expand Up @@ -303,7 +302,7 @@ func (d *Daemon) initK8sSubsystem() <-chan struct{} {
select {
case <-cachesSynced:
log.Info("All pre-existing resources related to policy have been received; continuing")
case <-time.After(cacheSyncTimeout):
case <-time.After(option.Config.K8sSyncTimeout):
log.Fatalf("Timed out waiting for pre-existing resources related to policy to be received; exiting")
}
}()
Expand Down
4 changes: 4 additions & 0 deletions pkg/defaults/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,10 @@ const (
// invoked only for endpoints which are selected by policy changes.
SelectiveRegeneration = true

// K8sSyncTimeout specifies the standard time to allow for synchronizing
// local caches with Kubernetes state before exiting.
K8sSyncTimeout = 3 * time.Minute

// K8sWatcherEndpointSelector specifies the k8s endpoints that Cilium
// should watch for.
K8sWatcherEndpointSelector = "metadata.name!=kube-scheduler,metadata.name!=kube-controller-manager,metadata.name!=etcd-operator,metadata.name!=gcp-controller-manager"
Expand Down
5 changes: 5 additions & 0 deletions pkg/option/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,9 @@ const (
// K8sServiceCacheSize is service cache size for cilium k8s package.
K8sServiceCacheSize = "k8s-service-cache-size"

// K8sSyncTimeout is the timeout to synchronize all resources with k8s.
K8sSyncTimeoutName = "k8s-sync-timeout"

// K8sWatcherQueueSize is the queue size used to serialize each k8s event type
K8sWatcherQueueSize = "k8s-watcher-queue-size"

Expand Down Expand Up @@ -1014,6 +1017,7 @@ type DaemonConfig struct {
IPv6ServiceRange string
K8sAPIServer string
K8sKubeConfigPath string
K8sSyncTimeout time.Duration
K8sWatcherEndpointSelector string
KVStore string
KVStoreOpt map[string]string
Expand Down Expand Up @@ -1635,6 +1639,7 @@ func (c *DaemonConfig) Populate() {
c.K8sServiceCacheSize = uint(viper.GetInt(K8sServiceCacheSize))
c.K8sForceJSONPatch = viper.GetBool(K8sForceJSONPatch)
c.K8sEventHandover = viper.GetBool(K8sEventHandover)
c.K8sSyncTimeout = viper.GetDuration(K8sSyncTimeoutName)
c.K8sWatcherQueueSize = uint(viper.GetInt(K8sWatcherQueueSize))
c.K8sWatcherEndpointSelector = viper.GetString(K8sWatcherEndpointSelector)
c.KeepTemplates = viper.GetBool(KeepBPFTemplates)
Expand Down

0 comments on commit d9886df

Please sign in to comment.