Skip to content

Commit

Permalink
Remove Cilium state service cache
Browse files Browse the repository at this point in the history
Tetragon doesn't use the service cache anymore.

Signed-off-by: Michi Mutsuzaki <[email protected]>
  • Loading branch information
michi-covalent authored and jrfastab committed Jun 6, 2024
1 parent dea5ed1 commit 0159ade
Show file tree
Hide file tree
Showing 7 changed files with 4 additions and 301 deletions.
5 changes: 0 additions & 5 deletions pkg/cilium/monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,6 @@ func consumeMonitorEvents(ctx context.Context, conn net.Conn, ciliumState *ciliu
dnsAdd := ciliumState.GetLogRecordNotifyChannel()
ipCacheEvents := make(chan monitorAPI.AgentNotify, 100)
ciliumState.StartMirroringIPCache(ipCacheEvents)
serviceEvents := make(chan monitorAPI.AgentNotify, 100)
ciliumState.StartMirroringServiceCache(serviceEvents)
for {
if err := pl.DecodeBinary(dec); err != nil {
return err
Expand All @@ -90,9 +88,6 @@ func consumeMonitorEvents(ctx context.Context, conn net.Conn, ciliumState *ciliu
case monitorAPI.AgentNotifyIPCacheUpserted,
monitorAPI.AgentNotifyIPCacheDeleted:
ipCacheEvents <- an
case monitorAPI.AgentNotifyServiceUpserted,
monitorAPI.AgentNotifyServiceDeleted:
serviceEvents <- an
}
case monitorAPI.MessageTypeAccessLog:
// TODO re-think the way this is being done. We are dissecting/
Expand Down
3 changes: 0 additions & 3 deletions pkg/cilium/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (
"github.com/cilium/tetragon/pkg/oldhubble/cilium/client"
"github.com/cilium/tetragon/pkg/oldhubble/fqdncache"
"github.com/cilium/tetragon/pkg/oldhubble/ipcache"
"github.com/cilium/tetragon/pkg/oldhubble/servicecache"
)

var (
Expand Down Expand Up @@ -43,7 +42,6 @@ func InitCiliumState(ctx context.Context, enableCiliumAPI bool) (*cilium.State,
v1.NewEndpoints(),
ipcache.New(),
fqdncache.New(),
servicecache.New(),
logger.GetLogger().WithField("subsystem", "cilium"))
go ciliumState.Start()
go HandleMonitorSocket(ctx, ciliumState)
Expand All @@ -57,7 +55,6 @@ func GetFakeCiliumState() *cilium.State {
v1.NewEndpoints(),
ipcache.New(),
fqdncache.New(),
servicecache.New(),
logger.GetLogger().WithField("subsystem", "cilium"))
}

Expand Down
10 changes: 0 additions & 10 deletions pkg/oldhubble/cilium/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ type Client interface {
GetIdentity(id uint64) (*models.Identity, error)
GetFqdnCache() ([]*models.DNSLookup, error)
GetIPCache() ([]*models.IPListEntry, error)
GetServiceCache() ([]*models.Service, error)
}

// Cilium is an abstraction to communicate with the cilium-agent.
Expand Down Expand Up @@ -84,15 +83,6 @@ func (c *Cilium) GetIPCache() ([]*models.IPListEntry, error) {
return ips.Payload, nil
}

// GetServiceCache retrieves the contents of the Cilium service cache.
func (c *Cilium) GetServiceCache() ([]*models.Service, error) {
svcs, err := c.Client.Service.GetService(nil)
if err != nil {
return nil, err
}
return svcs.Payload, nil
}

// IsIPCacheNotFoundErr is true if the IPCache fetch error was a 404
func IsIPCacheNotFoundErr(err error) bool {
_, ok := err.(*ciliumPolicy.GetIPNotFound)
Expand Down
104 changes: 0 additions & 104 deletions pkg/oldhubble/cilium/service.go

This file was deleted.

29 changes: 4 additions & 25 deletions pkg/oldhubble/cilium/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
v1 "github.com/cilium/tetragon/pkg/oldhubble/api/v1"
"github.com/cilium/tetragon/pkg/oldhubble/cilium/client"
"github.com/cilium/tetragon/pkg/oldhubble/ipcache"
"github.com/cilium/tetragon/pkg/oldhubble/servicecache"
"github.com/sirupsen/logrus"
)

Expand All @@ -30,9 +29,6 @@ type State struct {
// ipcache is a mirror of Cilium's IPCache
ipcache *ipcache.IPCache

// serviceCache is a cache that contains information about services.
serviceCache *servicecache.ServiceCache

// logRecord is a channel used to exchange L7 DNS requests seens from the
// monitor
logRecord chan monitor.LogRecordNotify
Expand All @@ -48,14 +44,13 @@ func NewCiliumState(
endpoints v1.EndpointsHandler,
ipCache *ipcache.IPCache,
fqdnCache FqdnCache,
serviceCache *servicecache.ServiceCache,
logger *logrus.Entry,
) *State {
return &State{
ciliumClient: ciliumClient,
endpoints: endpoints,
ipcache: ipCache,
fqdnCache: fqdnCache, serviceCache: serviceCache,
ciliumClient: ciliumClient,
endpoints: endpoints,
ipcache: ipCache,
fqdnCache: fqdnCache,
logRecord: make(chan monitor.LogRecordNotify, 100),
endpointEvents: make(chan monitorAPI.AgentNotify, 100),
log: logger,
Expand All @@ -82,17 +77,6 @@ func (s *State) StartMirroringIPCache(ipCacheEvents <-chan monitorAPI.AgentNotif
go s.syncIPCache(ipCacheEvents)
}

// StartMirroringServiceCache initially caches service information from Cilium
// and then starts to mirror service information based on events that are sent
// to the serviceEvents channel. Only messages of type
// `AgentNotifyServiceUpserted` and `AgentNotifyServiceDeleted` should be sent
// to this channel. This function assumes that the caller is already connected
// to Cilium Monitor, i.e. no Service notification must be lost after calling
// this method.
func (s *State) StartMirroringServiceCache(serviceEvents <-chan monitorAPI.AgentNotify) {
go s.syncServiceCache(serviceEvents)
}

// GetLogRecordNotifyChannel returns the event channel to receive
// monitorAPI.LogRecordNotify events.
func (s *State) GetLogRecordNotifyChannel() chan<- monitor.LogRecordNotify {
Expand Down Expand Up @@ -125,8 +109,3 @@ func (s *State) GetFQDNCache() FqdnCache {
func (s *State) GetIPCache() *ipcache.IPCache {
return s.ipcache
}

// GetServiceCache returns serviceCache.
func (s *State) GetServiceCache() *servicecache.ServiceCache {
return s.serviceCache
}
6 changes: 0 additions & 6 deletions pkg/oldhubble/parser/getters/getters.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ package getters
import (
"net"

pb "github.com/cilium/cilium/api/v1/flow"
v1 "github.com/cilium/tetragon/pkg/oldhubble/api/v1"
"github.com/cilium/tetragon/pkg/oldhubble/ipcache"

Expand Down Expand Up @@ -37,8 +36,3 @@ type IPGetter interface {
// GetIPIdentity fetches information known about a remote IP.
GetIPIdentity(ip net.IP) (identity ipcache.IPIdentity, ok bool)
}

// ServiceGetter fetches service metadata.
type ServiceGetter interface {
GetServiceByAddr(ip net.IP, port uint16) (service pb.Service, ok bool)
}
Loading

0 comments on commit 0159ade

Please sign in to comment.