Skip to content

Commit f214a44

Browse files
committed
fix: hubble not showing services and app names on relay and ui
This PR fixes the issue where service IPs are not being resolved in the Hubble relay's flow logs and app names are not showing up on Hubble UI. This was done by introducing a service cache and a label cache via the service and cilium identity controllers. Signed-off-by: Quang Nguyen <[email protected]>
1 parent 95a48c1 commit f214a44

File tree

14 files changed

+1441
-58
lines changed

14 files changed

+1441
-58
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ fmt: ## run gofumpt on $FMT_PKG (default "retina").
140140
$(GOFUMPT) -w $(FMT_PKG)
141141

142142
lint: ## Fast lint vs default branch showing only new issues.
143-
$(GOLANGCI_LINT) run --new-from-rev main --timeout 10m -v $(LINT_PKG)/...
143+
$(GOLANGCI_LINT) run --new-from-rev main --timeout 10m --concurrency 8 -v $(LINT_PKG)/...
144144

145145
lint-existing: ## Lint the current branch in entirety.
146146
$(GOLANGCI_LINT) run -v $(LINT_PKG)/...

cmd/hubble/cells_linux.go

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,6 @@ import (
99
"github.com/cilium/cilium/pkg/gops"
1010
hubblecell "github.com/cilium/cilium/pkg/hubble/cell"
1111
exportercell "github.com/cilium/cilium/pkg/hubble/exporter/cell"
12-
hubbleParser "github.com/cilium/cilium/pkg/hubble/parser"
13-
"github.com/cilium/cilium/pkg/ipcache"
14-
"github.com/cilium/cilium/pkg/k8s"
1512
k8sClient "github.com/cilium/cilium/pkg/k8s/client"
1613
"github.com/cilium/cilium/pkg/logging"
1714
"github.com/cilium/cilium/pkg/logging/logfields"
@@ -20,13 +17,13 @@ import (
2017
"github.com/cilium/cilium/pkg/pprof"
2118
"github.com/cilium/cilium/pkg/recorder"
2219
"github.com/cilium/hive/cell"
23-
"github.com/sirupsen/logrus"
2420
"k8s.io/client-go/rest"
2521

2622
"github.com/microsoft/retina/internal/buildinfo"
2723
"github.com/microsoft/retina/pkg/config"
2824
rnode "github.com/microsoft/retina/pkg/controllers/daemon/nodereconciler"
2925
"github.com/microsoft/retina/pkg/hubble/parser"
26+
"github.com/microsoft/retina/pkg/hubble/resources"
3027
retinak8s "github.com/microsoft/retina/pkg/k8s"
3128
"github.com/microsoft/retina/pkg/managers/pluginmanager"
3229
"github.com/microsoft/retina/pkg/monitoragent"
@@ -97,11 +94,9 @@ var (
9794

9895
recorder.Cell,
9996

100-
cell.Provide(
101-
func(l logrus.FieldLogger, ipc *ipcache.IPCache, sc *k8s.ServiceCacheImpl) hubbleParser.Decoder {
102-
return parser.New(l.WithField("decoder", nil), sc, ipc)
103-
},
104-
),
97+
// Provides resources for hubble
98+
resources.Cell,
99+
cell.Provide(parser.New),
105100

106101
// Provides the node reconciler as node manager
107102
rnode.Cell,

cmd/hubble/daemon_linux.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import (
2828
"github.com/cilium/hive/cell"
2929
"github.com/cilium/workerpool"
3030

31+
cilium_api_v2 "github.com/cilium/cilium/pkg/k8s/apis/cilium.io/v2"
3132
corev1 "k8s.io/api/core/v1"
3233
k8sruntime "k8s.io/apimachinery/pkg/runtime"
3334
"k8s.io/client-go/rest"
@@ -50,6 +51,11 @@ var (
5051
return nil, nil, errors.Wrap(err, "failed to add corev1 to scheme")
5152
}
5253

54+
if err := cilium_api_v2.AddToScheme(scheme); err != nil { //nolint:govet // intentional shadow
55+
logger.Error("failed to add cilium.io/v2 to scheme")
56+
return nil, nil, errors.Wrap(err, "failed to add cilium.io/v2 to scheme")
57+
}
58+
5359
mgrOption := ctrl.Options{
5460
Scheme: scheme,
5561
Metrics: metricsserver.Options{

deploy/hubble/manifests/controller/helm/retina/values.yaml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -406,9 +406,9 @@ hubble:
406406
# -- Hubble-relay container image.
407407
image:
408408
override: ~
409-
repository: "mcr.microsoft.com/oss/cilium/hubble-relay"
410-
tag: "v1.15.0"
411-
digest: "sha256:19cd56e7618832257bf88b2f281287cb57f9f7fcb9e04775a6198d4bc4daffae"
409+
repository: "quay.io/cilium/hubble-relay-ci"
410+
tag: "latest"
411+
digest: ""
412412
useDigest: false
413413
pullPolicy: "Always"
414414

@@ -650,9 +650,9 @@ hubble:
650650
# -- Hubble-ui backend image.
651651
image:
652652
override: ~
653-
repository: "mcr.microsoft.com/oss/cilium/hubble-ui-backend"
654-
tag: "v0.12.2"
655-
digest: "sha256:b73dd1ac1b7159d42cdba31433964313e756daafefffad5e91c3b61b47c3782f"
653+
repository: "quay.io/cilium/hubble-ui-backend"
654+
tag: "v0.13.2"
655+
digest: "sha256:a034b7e98e6ea796ed26df8f4e71f83fc16465a19d166eff67a03b822c0bfa15"
656656
useDigest: true
657657
pullPolicy: "Always"
658658

@@ -689,9 +689,9 @@ hubble:
689689
# -- Hubble-ui frontend image.
690690
image:
691691
override: ~
692-
repository: "mcr.microsoft.com/oss/cilium/hubble-ui"
693-
tag: "v0.12.2"
694-
digest: "sha256:8c53cdaebb4ae863ad061387a68ea06e38777d2911e6c0e570be1932bb4ba526"
692+
repository: "quay.io/cilium/hubble-ui"
693+
tag: "v0.13.2"
694+
digest: "sha256:9e37c1296b802830834cc87342a9182ccbb71ffebb711971e849221bd9d59392"
695695
useDigest: true
696696
pullPolicy: "Always"
697697

pkg/hubble/common/decoder_linux.go

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77
"github.com/cilium/cilium/api/v1/flow"
88
"github.com/cilium/cilium/pkg/identity"
99
ipc "github.com/cilium/cilium/pkg/ipcache"
10-
"github.com/cilium/cilium/pkg/k8s"
1110
"github.com/cilium/cilium/pkg/labels"
1211
)
1312

@@ -18,15 +17,22 @@ type EpDecoder interface {
1817
IsEndpointOnLocalHost(ip string) bool
1918
}
2019

20+
type LabelCache interface {
21+
// GetLabelsFromSecurityIdentity returns the labels for a given security identity.
22+
GetLabelsFromSecurityIdentity(identity.NumericIdentity) []string
23+
}
24+
2125
type epDecoder struct {
2226
localHostIP string
2327
ipcache *ipc.IPCache
28+
labelCache LabelCache
2429
}
2530

26-
func NewEpDecoder(c *ipc.IPCache) EpDecoder {
31+
func NewEpDecoder(c *ipc.IPCache, lc LabelCache) EpDecoder {
2732
return &epDecoder{
2833
localHostIP: os.Getenv("NODE_IP"),
2934
ipcache: c,
35+
labelCache: lc,
3036
}
3137
}
3238

@@ -54,7 +60,7 @@ func (e *epDecoder) Decode(ip netip.Addr) *flow.Endpoint {
5460
case identity.ReservedIdentityWorld:
5561
ep.Labels = labels.LabelWorld.GetModel()
5662
default:
57-
// TODO: We do not have an api on the ipcache to get the labels from the ip or identity.
63+
ep.Labels = e.labelCache.GetLabelsFromSecurityIdentity(id.ID)
5864
}
5965

6066
return ep
@@ -69,20 +75,3 @@ func (e *epDecoder) IsEndpointOnLocalHost(string) bool {
6975
type SvcDecoder interface {
7076
Decode(ip netip.Addr) *flow.Service
7177
}
72-
73-
type svcDecoder struct {
74-
svccache k8s.ServiceCache
75-
}
76-
77-
func NewSvcDecoder(sc k8s.ServiceCache) SvcDecoder {
78-
return &svcDecoder{
79-
svccache: sc,
80-
}
81-
}
82-
83-
func (s *svcDecoder) Decode(netip.Addr) *flow.Service {
84-
svc := &flow.Service{}
85-
// TODO: serviceCache from cilium do not have a way to get the service name
86-
// and namespace from the ip. We need to add this to the serviceCache.
87-
return svc
88-
}

pkg/hubble/parser/layer34/parser_linux.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ import (
66

77
"github.com/cilium/cilium/api/v1/flow"
88
ipc "github.com/cilium/cilium/pkg/ipcache"
9-
"github.com/cilium/cilium/pkg/k8s"
109

1110
"github.com/microsoft/retina/pkg/hubble/common"
11+
"github.com/microsoft/retina/pkg/hubble/resources"
1212
"github.com/microsoft/retina/pkg/utils"
1313
"github.com/sirupsen/logrus"
1414
"go.uber.org/zap"
@@ -20,11 +20,11 @@ type Parser struct {
2020
epd common.EpDecoder
2121
}
2222

23-
func New(l *logrus.Entry, svc k8s.ServiceCache, c *ipc.IPCache) *Parser {
23+
func New(l *logrus.Entry, svc *resources.ServiceReconciler, c *ipc.IPCache, labelCache common.LabelCache) *Parser {
2424
p := &Parser{
2525
l: l.WithField("subsys", "layer34"),
26-
svd: common.NewSvcDecoder(svc),
27-
epd: common.NewEpDecoder(c),
26+
svd: svc,
27+
epd: common.NewEpDecoder(c, labelCache),
2828
}
2929
// Log the localHostIP for debugging purposes.
3030
return p

pkg/hubble/parser/parser_linux.go

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,14 @@ import (
66
"github.com/cilium/cilium/api/v1/flow"
77
v1 "github.com/cilium/cilium/pkg/hubble/api/v1"
88
observer "github.com/cilium/cilium/pkg/hubble/observer/types"
9+
"github.com/cilium/cilium/pkg/hubble/parser"
910
ipc "github.com/cilium/cilium/pkg/ipcache"
10-
"github.com/cilium/cilium/pkg/k8s"
11+
"github.com/cilium/hive/cell"
12+
"github.com/microsoft/retina/pkg/hubble/common"
1113
"github.com/microsoft/retina/pkg/hubble/parser/layer34"
1214
"github.com/microsoft/retina/pkg/hubble/parser/seven"
15+
"github.com/microsoft/retina/pkg/hubble/resources"
16+
1317
"github.com/sirupsen/logrus"
1418
"go.uber.org/zap"
1519
"google.golang.org/protobuf/types/known/timestamppb"
@@ -22,23 +26,30 @@ var (
2226
errUnknownPayload = errors.New("unknown payload")
2327
)
2428

29+
type Params struct {
30+
cell.In
31+
32+
Logger logrus.FieldLogger
33+
ServiceReconciler *resources.ServiceReconciler
34+
LabelCache common.LabelCache
35+
36+
IPCache *ipc.IPCache
37+
}
38+
2539
type Parser struct {
26-
l logrus.FieldLogger
27-
ipcache *ipc.IPCache
28-
svc k8s.ServiceCache
40+
l *logrus.Entry
2941

3042
l34 *layer34.Parser
3143
l7 *seven.Parser
3244
}
3345

34-
func New(l *logrus.Entry, svc k8s.ServiceCache, c *ipc.IPCache) *Parser {
46+
func New(params Params) parser.Decoder {
47+
logger := params.Logger.WithField("subsys", "payloadparser")
3548
return &Parser{
36-
l: l,
37-
ipcache: c,
38-
svc: svc,
49+
l: logger,
3950

40-
l34: layer34.New(l, svc, c),
41-
l7: seven.New(l, svc, c),
51+
l34: layer34.New(logger, params.ServiceReconciler, params.IPCache, params.LabelCache),
52+
l7: seven.New(logger, params.ServiceReconciler, params.IPCache, params.LabelCache),
4253
}
4354
}
4455

pkg/hubble/parser/seven/parser_linux.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ import (
77

88
"github.com/cilium/cilium/api/v1/flow"
99
ipc "github.com/cilium/cilium/pkg/ipcache"
10-
"github.com/cilium/cilium/pkg/k8s"
1110
"github.com/google/gopacket/layers"
1211
"github.com/microsoft/retina/pkg/hubble/common"
12+
"github.com/microsoft/retina/pkg/hubble/resources"
1313
"github.com/sirupsen/logrus"
1414
"go.uber.org/zap"
1515
)
@@ -20,11 +20,11 @@ type Parser struct {
2020
epd common.EpDecoder
2121
}
2222

23-
func New(l *logrus.Entry, svc k8s.ServiceCache, c *ipc.IPCache) *Parser {
23+
func New(l *logrus.Entry, svc *resources.ServiceReconciler, c *ipc.IPCache, labelCache common.LabelCache) *Parser {
2424
return &Parser{
2525
l: l.WithField("subsys", "seven"),
26-
svd: common.NewSvcDecoder(svc),
27-
epd: common.NewEpDecoder(c),
26+
svd: svc,
27+
epd: common.NewEpDecoder(c, labelCache),
2828
}
2929
}
3030

pkg/hubble/resources/cell_linux.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package resources
2+
3+
import (
4+
"github.com/cilium/hive/cell"
5+
"github.com/pkg/errors"
6+
"go.uber.org/zap"
7+
ctrl "sigs.k8s.io/controller-runtime"
8+
)
9+
10+
var Cell = cell.Module(
11+
"resources",
12+
"Resources for Hubble",
13+
cell.Provide(NewServiceReconciler),
14+
cell.Provide(NewCiliumIdentityReconciler),
15+
cell.Invoke(func(svc *ServiceReconciler, cid *CiliumIdentityReconciler, ctrlManager ctrl.Manager) error {
16+
if err := svc.SetupWithManager(ctrlManager); err != nil {
17+
svc.logger.Error("failed to setup service reconciler with manager", zap.Error(err))
18+
return errors.Wrap(err, "failed to setup service reconciler with manager")
19+
}
20+
svc.logger.Info("Service reconciler setup completed")
21+
if err := cid.SetupWithManager(ctrlManager); err != nil {
22+
cid.logger.Error("failed to setup cilium identity reconciler with manager", zap.Error(err))
23+
return errors.Wrap(err, "failed to setup cilium identity reconciler with manager")
24+
}
25+
cid.logger.Info("Cilium identity reconciler setup completed")
26+
return nil
27+
}),
28+
)

0 commit comments

Comments
 (0)