Skip to content

Commit

Permalink
cmd/contour: only create snapshot handler for envoy xDS server (#5973)
Browse files Browse the repository at this point in the history
Since the snapshot handler is only used for the envoy
xDS server type, only instantiate it and wire it up
when using that server type.

Signed-off-by: Steve Kriss <krisss@vmware.com>
  • Loading branch information
skriss authored Nov 17, 2023
1 parent e3e0f34 commit 55aa95d
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions cmd/contour/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -484,14 +484,18 @@ func (s *Server) doServe() error {

// snapshotHandler triggers go-control-plane Snapshots based on
// the contents of the Contour xDS caches after the DAG is built.
snapshotHandler := xdscache_v3.NewSnapshotHandler(
resources,
envoy_cache_v3.NewSnapshotCache(false, &contour_xds_v3.Hash, s.log.WithField("context", "snapshotCache")),
s.log.WithField("context", "snapshotHandler"),
)
var snapshotHandler *xdscache_v3.SnapshotHandler

if contourConfiguration.XDSServer.Type == contour_api_v1alpha1.EnvoyServerType {
snapshotHandler = xdscache_v3.NewSnapshotHandler(
resources,
envoy_cache_v3.NewSnapshotCache(false, &contour_xds_v3.Hash, s.log.WithField("context", "snapshotCache")),
s.log.WithField("context", "snapshotHandler"),
)

// register observer for endpoints updates.
endpointHandler.SetObserver(contour.ComposeObservers(snapshotHandler))
// register observer for endpoints updates.
endpointHandler.SetObserver(contour.ComposeObservers(snapshotHandler))
}

// Log that we're using the fallback certificate if configured.
if contourConfiguration.HTTPProxy.FallbackCertificate != nil {
Expand Down Expand Up @@ -559,9 +563,14 @@ func (s *Server) doServe() error {
})

// Build the core Kubernetes event handler.
xdsCaches := xdscache.ObserversOf(resources)
if snapshotHandler != nil {
xdsCaches = append(xdsCaches, snapshotHandler)
}

observer := contour.NewRebuildMetricsObserver(
contourMetrics,
dag.ComposeObservers(append(xdscache.ObserversOf(resources), snapshotHandler)...),
dag.ComposeObservers(xdsCaches...),
)

hasSynced := func() bool {
Expand Down

0 comments on commit 55aa95d

Please sign in to comment.