Skip to content

Commit

Permalink
feat(hubble): Add Ciliumendpoint and Service resource to k8s watcher (#…
Browse files Browse the repository at this point in the history
…900)

# Description

Add CiliumEndpoint and Service objects to IPCache for flow enrichment.

## Related Issue

#536

## Checklist

- [x] I have read the [contributing
documentation](https://retina.sh/docs/contributing).
- [x] I signed and signed-off the commits (`git commit -S -s ...`). See
[this
documentation](https://docs.github.com/en/authentication/managing-commit-signature-verification/about-commit-signature-verification)
on signing commits.
- [x] I have correctly attributed the author(s) of the code.
- [x] I have tested the changes locally.
- [x] I have followed the project's style guidelines.
- [x] I have updated the documentation, if necessary.
- [x] I have added tests, if applicable.

## Screenshots (if applicable) or Testing Completed

```bash
Oct 27 18:19:13.348: kube-system/alpine:59204 (ID:45406) -> 10.0.216.107:8080 (world) to-stack FORWARDED (TCP Flags: SYN:true)
Oct 27 18:19:13.350: kube-system/alpine:59204 (ID:45406) <- 10.0.216.107:8080 (world) to-endpoint FORWARDED (TCP Flags: SYN:true  ACK:true)
Oct 27 18:19:13.350: kube-system/alpine:59204 (ID:45406) -> 10.0.216.107:8080 (world) to-stack FORWARDED (TCP Flags: ACK:true)
Oct 27 18:19:13.350: kube-system/alpine:59204 (ID:45406) -> 10.0.216.107:8080 (world) to-stack FORWARDED (TCP Flags: PSH:true  ACK:true)
Oct 27 18:19:13.352: kube-system/alpine:59204 (ID:45406) <- 10.0.216.107:8080 (world) to-endpoint FORWARDED (TCP Flags: PSH:true  ACK:true)
Oct 27 18:19:13.352: kube-system/alpine:59204 (ID:45406) <- 10.0.216.107:8080 (world) to-endpoint FORWARDED (TCP Flags: FIN:true  ACK:true)
Oct 27 18:19:13.352: 10.0.216.107:8080 (world) <- kube-system/alpine:59204 (ID:45406) to-stack FORWARDED (TCP Flags: FIN:true  ACK:true)
Oct 27 18:19:13.352: default/kapinger-good-6b6c74547d-5db4w:8080 (ID:12871) -> kube-system/alpine:59204 (ID:45406) to-stack FORWARDED (TCP Flags: SYN:true  ACK:true)
Oct 27 18:19:13.353: 10.0.216.107:8080 (world) -> kube-system/alpine:59204 (ID:45406) to-endpoint FORWARDED (TCP Flags: ACK:true)
Oct 27 18:19:13.354: default/kapinger-good-6b6c74547d-5db4w:8080 (ID:12871) -> kube-system/alpine:59204 (ID:45406) to-stack FORWARDED (TCP Flags: ACK:true)
Oct 27 18:19:13.354: default/kapinger-good-6b6c74547d-5db4w:8080 (ID:12871) -> kube-system/alpine:59204 (ID:45406) to-stack FORWARDED (TCP Flags: PSH:true  ACK:true)
Oct 27 18:19:13.355: default/kapinger-good-6b6c74547d-5db4w:8080 (ID:12871) -> kube-system/alpine:59204 (ID:45406) to-stack FORWARDED (TCP Flags: FIN:true  ACK:true)
Oct 27 18:19:13.355: kube-system/alpine:59204 (ID:45406) <- default/kapinger-good-6b6c74547d-5db4w:8080 (ID:12871) to-stack FORWARDED (TCP Flags: ACK:true)
```

## Additional Notes

Add any additional notes or context about the pull request here.

---

Please refer to the [CONTRIBUTING.md](../CONTRIBUTING.md) file for more
information on how to contribute to this project.
  • Loading branch information
anubhabMajumdar authored Oct 28, 2024
1 parent 06e4a5e commit b4837fc
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 12 deletions.
25 changes: 18 additions & 7 deletions pkg/k8s/cell_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,9 @@ var Cell = cell.Module(
func() resource.Resource[*cilium_api_v2alpha1.CiliumEndpointSlice] {
return &fakeresource[*cilium_api_v2alpha1.CiliumEndpointSlice]{}
},
func() resource.Resource[*types.CiliumEndpoint] {
return &fakeresource[*types.CiliumEndpoint]{}
},
func() resource.Resource[*cilium_api_v2.CiliumNode] {
return &fakeresource[*cilium_api_v2.CiliumNode]{}
},
func() daemonk8s.ServiceNonHeadless {
return &fakeresource[*slim_corev1.Service]{}
},
func() daemonk8s.EndpointsNonHeadless {
return &fakeresource[*ciliumk8s.Endpoints]{}
},
Expand All @@ -74,6 +68,12 @@ var Cell = cell.Module(
},
),

// Provide the resources needed by the watchers.

cell.Provide(func(lc cell.Lifecycle, cs client.Clientset) (resource.Resource[*types.CiliumEndpoint], error) {
return ciliumk8s.CiliumSlimEndpointResource(lc, cs, nil)
}),

cell.Provide(func(lc cell.Lifecycle, cs client.Clientset) (resource.Resource[*ciliumk8s.Endpoints], error) {
//nolint:wrapcheck // a wrapped error here is of dubious value
return ciliumk8s.EndpointsResource(lc, ciliumk8s.Config{
Expand All @@ -88,7 +88,18 @@ var Cell = cell.Module(
lc,
ciliumk8s.Config{
EnableK8sEndpointSlice: false,
K8sServiceProxyName: "",
},
cs,
func(*metav1.ListOptions) {},
)
}),

cell.Provide(func(lc cell.Lifecycle, cs client.Clientset) (daemonk8s.ServiceNonHeadless, error) {
//nolint:wrapcheck // a wrapped error here is of dubious value
return ciliumk8s.ServiceResource(
lc,
ciliumk8s.Config{
EnableK8sEndpointSlice: false,
},
cs,
func(*metav1.ListOptions) {},
Expand Down
10 changes: 5 additions & 5 deletions pkg/k8s/watcher_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ import (

const (
K8sAPIGroupCiliumEndpointV2 = "cilium/v2::CiliumEndpoint"
K8sAPIGroupServiceV1Core = "core/v1::Service"
)

var (
once sync.Once
w *watchers.K8sWatcher
logger = logging.DefaultLogger.WithField(logfields.LogSubsys, "k8s-watcher")
// k8sResources = []string{K8sAPIGroupCiliumEndpointV2, resources.K8sAPIGroupServiceV1Core}
k8sResources = []string{}
once sync.Once
w *watchers.K8sWatcher
logger = logging.DefaultLogger.WithField(logfields.LogSubsys, "k8s-watcher")
k8sResources = []string{K8sAPIGroupCiliumEndpointV2, K8sAPIGroupServiceV1Core}
)

type watcherParams struct {
Expand Down

0 comments on commit b4837fc

Please sign in to comment.