From cac60ce49181213501bf9a207b12f2372d49939b Mon Sep 17 00:00:00 2001 From: aicee Date: Fri, 27 Jun 2025 17:53:54 +0800 Subject: [PATCH 1/6] Sort dump output by name Signed-off-by: aicee --- pkg/status/status_server.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/pkg/status/status_server.go b/pkg/status/status_server.go index 9486d4ce5..bf6c52a49 100644 --- a/pkg/status/status_server.go +++ b/pkg/status/status_server.go @@ -23,6 +23,7 @@ import ( "io" "net/http" "net/http/pprof" + "sort" "strconv" "time" @@ -568,6 +569,16 @@ func (s *Server) StopServer() error { } func printWorkloadDump(w http.ResponseWriter, wd WorkloadDump) { + sort.Slice(wd.Workloads, func(i, j int) bool { + return wd.Workloads[i].Name < wd.Workloads[j].Name + }) + sort.Slice(wd.Services, func(i, j int) bool { + return wd.Services[i].Name < wd.Services[j].Name + }) + sort.Slice(wd.Policies, func(i, j int) bool { + return wd.Policies[i].Name < wd.Policies[j].Name + }) + data, err := json.MarshalIndent(wd, "", " ") if err != nil { log.Errorf("Failed to marshal WorkloadDump: %v", err) From 6b545798ef05fcd8b27dfa912c08690d4417f962 Mon Sep 17 00:00:00 2001 From: aicee Date: Wed, 2 Jul 2025 10:25:03 +0800 Subject: [PATCH 2/6] add unit test for sorting dump output by name Signed-off-by: aicee --- .../kernelnative/kmeshcgroupsock_bpfeb.go | 242 +++++++++ .../kernelnative/kmeshcgroupsock_bpfel.go | 242 +++++++++ .../kmeshcgroupsockcompat_bpfeb.go | 242 +++++++++ .../kmeshcgroupsockcompat_bpfel.go | 242 +++++++++ .../bpf2go/kernelnative/kmeshsockops_bpfeb.go | 192 +++++++ .../bpf2go/kernelnative/kmeshsockops_bpfel.go | 192 +++++++ .../kernelnative/kmeshsockopscompat_bpfeb.go | 192 +++++++ .../kernelnative/kmeshsockopscompat_bpfel.go | 192 +++++++ pkg/status/status_server_test.go | 168 +++++- .../workload_configdump_modified.json | 495 ++++++++++++++++++ .../workload_configdump_original.json | 495 ++++++++++++++++++ 11 files changed, 2880 insertions(+), 14 deletions(-) create mode 100644 bpf/kmesh/bpf2go/kernelnative/kmeshcgroupsock_bpfeb.go create mode 100644 bpf/kmesh/bpf2go/kernelnative/kmeshcgroupsock_bpfel.go create mode 100644 bpf/kmesh/bpf2go/kernelnative/kmeshcgroupsockcompat_bpfeb.go create mode 100644 bpf/kmesh/bpf2go/kernelnative/kmeshcgroupsockcompat_bpfel.go create mode 100644 bpf/kmesh/bpf2go/kernelnative/kmeshsockops_bpfeb.go create mode 100644 bpf/kmesh/bpf2go/kernelnative/kmeshsockops_bpfel.go create mode 100644 bpf/kmesh/bpf2go/kernelnative/kmeshsockopscompat_bpfeb.go create mode 100644 bpf/kmesh/bpf2go/kernelnative/kmeshsockopscompat_bpfel.go create mode 100644 pkg/status/testdata/workload_configdump_modified.json create mode 100644 pkg/status/testdata/workload_configdump_original.json diff --git a/bpf/kmesh/bpf2go/kernelnative/kmeshcgroupsock_bpfeb.go b/bpf/kmesh/bpf2go/kernelnative/kmeshcgroupsock_bpfeb.go new file mode 100644 index 000000000..e9a4db93e --- /dev/null +++ b/bpf/kmesh/bpf2go/kernelnative/kmeshcgroupsock_bpfeb.go @@ -0,0 +1,242 @@ +// Code generated by bpf2go; DO NOT EDIT. +//go:build mips || mips64 || ppc64 || s390x + +package bpf2go + +import ( + "bytes" + _ "embed" + "fmt" + "io" + + "github.com/cilium/ebpf" +) + +type KmeshCgroupSockBuf struct{ Data [40]int8 } + +type KmeshCgroupSockClusterSockData struct{ ClusterId uint32 } + +type KmeshCgroupSockManagerKey struct { + NetnsCookie uint64 + _ [8]byte +} + +type KmeshCgroupSockRatelimitKey struct { + Key struct { + SkSkb struct { + Netns uint64 + Ipv4 uint32 + Port uint32 + Family uint32 + _ [4]byte + } + } +} + +type KmeshCgroupSockRatelimitValue struct { + LastTopup uint64 + Tokens uint64 +} + +type KmeshCgroupSockSockStorageData struct { + ConnectNs uint64 + LastReportNs uint64 + Direction uint8 + ConnectSuccess uint8 + ViaWaypoint bool + HasEncoded bool + HasSetIp bool + _ [3]byte + SkTuple struct { + Ipv4 struct { + Saddr uint32 + Daddr uint32 + Sport uint16 + Dport uint16 + } + _ [24]byte + } + _ [4]byte +} + +// LoadKmeshCgroupSock returns the embedded CollectionSpec for KmeshCgroupSock. +func LoadKmeshCgroupSock() (*ebpf.CollectionSpec, error) { + reader := bytes.NewReader(_KmeshCgroupSockBytes) + spec, err := ebpf.LoadCollectionSpecFromReader(reader) + if err != nil { + return nil, fmt.Errorf("can't load KmeshCgroupSock: %w", err) + } + + return spec, err +} + +// LoadKmeshCgroupSockObjects loads KmeshCgroupSock and converts it into a struct. +// +// The following types are suitable as obj argument: +// +// *KmeshCgroupSockObjects +// *KmeshCgroupSockPrograms +// *KmeshCgroupSockMaps +// +// See ebpf.CollectionSpec.LoadAndAssign documentation for details. +func LoadKmeshCgroupSockObjects(obj interface{}, opts *ebpf.CollectionOptions) error { + spec, err := LoadKmeshCgroupSock() + if err != nil { + return err + } + + return spec.LoadAndAssign(obj, opts) +} + +// KmeshCgroupSockSpecs contains maps and programs before they are loaded into the kernel. +// +// It can be passed ebpf.CollectionSpec.Assign. +type KmeshCgroupSockSpecs struct { + KmeshCgroupSockProgramSpecs + KmeshCgroupSockMapSpecs + KmeshCgroupSockVariableSpecs +} + +// KmeshCgroupSockProgramSpecs contains programs before they are loaded into the kernel. +// +// It can be passed ebpf.CollectionSpec.Assign. +type KmeshCgroupSockProgramSpecs struct { + CgroupConnect4Prog *ebpf.ProgramSpec `ebpf:"cgroup_connect4_prog"` + ClusterManager *ebpf.ProgramSpec `ebpf:"cluster_manager"` + FilterChainManager *ebpf.ProgramSpec `ebpf:"filter_chain_manager"` + FilterManager *ebpf.ProgramSpec `ebpf:"filter_manager"` +} + +// KmeshCgroupSockMapSpecs contains maps before they are loaded into the kernel. +// +// It can be passed ebpf.CollectionSpec.Assign. +type KmeshCgroupSockMapSpecs struct { + KmCgrptailcall *ebpf.MapSpec `ebpf:"km_cgrptailcall"` + KmCluster *ebpf.MapSpec `ebpf:"km_cluster"` + KmClusterEps *ebpf.MapSpec `ebpf:"km_cluster_eps"` + KmClusterSock *ebpf.MapSpec `ebpf:"km_cluster_sock"` + KmClusterstats *ebpf.MapSpec `ebpf:"km_clusterstats"` + KmEpsData *ebpf.MapSpec `ebpf:"km_eps_data"` + KmListener *ebpf.MapSpec `ebpf:"km_listener"` + KmLogEvent *ebpf.MapSpec `ebpf:"km_log_event"` + KmMaglevOuter *ebpf.MapSpec `ebpf:"km_maglev_outer"` + KmManage *ebpf.MapSpec `ebpf:"km_manage"` + KmRatelimit *ebpf.MapSpec `ebpf:"km_ratelimit"` + KmSockstorage *ebpf.MapSpec `ebpf:"km_sockstorage"` + KmTailcallCtx *ebpf.MapSpec `ebpf:"km_tailcall_ctx"` + KmTmpbuf *ebpf.MapSpec `ebpf:"km_tmpbuf"` + KmeshMap1600 *ebpf.MapSpec `ebpf:"kmesh_map1600"` + KmeshMap192 *ebpf.MapSpec `ebpf:"kmesh_map192"` + KmeshMap296 *ebpf.MapSpec `ebpf:"kmesh_map296"` + KmeshMap64 *ebpf.MapSpec `ebpf:"kmesh_map64"` +} + +// KmeshCgroupSockVariableSpecs contains global variables before they are loaded into the kernel. +// +// It can be passed ebpf.CollectionSpec.Assign. +type KmeshCgroupSockVariableSpecs struct { + BpfLogLevel *ebpf.VariableSpec `ebpf:"bpf_log_level"` +} + +// KmeshCgroupSockObjects contains all objects after they have been loaded into the kernel. +// +// It can be passed to LoadKmeshCgroupSockObjects or ebpf.CollectionSpec.LoadAndAssign. +type KmeshCgroupSockObjects struct { + KmeshCgroupSockPrograms + KmeshCgroupSockMaps + KmeshCgroupSockVariables +} + +func (o *KmeshCgroupSockObjects) Close() error { + return _KmeshCgroupSockClose( + &o.KmeshCgroupSockPrograms, + &o.KmeshCgroupSockMaps, + ) +} + +// KmeshCgroupSockMaps contains all maps after they have been loaded into the kernel. +// +// It can be passed to LoadKmeshCgroupSockObjects or ebpf.CollectionSpec.LoadAndAssign. +type KmeshCgroupSockMaps struct { + KmCgrptailcall *ebpf.Map `ebpf:"km_cgrptailcall"` + KmCluster *ebpf.Map `ebpf:"km_cluster"` + KmClusterEps *ebpf.Map `ebpf:"km_cluster_eps"` + KmClusterSock *ebpf.Map `ebpf:"km_cluster_sock"` + KmClusterstats *ebpf.Map `ebpf:"km_clusterstats"` + KmEpsData *ebpf.Map `ebpf:"km_eps_data"` + KmListener *ebpf.Map `ebpf:"km_listener"` + KmLogEvent *ebpf.Map `ebpf:"km_log_event"` + KmMaglevOuter *ebpf.Map `ebpf:"km_maglev_outer"` + KmManage *ebpf.Map `ebpf:"km_manage"` + KmRatelimit *ebpf.Map `ebpf:"km_ratelimit"` + KmSockstorage *ebpf.Map `ebpf:"km_sockstorage"` + KmTailcallCtx *ebpf.Map `ebpf:"km_tailcall_ctx"` + KmTmpbuf *ebpf.Map `ebpf:"km_tmpbuf"` + KmeshMap1600 *ebpf.Map `ebpf:"kmesh_map1600"` + KmeshMap192 *ebpf.Map `ebpf:"kmesh_map192"` + KmeshMap296 *ebpf.Map `ebpf:"kmesh_map296"` + KmeshMap64 *ebpf.Map `ebpf:"kmesh_map64"` +} + +func (m *KmeshCgroupSockMaps) Close() error { + return _KmeshCgroupSockClose( + m.KmCgrptailcall, + m.KmCluster, + m.KmClusterEps, + m.KmClusterSock, + m.KmClusterstats, + m.KmEpsData, + m.KmListener, + m.KmLogEvent, + m.KmMaglevOuter, + m.KmManage, + m.KmRatelimit, + m.KmSockstorage, + m.KmTailcallCtx, + m.KmTmpbuf, + m.KmeshMap1600, + m.KmeshMap192, + m.KmeshMap296, + m.KmeshMap64, + ) +} + +// KmeshCgroupSockVariables contains all global variables after they have been loaded into the kernel. +// +// It can be passed to LoadKmeshCgroupSockObjects or ebpf.CollectionSpec.LoadAndAssign. +type KmeshCgroupSockVariables struct { + BpfLogLevel *ebpf.Variable `ebpf:"bpf_log_level"` +} + +// KmeshCgroupSockPrograms contains all programs after they have been loaded into the kernel. +// +// It can be passed to LoadKmeshCgroupSockObjects or ebpf.CollectionSpec.LoadAndAssign. +type KmeshCgroupSockPrograms struct { + CgroupConnect4Prog *ebpf.Program `ebpf:"cgroup_connect4_prog"` + ClusterManager *ebpf.Program `ebpf:"cluster_manager"` + FilterChainManager *ebpf.Program `ebpf:"filter_chain_manager"` + FilterManager *ebpf.Program `ebpf:"filter_manager"` +} + +func (p *KmeshCgroupSockPrograms) Close() error { + return _KmeshCgroupSockClose( + p.CgroupConnect4Prog, + p.ClusterManager, + p.FilterChainManager, + p.FilterManager, + ) +} + +func _KmeshCgroupSockClose(closers ...io.Closer) error { + for _, closer := range closers { + if err := closer.Close(); err != nil { + return err + } + } + return nil +} + +// Do not access this directly. +// +//go:embed kmeshcgroupsock_bpfeb.o +var _KmeshCgroupSockBytes []byte diff --git a/bpf/kmesh/bpf2go/kernelnative/kmeshcgroupsock_bpfel.go b/bpf/kmesh/bpf2go/kernelnative/kmeshcgroupsock_bpfel.go new file mode 100644 index 000000000..c318859f4 --- /dev/null +++ b/bpf/kmesh/bpf2go/kernelnative/kmeshcgroupsock_bpfel.go @@ -0,0 +1,242 @@ +// Code generated by bpf2go; DO NOT EDIT. +//go:build 386 || amd64 || arm || arm64 || loong64 || mips64le || mipsle || ppc64le || riscv64 + +package bpf2go + +import ( + "bytes" + _ "embed" + "fmt" + "io" + + "github.com/cilium/ebpf" +) + +type KmeshCgroupSockBuf struct{ Data [40]int8 } + +type KmeshCgroupSockClusterSockData struct{ ClusterId uint32 } + +type KmeshCgroupSockManagerKey struct { + NetnsCookie uint64 + _ [8]byte +} + +type KmeshCgroupSockRatelimitKey struct { + Key struct { + SkSkb struct { + Netns uint64 + Ipv4 uint32 + Port uint32 + Family uint32 + _ [4]byte + } + } +} + +type KmeshCgroupSockRatelimitValue struct { + LastTopup uint64 + Tokens uint64 +} + +type KmeshCgroupSockSockStorageData struct { + ConnectNs uint64 + LastReportNs uint64 + Direction uint8 + ConnectSuccess uint8 + ViaWaypoint bool + HasEncoded bool + HasSetIp bool + _ [3]byte + SkTuple struct { + Ipv4 struct { + Saddr uint32 + Daddr uint32 + Sport uint16 + Dport uint16 + } + _ [24]byte + } + _ [4]byte +} + +// LoadKmeshCgroupSock returns the embedded CollectionSpec for KmeshCgroupSock. +func LoadKmeshCgroupSock() (*ebpf.CollectionSpec, error) { + reader := bytes.NewReader(_KmeshCgroupSockBytes) + spec, err := ebpf.LoadCollectionSpecFromReader(reader) + if err != nil { + return nil, fmt.Errorf("can't load KmeshCgroupSock: %w", err) + } + + return spec, err +} + +// LoadKmeshCgroupSockObjects loads KmeshCgroupSock and converts it into a struct. +// +// The following types are suitable as obj argument: +// +// *KmeshCgroupSockObjects +// *KmeshCgroupSockPrograms +// *KmeshCgroupSockMaps +// +// See ebpf.CollectionSpec.LoadAndAssign documentation for details. +func LoadKmeshCgroupSockObjects(obj interface{}, opts *ebpf.CollectionOptions) error { + spec, err := LoadKmeshCgroupSock() + if err != nil { + return err + } + + return spec.LoadAndAssign(obj, opts) +} + +// KmeshCgroupSockSpecs contains maps and programs before they are loaded into the kernel. +// +// It can be passed ebpf.CollectionSpec.Assign. +type KmeshCgroupSockSpecs struct { + KmeshCgroupSockProgramSpecs + KmeshCgroupSockMapSpecs + KmeshCgroupSockVariableSpecs +} + +// KmeshCgroupSockProgramSpecs contains programs before they are loaded into the kernel. +// +// It can be passed ebpf.CollectionSpec.Assign. +type KmeshCgroupSockProgramSpecs struct { + CgroupConnect4Prog *ebpf.ProgramSpec `ebpf:"cgroup_connect4_prog"` + ClusterManager *ebpf.ProgramSpec `ebpf:"cluster_manager"` + FilterChainManager *ebpf.ProgramSpec `ebpf:"filter_chain_manager"` + FilterManager *ebpf.ProgramSpec `ebpf:"filter_manager"` +} + +// KmeshCgroupSockMapSpecs contains maps before they are loaded into the kernel. +// +// It can be passed ebpf.CollectionSpec.Assign. +type KmeshCgroupSockMapSpecs struct { + KmCgrptailcall *ebpf.MapSpec `ebpf:"km_cgrptailcall"` + KmCluster *ebpf.MapSpec `ebpf:"km_cluster"` + KmClusterEps *ebpf.MapSpec `ebpf:"km_cluster_eps"` + KmClusterSock *ebpf.MapSpec `ebpf:"km_cluster_sock"` + KmClusterstats *ebpf.MapSpec `ebpf:"km_clusterstats"` + KmEpsData *ebpf.MapSpec `ebpf:"km_eps_data"` + KmListener *ebpf.MapSpec `ebpf:"km_listener"` + KmLogEvent *ebpf.MapSpec `ebpf:"km_log_event"` + KmMaglevOuter *ebpf.MapSpec `ebpf:"km_maglev_outer"` + KmManage *ebpf.MapSpec `ebpf:"km_manage"` + KmRatelimit *ebpf.MapSpec `ebpf:"km_ratelimit"` + KmSockstorage *ebpf.MapSpec `ebpf:"km_sockstorage"` + KmTailcallCtx *ebpf.MapSpec `ebpf:"km_tailcall_ctx"` + KmTmpbuf *ebpf.MapSpec `ebpf:"km_tmpbuf"` + KmeshMap1600 *ebpf.MapSpec `ebpf:"kmesh_map1600"` + KmeshMap192 *ebpf.MapSpec `ebpf:"kmesh_map192"` + KmeshMap296 *ebpf.MapSpec `ebpf:"kmesh_map296"` + KmeshMap64 *ebpf.MapSpec `ebpf:"kmesh_map64"` +} + +// KmeshCgroupSockVariableSpecs contains global variables before they are loaded into the kernel. +// +// It can be passed ebpf.CollectionSpec.Assign. +type KmeshCgroupSockVariableSpecs struct { + BpfLogLevel *ebpf.VariableSpec `ebpf:"bpf_log_level"` +} + +// KmeshCgroupSockObjects contains all objects after they have been loaded into the kernel. +// +// It can be passed to LoadKmeshCgroupSockObjects or ebpf.CollectionSpec.LoadAndAssign. +type KmeshCgroupSockObjects struct { + KmeshCgroupSockPrograms + KmeshCgroupSockMaps + KmeshCgroupSockVariables +} + +func (o *KmeshCgroupSockObjects) Close() error { + return _KmeshCgroupSockClose( + &o.KmeshCgroupSockPrograms, + &o.KmeshCgroupSockMaps, + ) +} + +// KmeshCgroupSockMaps contains all maps after they have been loaded into the kernel. +// +// It can be passed to LoadKmeshCgroupSockObjects or ebpf.CollectionSpec.LoadAndAssign. +type KmeshCgroupSockMaps struct { + KmCgrptailcall *ebpf.Map `ebpf:"km_cgrptailcall"` + KmCluster *ebpf.Map `ebpf:"km_cluster"` + KmClusterEps *ebpf.Map `ebpf:"km_cluster_eps"` + KmClusterSock *ebpf.Map `ebpf:"km_cluster_sock"` + KmClusterstats *ebpf.Map `ebpf:"km_clusterstats"` + KmEpsData *ebpf.Map `ebpf:"km_eps_data"` + KmListener *ebpf.Map `ebpf:"km_listener"` + KmLogEvent *ebpf.Map `ebpf:"km_log_event"` + KmMaglevOuter *ebpf.Map `ebpf:"km_maglev_outer"` + KmManage *ebpf.Map `ebpf:"km_manage"` + KmRatelimit *ebpf.Map `ebpf:"km_ratelimit"` + KmSockstorage *ebpf.Map `ebpf:"km_sockstorage"` + KmTailcallCtx *ebpf.Map `ebpf:"km_tailcall_ctx"` + KmTmpbuf *ebpf.Map `ebpf:"km_tmpbuf"` + KmeshMap1600 *ebpf.Map `ebpf:"kmesh_map1600"` + KmeshMap192 *ebpf.Map `ebpf:"kmesh_map192"` + KmeshMap296 *ebpf.Map `ebpf:"kmesh_map296"` + KmeshMap64 *ebpf.Map `ebpf:"kmesh_map64"` +} + +func (m *KmeshCgroupSockMaps) Close() error { + return _KmeshCgroupSockClose( + m.KmCgrptailcall, + m.KmCluster, + m.KmClusterEps, + m.KmClusterSock, + m.KmClusterstats, + m.KmEpsData, + m.KmListener, + m.KmLogEvent, + m.KmMaglevOuter, + m.KmManage, + m.KmRatelimit, + m.KmSockstorage, + m.KmTailcallCtx, + m.KmTmpbuf, + m.KmeshMap1600, + m.KmeshMap192, + m.KmeshMap296, + m.KmeshMap64, + ) +} + +// KmeshCgroupSockVariables contains all global variables after they have been loaded into the kernel. +// +// It can be passed to LoadKmeshCgroupSockObjects or ebpf.CollectionSpec.LoadAndAssign. +type KmeshCgroupSockVariables struct { + BpfLogLevel *ebpf.Variable `ebpf:"bpf_log_level"` +} + +// KmeshCgroupSockPrograms contains all programs after they have been loaded into the kernel. +// +// It can be passed to LoadKmeshCgroupSockObjects or ebpf.CollectionSpec.LoadAndAssign. +type KmeshCgroupSockPrograms struct { + CgroupConnect4Prog *ebpf.Program `ebpf:"cgroup_connect4_prog"` + ClusterManager *ebpf.Program `ebpf:"cluster_manager"` + FilterChainManager *ebpf.Program `ebpf:"filter_chain_manager"` + FilterManager *ebpf.Program `ebpf:"filter_manager"` +} + +func (p *KmeshCgroupSockPrograms) Close() error { + return _KmeshCgroupSockClose( + p.CgroupConnect4Prog, + p.ClusterManager, + p.FilterChainManager, + p.FilterManager, + ) +} + +func _KmeshCgroupSockClose(closers ...io.Closer) error { + for _, closer := range closers { + if err := closer.Close(); err != nil { + return err + } + } + return nil +} + +// Do not access this directly. +// +//go:embed kmeshcgroupsock_bpfel.o +var _KmeshCgroupSockBytes []byte diff --git a/bpf/kmesh/bpf2go/kernelnative/kmeshcgroupsockcompat_bpfeb.go b/bpf/kmesh/bpf2go/kernelnative/kmeshcgroupsockcompat_bpfeb.go new file mode 100644 index 000000000..6400c64ef --- /dev/null +++ b/bpf/kmesh/bpf2go/kernelnative/kmeshcgroupsockcompat_bpfeb.go @@ -0,0 +1,242 @@ +// Code generated by bpf2go; DO NOT EDIT. +//go:build mips || mips64 || ppc64 || s390x + +package bpf2go + +import ( + "bytes" + _ "embed" + "fmt" + "io" + + "github.com/cilium/ebpf" +) + +type KmeshCgroupSockCompatBuf struct{ Data [40]int8 } + +type KmeshCgroupSockCompatClusterSockData struct{ ClusterId uint32 } + +type KmeshCgroupSockCompatManagerKey struct { + NetnsCookie uint64 + _ [8]byte +} + +type KmeshCgroupSockCompatRatelimitKey struct { + Key struct { + SkSkb struct { + Netns uint64 + Ipv4 uint32 + Port uint32 + Family uint32 + _ [4]byte + } + } +} + +type KmeshCgroupSockCompatRatelimitValue struct { + LastTopup uint64 + Tokens uint64 +} + +type KmeshCgroupSockCompatSockStorageData struct { + ConnectNs uint64 + LastReportNs uint64 + Direction uint8 + ConnectSuccess uint8 + ViaWaypoint bool + HasEncoded bool + HasSetIp bool + _ [3]byte + SkTuple struct { + Ipv4 struct { + Saddr uint32 + Daddr uint32 + Sport uint16 + Dport uint16 + } + _ [24]byte + } + _ [4]byte +} + +// LoadKmeshCgroupSockCompat returns the embedded CollectionSpec for KmeshCgroupSockCompat. +func LoadKmeshCgroupSockCompat() (*ebpf.CollectionSpec, error) { + reader := bytes.NewReader(_KmeshCgroupSockCompatBytes) + spec, err := ebpf.LoadCollectionSpecFromReader(reader) + if err != nil { + return nil, fmt.Errorf("can't load KmeshCgroupSockCompat: %w", err) + } + + return spec, err +} + +// LoadKmeshCgroupSockCompatObjects loads KmeshCgroupSockCompat and converts it into a struct. +// +// The following types are suitable as obj argument: +// +// *KmeshCgroupSockCompatObjects +// *KmeshCgroupSockCompatPrograms +// *KmeshCgroupSockCompatMaps +// +// See ebpf.CollectionSpec.LoadAndAssign documentation for details. +func LoadKmeshCgroupSockCompatObjects(obj interface{}, opts *ebpf.CollectionOptions) error { + spec, err := LoadKmeshCgroupSockCompat() + if err != nil { + return err + } + + return spec.LoadAndAssign(obj, opts) +} + +// KmeshCgroupSockCompatSpecs contains maps and programs before they are loaded into the kernel. +// +// It can be passed ebpf.CollectionSpec.Assign. +type KmeshCgroupSockCompatSpecs struct { + KmeshCgroupSockCompatProgramSpecs + KmeshCgroupSockCompatMapSpecs + KmeshCgroupSockCompatVariableSpecs +} + +// KmeshCgroupSockCompatProgramSpecs contains programs before they are loaded into the kernel. +// +// It can be passed ebpf.CollectionSpec.Assign. +type KmeshCgroupSockCompatProgramSpecs struct { + CgroupConnect4Prog *ebpf.ProgramSpec `ebpf:"cgroup_connect4_prog"` + ClusterManager *ebpf.ProgramSpec `ebpf:"cluster_manager"` + FilterChainManager *ebpf.ProgramSpec `ebpf:"filter_chain_manager"` + FilterManager *ebpf.ProgramSpec `ebpf:"filter_manager"` +} + +// KmeshCgroupSockCompatMapSpecs contains maps before they are loaded into the kernel. +// +// It can be passed ebpf.CollectionSpec.Assign. +type KmeshCgroupSockCompatMapSpecs struct { + KmCgrptailcall *ebpf.MapSpec `ebpf:"km_cgrptailcall"` + KmCluster *ebpf.MapSpec `ebpf:"km_cluster"` + KmClusterEps *ebpf.MapSpec `ebpf:"km_cluster_eps"` + KmClusterSock *ebpf.MapSpec `ebpf:"km_cluster_sock"` + KmClusterstats *ebpf.MapSpec `ebpf:"km_clusterstats"` + KmEpsData *ebpf.MapSpec `ebpf:"km_eps_data"` + KmListener *ebpf.MapSpec `ebpf:"km_listener"` + KmLogEvent *ebpf.MapSpec `ebpf:"km_log_event"` + KmMaglevOuter *ebpf.MapSpec `ebpf:"km_maglev_outer"` + KmManage *ebpf.MapSpec `ebpf:"km_manage"` + KmRatelimit *ebpf.MapSpec `ebpf:"km_ratelimit"` + KmSockstorage *ebpf.MapSpec `ebpf:"km_sockstorage"` + KmTailcallCtx *ebpf.MapSpec `ebpf:"km_tailcall_ctx"` + KmTmpbuf *ebpf.MapSpec `ebpf:"km_tmpbuf"` + KmeshMap1600 *ebpf.MapSpec `ebpf:"kmesh_map1600"` + KmeshMap192 *ebpf.MapSpec `ebpf:"kmesh_map192"` + KmeshMap296 *ebpf.MapSpec `ebpf:"kmesh_map296"` + KmeshMap64 *ebpf.MapSpec `ebpf:"kmesh_map64"` +} + +// KmeshCgroupSockCompatVariableSpecs contains global variables before they are loaded into the kernel. +// +// It can be passed ebpf.CollectionSpec.Assign. +type KmeshCgroupSockCompatVariableSpecs struct { + BpfLogLevel *ebpf.VariableSpec `ebpf:"bpf_log_level"` +} + +// KmeshCgroupSockCompatObjects contains all objects after they have been loaded into the kernel. +// +// It can be passed to LoadKmeshCgroupSockCompatObjects or ebpf.CollectionSpec.LoadAndAssign. +type KmeshCgroupSockCompatObjects struct { + KmeshCgroupSockCompatPrograms + KmeshCgroupSockCompatMaps + KmeshCgroupSockCompatVariables +} + +func (o *KmeshCgroupSockCompatObjects) Close() error { + return _KmeshCgroupSockCompatClose( + &o.KmeshCgroupSockCompatPrograms, + &o.KmeshCgroupSockCompatMaps, + ) +} + +// KmeshCgroupSockCompatMaps contains all maps after they have been loaded into the kernel. +// +// It can be passed to LoadKmeshCgroupSockCompatObjects or ebpf.CollectionSpec.LoadAndAssign. +type KmeshCgroupSockCompatMaps struct { + KmCgrptailcall *ebpf.Map `ebpf:"km_cgrptailcall"` + KmCluster *ebpf.Map `ebpf:"km_cluster"` + KmClusterEps *ebpf.Map `ebpf:"km_cluster_eps"` + KmClusterSock *ebpf.Map `ebpf:"km_cluster_sock"` + KmClusterstats *ebpf.Map `ebpf:"km_clusterstats"` + KmEpsData *ebpf.Map `ebpf:"km_eps_data"` + KmListener *ebpf.Map `ebpf:"km_listener"` + KmLogEvent *ebpf.Map `ebpf:"km_log_event"` + KmMaglevOuter *ebpf.Map `ebpf:"km_maglev_outer"` + KmManage *ebpf.Map `ebpf:"km_manage"` + KmRatelimit *ebpf.Map `ebpf:"km_ratelimit"` + KmSockstorage *ebpf.Map `ebpf:"km_sockstorage"` + KmTailcallCtx *ebpf.Map `ebpf:"km_tailcall_ctx"` + KmTmpbuf *ebpf.Map `ebpf:"km_tmpbuf"` + KmeshMap1600 *ebpf.Map `ebpf:"kmesh_map1600"` + KmeshMap192 *ebpf.Map `ebpf:"kmesh_map192"` + KmeshMap296 *ebpf.Map `ebpf:"kmesh_map296"` + KmeshMap64 *ebpf.Map `ebpf:"kmesh_map64"` +} + +func (m *KmeshCgroupSockCompatMaps) Close() error { + return _KmeshCgroupSockCompatClose( + m.KmCgrptailcall, + m.KmCluster, + m.KmClusterEps, + m.KmClusterSock, + m.KmClusterstats, + m.KmEpsData, + m.KmListener, + m.KmLogEvent, + m.KmMaglevOuter, + m.KmManage, + m.KmRatelimit, + m.KmSockstorage, + m.KmTailcallCtx, + m.KmTmpbuf, + m.KmeshMap1600, + m.KmeshMap192, + m.KmeshMap296, + m.KmeshMap64, + ) +} + +// KmeshCgroupSockCompatVariables contains all global variables after they have been loaded into the kernel. +// +// It can be passed to LoadKmeshCgroupSockCompatObjects or ebpf.CollectionSpec.LoadAndAssign. +type KmeshCgroupSockCompatVariables struct { + BpfLogLevel *ebpf.Variable `ebpf:"bpf_log_level"` +} + +// KmeshCgroupSockCompatPrograms contains all programs after they have been loaded into the kernel. +// +// It can be passed to LoadKmeshCgroupSockCompatObjects or ebpf.CollectionSpec.LoadAndAssign. +type KmeshCgroupSockCompatPrograms struct { + CgroupConnect4Prog *ebpf.Program `ebpf:"cgroup_connect4_prog"` + ClusterManager *ebpf.Program `ebpf:"cluster_manager"` + FilterChainManager *ebpf.Program `ebpf:"filter_chain_manager"` + FilterManager *ebpf.Program `ebpf:"filter_manager"` +} + +func (p *KmeshCgroupSockCompatPrograms) Close() error { + return _KmeshCgroupSockCompatClose( + p.CgroupConnect4Prog, + p.ClusterManager, + p.FilterChainManager, + p.FilterManager, + ) +} + +func _KmeshCgroupSockCompatClose(closers ...io.Closer) error { + for _, closer := range closers { + if err := closer.Close(); err != nil { + return err + } + } + return nil +} + +// Do not access this directly. +// +//go:embed kmeshcgroupsockcompat_bpfeb.o +var _KmeshCgroupSockCompatBytes []byte diff --git a/bpf/kmesh/bpf2go/kernelnative/kmeshcgroupsockcompat_bpfel.go b/bpf/kmesh/bpf2go/kernelnative/kmeshcgroupsockcompat_bpfel.go new file mode 100644 index 000000000..2d40c5040 --- /dev/null +++ b/bpf/kmesh/bpf2go/kernelnative/kmeshcgroupsockcompat_bpfel.go @@ -0,0 +1,242 @@ +// Code generated by bpf2go; DO NOT EDIT. +//go:build 386 || amd64 || arm || arm64 || loong64 || mips64le || mipsle || ppc64le || riscv64 + +package bpf2go + +import ( + "bytes" + _ "embed" + "fmt" + "io" + + "github.com/cilium/ebpf" +) + +type KmeshCgroupSockCompatBuf struct{ Data [40]int8 } + +type KmeshCgroupSockCompatClusterSockData struct{ ClusterId uint32 } + +type KmeshCgroupSockCompatManagerKey struct { + NetnsCookie uint64 + _ [8]byte +} + +type KmeshCgroupSockCompatRatelimitKey struct { + Key struct { + SkSkb struct { + Netns uint64 + Ipv4 uint32 + Port uint32 + Family uint32 + _ [4]byte + } + } +} + +type KmeshCgroupSockCompatRatelimitValue struct { + LastTopup uint64 + Tokens uint64 +} + +type KmeshCgroupSockCompatSockStorageData struct { + ConnectNs uint64 + LastReportNs uint64 + Direction uint8 + ConnectSuccess uint8 + ViaWaypoint bool + HasEncoded bool + HasSetIp bool + _ [3]byte + SkTuple struct { + Ipv4 struct { + Saddr uint32 + Daddr uint32 + Sport uint16 + Dport uint16 + } + _ [24]byte + } + _ [4]byte +} + +// LoadKmeshCgroupSockCompat returns the embedded CollectionSpec for KmeshCgroupSockCompat. +func LoadKmeshCgroupSockCompat() (*ebpf.CollectionSpec, error) { + reader := bytes.NewReader(_KmeshCgroupSockCompatBytes) + spec, err := ebpf.LoadCollectionSpecFromReader(reader) + if err != nil { + return nil, fmt.Errorf("can't load KmeshCgroupSockCompat: %w", err) + } + + return spec, err +} + +// LoadKmeshCgroupSockCompatObjects loads KmeshCgroupSockCompat and converts it into a struct. +// +// The following types are suitable as obj argument: +// +// *KmeshCgroupSockCompatObjects +// *KmeshCgroupSockCompatPrograms +// *KmeshCgroupSockCompatMaps +// +// See ebpf.CollectionSpec.LoadAndAssign documentation for details. +func LoadKmeshCgroupSockCompatObjects(obj interface{}, opts *ebpf.CollectionOptions) error { + spec, err := LoadKmeshCgroupSockCompat() + if err != nil { + return err + } + + return spec.LoadAndAssign(obj, opts) +} + +// KmeshCgroupSockCompatSpecs contains maps and programs before they are loaded into the kernel. +// +// It can be passed ebpf.CollectionSpec.Assign. +type KmeshCgroupSockCompatSpecs struct { + KmeshCgroupSockCompatProgramSpecs + KmeshCgroupSockCompatMapSpecs + KmeshCgroupSockCompatVariableSpecs +} + +// KmeshCgroupSockCompatProgramSpecs contains programs before they are loaded into the kernel. +// +// It can be passed ebpf.CollectionSpec.Assign. +type KmeshCgroupSockCompatProgramSpecs struct { + CgroupConnect4Prog *ebpf.ProgramSpec `ebpf:"cgroup_connect4_prog"` + ClusterManager *ebpf.ProgramSpec `ebpf:"cluster_manager"` + FilterChainManager *ebpf.ProgramSpec `ebpf:"filter_chain_manager"` + FilterManager *ebpf.ProgramSpec `ebpf:"filter_manager"` +} + +// KmeshCgroupSockCompatMapSpecs contains maps before they are loaded into the kernel. +// +// It can be passed ebpf.CollectionSpec.Assign. +type KmeshCgroupSockCompatMapSpecs struct { + KmCgrptailcall *ebpf.MapSpec `ebpf:"km_cgrptailcall"` + KmCluster *ebpf.MapSpec `ebpf:"km_cluster"` + KmClusterEps *ebpf.MapSpec `ebpf:"km_cluster_eps"` + KmClusterSock *ebpf.MapSpec `ebpf:"km_cluster_sock"` + KmClusterstats *ebpf.MapSpec `ebpf:"km_clusterstats"` + KmEpsData *ebpf.MapSpec `ebpf:"km_eps_data"` + KmListener *ebpf.MapSpec `ebpf:"km_listener"` + KmLogEvent *ebpf.MapSpec `ebpf:"km_log_event"` + KmMaglevOuter *ebpf.MapSpec `ebpf:"km_maglev_outer"` + KmManage *ebpf.MapSpec `ebpf:"km_manage"` + KmRatelimit *ebpf.MapSpec `ebpf:"km_ratelimit"` + KmSockstorage *ebpf.MapSpec `ebpf:"km_sockstorage"` + KmTailcallCtx *ebpf.MapSpec `ebpf:"km_tailcall_ctx"` + KmTmpbuf *ebpf.MapSpec `ebpf:"km_tmpbuf"` + KmeshMap1600 *ebpf.MapSpec `ebpf:"kmesh_map1600"` + KmeshMap192 *ebpf.MapSpec `ebpf:"kmesh_map192"` + KmeshMap296 *ebpf.MapSpec `ebpf:"kmesh_map296"` + KmeshMap64 *ebpf.MapSpec `ebpf:"kmesh_map64"` +} + +// KmeshCgroupSockCompatVariableSpecs contains global variables before they are loaded into the kernel. +// +// It can be passed ebpf.CollectionSpec.Assign. +type KmeshCgroupSockCompatVariableSpecs struct { + BpfLogLevel *ebpf.VariableSpec `ebpf:"bpf_log_level"` +} + +// KmeshCgroupSockCompatObjects contains all objects after they have been loaded into the kernel. +// +// It can be passed to LoadKmeshCgroupSockCompatObjects or ebpf.CollectionSpec.LoadAndAssign. +type KmeshCgroupSockCompatObjects struct { + KmeshCgroupSockCompatPrograms + KmeshCgroupSockCompatMaps + KmeshCgroupSockCompatVariables +} + +func (o *KmeshCgroupSockCompatObjects) Close() error { + return _KmeshCgroupSockCompatClose( + &o.KmeshCgroupSockCompatPrograms, + &o.KmeshCgroupSockCompatMaps, + ) +} + +// KmeshCgroupSockCompatMaps contains all maps after they have been loaded into the kernel. +// +// It can be passed to LoadKmeshCgroupSockCompatObjects or ebpf.CollectionSpec.LoadAndAssign. +type KmeshCgroupSockCompatMaps struct { + KmCgrptailcall *ebpf.Map `ebpf:"km_cgrptailcall"` + KmCluster *ebpf.Map `ebpf:"km_cluster"` + KmClusterEps *ebpf.Map `ebpf:"km_cluster_eps"` + KmClusterSock *ebpf.Map `ebpf:"km_cluster_sock"` + KmClusterstats *ebpf.Map `ebpf:"km_clusterstats"` + KmEpsData *ebpf.Map `ebpf:"km_eps_data"` + KmListener *ebpf.Map `ebpf:"km_listener"` + KmLogEvent *ebpf.Map `ebpf:"km_log_event"` + KmMaglevOuter *ebpf.Map `ebpf:"km_maglev_outer"` + KmManage *ebpf.Map `ebpf:"km_manage"` + KmRatelimit *ebpf.Map `ebpf:"km_ratelimit"` + KmSockstorage *ebpf.Map `ebpf:"km_sockstorage"` + KmTailcallCtx *ebpf.Map `ebpf:"km_tailcall_ctx"` + KmTmpbuf *ebpf.Map `ebpf:"km_tmpbuf"` + KmeshMap1600 *ebpf.Map `ebpf:"kmesh_map1600"` + KmeshMap192 *ebpf.Map `ebpf:"kmesh_map192"` + KmeshMap296 *ebpf.Map `ebpf:"kmesh_map296"` + KmeshMap64 *ebpf.Map `ebpf:"kmesh_map64"` +} + +func (m *KmeshCgroupSockCompatMaps) Close() error { + return _KmeshCgroupSockCompatClose( + m.KmCgrptailcall, + m.KmCluster, + m.KmClusterEps, + m.KmClusterSock, + m.KmClusterstats, + m.KmEpsData, + m.KmListener, + m.KmLogEvent, + m.KmMaglevOuter, + m.KmManage, + m.KmRatelimit, + m.KmSockstorage, + m.KmTailcallCtx, + m.KmTmpbuf, + m.KmeshMap1600, + m.KmeshMap192, + m.KmeshMap296, + m.KmeshMap64, + ) +} + +// KmeshCgroupSockCompatVariables contains all global variables after they have been loaded into the kernel. +// +// It can be passed to LoadKmeshCgroupSockCompatObjects or ebpf.CollectionSpec.LoadAndAssign. +type KmeshCgroupSockCompatVariables struct { + BpfLogLevel *ebpf.Variable `ebpf:"bpf_log_level"` +} + +// KmeshCgroupSockCompatPrograms contains all programs after they have been loaded into the kernel. +// +// It can be passed to LoadKmeshCgroupSockCompatObjects or ebpf.CollectionSpec.LoadAndAssign. +type KmeshCgroupSockCompatPrograms struct { + CgroupConnect4Prog *ebpf.Program `ebpf:"cgroup_connect4_prog"` + ClusterManager *ebpf.Program `ebpf:"cluster_manager"` + FilterChainManager *ebpf.Program `ebpf:"filter_chain_manager"` + FilterManager *ebpf.Program `ebpf:"filter_manager"` +} + +func (p *KmeshCgroupSockCompatPrograms) Close() error { + return _KmeshCgroupSockCompatClose( + p.CgroupConnect4Prog, + p.ClusterManager, + p.FilterChainManager, + p.FilterManager, + ) +} + +func _KmeshCgroupSockCompatClose(closers ...io.Closer) error { + for _, closer := range closers { + if err := closer.Close(); err != nil { + return err + } + } + return nil +} + +// Do not access this directly. +// +//go:embed kmeshcgroupsockcompat_bpfel.o +var _KmeshCgroupSockCompatBytes []byte diff --git a/bpf/kmesh/bpf2go/kernelnative/kmeshsockops_bpfeb.go b/bpf/kmesh/bpf2go/kernelnative/kmeshsockops_bpfeb.go new file mode 100644 index 000000000..84bbb6cc8 --- /dev/null +++ b/bpf/kmesh/bpf2go/kernelnative/kmeshsockops_bpfeb.go @@ -0,0 +1,192 @@ +// Code generated by bpf2go; DO NOT EDIT. +//go:build mips || mips64 || ppc64 || s390x + +package bpf2go + +import ( + "bytes" + _ "embed" + "fmt" + "io" + + "github.com/cilium/ebpf" +) + +type KmeshSockopsBuf struct{ Data [40]int8 } + +type KmeshSockopsClusterSockData struct{ ClusterId uint32 } + +type KmeshSockopsManagerKey struct { + NetnsCookie uint64 + _ [8]byte +} + +type KmeshSockopsSockStorageData struct { + ConnectNs uint64 + LastReportNs uint64 + Direction uint8 + ConnectSuccess uint8 + ViaWaypoint bool + HasEncoded bool + HasSetIp bool + _ [3]byte + SkTuple struct { + Ipv4 struct { + Saddr uint32 + Daddr uint32 + Sport uint16 + Dport uint16 + } + _ [24]byte + } + _ [4]byte +} + +// LoadKmeshSockops returns the embedded CollectionSpec for KmeshSockops. +func LoadKmeshSockops() (*ebpf.CollectionSpec, error) { + reader := bytes.NewReader(_KmeshSockopsBytes) + spec, err := ebpf.LoadCollectionSpecFromReader(reader) + if err != nil { + return nil, fmt.Errorf("can't load KmeshSockops: %w", err) + } + + return spec, err +} + +// LoadKmeshSockopsObjects loads KmeshSockops and converts it into a struct. +// +// The following types are suitable as obj argument: +// +// *KmeshSockopsObjects +// *KmeshSockopsPrograms +// *KmeshSockopsMaps +// +// See ebpf.CollectionSpec.LoadAndAssign documentation for details. +func LoadKmeshSockopsObjects(obj interface{}, opts *ebpf.CollectionOptions) error { + spec, err := LoadKmeshSockops() + if err != nil { + return err + } + + return spec.LoadAndAssign(obj, opts) +} + +// KmeshSockopsSpecs contains maps and programs before they are loaded into the kernel. +// +// It can be passed ebpf.CollectionSpec.Assign. +type KmeshSockopsSpecs struct { + KmeshSockopsProgramSpecs + KmeshSockopsMapSpecs + KmeshSockopsVariableSpecs +} + +// KmeshSockopsProgramSpecs contains programs before they are loaded into the kernel. +// +// It can be passed ebpf.CollectionSpec.Assign. +type KmeshSockopsProgramSpecs struct { + SockopsProg *ebpf.ProgramSpec `ebpf:"sockops_prog"` +} + +// KmeshSockopsMapSpecs contains maps before they are loaded into the kernel. +// +// It can be passed ebpf.CollectionSpec.Assign. +type KmeshSockopsMapSpecs struct { + KmClusterSock *ebpf.MapSpec `ebpf:"km_cluster_sock"` + KmClusterstats *ebpf.MapSpec `ebpf:"km_clusterstats"` + KmLogEvent *ebpf.MapSpec `ebpf:"km_log_event"` + KmManage *ebpf.MapSpec `ebpf:"km_manage"` + KmSockstorage *ebpf.MapSpec `ebpf:"km_sockstorage"` + KmTmpbuf *ebpf.MapSpec `ebpf:"km_tmpbuf"` + KmeshMap1600 *ebpf.MapSpec `ebpf:"kmesh_map1600"` + KmeshMap192 *ebpf.MapSpec `ebpf:"kmesh_map192"` + KmeshMap296 *ebpf.MapSpec `ebpf:"kmesh_map296"` + KmeshMap64 *ebpf.MapSpec `ebpf:"kmesh_map64"` +} + +// KmeshSockopsVariableSpecs contains global variables before they are loaded into the kernel. +// +// It can be passed ebpf.CollectionSpec.Assign. +type KmeshSockopsVariableSpecs struct { + BpfLogLevel *ebpf.VariableSpec `ebpf:"bpf_log_level"` +} + +// KmeshSockopsObjects contains all objects after they have been loaded into the kernel. +// +// It can be passed to LoadKmeshSockopsObjects or ebpf.CollectionSpec.LoadAndAssign. +type KmeshSockopsObjects struct { + KmeshSockopsPrograms + KmeshSockopsMaps + KmeshSockopsVariables +} + +func (o *KmeshSockopsObjects) Close() error { + return _KmeshSockopsClose( + &o.KmeshSockopsPrograms, + &o.KmeshSockopsMaps, + ) +} + +// KmeshSockopsMaps contains all maps after they have been loaded into the kernel. +// +// It can be passed to LoadKmeshSockopsObjects or ebpf.CollectionSpec.LoadAndAssign. +type KmeshSockopsMaps struct { + KmClusterSock *ebpf.Map `ebpf:"km_cluster_sock"` + KmClusterstats *ebpf.Map `ebpf:"km_clusterstats"` + KmLogEvent *ebpf.Map `ebpf:"km_log_event"` + KmManage *ebpf.Map `ebpf:"km_manage"` + KmSockstorage *ebpf.Map `ebpf:"km_sockstorage"` + KmTmpbuf *ebpf.Map `ebpf:"km_tmpbuf"` + KmeshMap1600 *ebpf.Map `ebpf:"kmesh_map1600"` + KmeshMap192 *ebpf.Map `ebpf:"kmesh_map192"` + KmeshMap296 *ebpf.Map `ebpf:"kmesh_map296"` + KmeshMap64 *ebpf.Map `ebpf:"kmesh_map64"` +} + +func (m *KmeshSockopsMaps) Close() error { + return _KmeshSockopsClose( + m.KmClusterSock, + m.KmClusterstats, + m.KmLogEvent, + m.KmManage, + m.KmSockstorage, + m.KmTmpbuf, + m.KmeshMap1600, + m.KmeshMap192, + m.KmeshMap296, + m.KmeshMap64, + ) +} + +// KmeshSockopsVariables contains all global variables after they have been loaded into the kernel. +// +// It can be passed to LoadKmeshSockopsObjects or ebpf.CollectionSpec.LoadAndAssign. +type KmeshSockopsVariables struct { + BpfLogLevel *ebpf.Variable `ebpf:"bpf_log_level"` +} + +// KmeshSockopsPrograms contains all programs after they have been loaded into the kernel. +// +// It can be passed to LoadKmeshSockopsObjects or ebpf.CollectionSpec.LoadAndAssign. +type KmeshSockopsPrograms struct { + SockopsProg *ebpf.Program `ebpf:"sockops_prog"` +} + +func (p *KmeshSockopsPrograms) Close() error { + return _KmeshSockopsClose( + p.SockopsProg, + ) +} + +func _KmeshSockopsClose(closers ...io.Closer) error { + for _, closer := range closers { + if err := closer.Close(); err != nil { + return err + } + } + return nil +} + +// Do not access this directly. +// +//go:embed kmeshsockops_bpfeb.o +var _KmeshSockopsBytes []byte diff --git a/bpf/kmesh/bpf2go/kernelnative/kmeshsockops_bpfel.go b/bpf/kmesh/bpf2go/kernelnative/kmeshsockops_bpfel.go new file mode 100644 index 000000000..8db351f13 --- /dev/null +++ b/bpf/kmesh/bpf2go/kernelnative/kmeshsockops_bpfel.go @@ -0,0 +1,192 @@ +// Code generated by bpf2go; DO NOT EDIT. +//go:build 386 || amd64 || arm || arm64 || loong64 || mips64le || mipsle || ppc64le || riscv64 + +package bpf2go + +import ( + "bytes" + _ "embed" + "fmt" + "io" + + "github.com/cilium/ebpf" +) + +type KmeshSockopsBuf struct{ Data [40]int8 } + +type KmeshSockopsClusterSockData struct{ ClusterId uint32 } + +type KmeshSockopsManagerKey struct { + NetnsCookie uint64 + _ [8]byte +} + +type KmeshSockopsSockStorageData struct { + ConnectNs uint64 + LastReportNs uint64 + Direction uint8 + ConnectSuccess uint8 + ViaWaypoint bool + HasEncoded bool + HasSetIp bool + _ [3]byte + SkTuple struct { + Ipv4 struct { + Saddr uint32 + Daddr uint32 + Sport uint16 + Dport uint16 + } + _ [24]byte + } + _ [4]byte +} + +// LoadKmeshSockops returns the embedded CollectionSpec for KmeshSockops. +func LoadKmeshSockops() (*ebpf.CollectionSpec, error) { + reader := bytes.NewReader(_KmeshSockopsBytes) + spec, err := ebpf.LoadCollectionSpecFromReader(reader) + if err != nil { + return nil, fmt.Errorf("can't load KmeshSockops: %w", err) + } + + return spec, err +} + +// LoadKmeshSockopsObjects loads KmeshSockops and converts it into a struct. +// +// The following types are suitable as obj argument: +// +// *KmeshSockopsObjects +// *KmeshSockopsPrograms +// *KmeshSockopsMaps +// +// See ebpf.CollectionSpec.LoadAndAssign documentation for details. +func LoadKmeshSockopsObjects(obj interface{}, opts *ebpf.CollectionOptions) error { + spec, err := LoadKmeshSockops() + if err != nil { + return err + } + + return spec.LoadAndAssign(obj, opts) +} + +// KmeshSockopsSpecs contains maps and programs before they are loaded into the kernel. +// +// It can be passed ebpf.CollectionSpec.Assign. +type KmeshSockopsSpecs struct { + KmeshSockopsProgramSpecs + KmeshSockopsMapSpecs + KmeshSockopsVariableSpecs +} + +// KmeshSockopsProgramSpecs contains programs before they are loaded into the kernel. +// +// It can be passed ebpf.CollectionSpec.Assign. +type KmeshSockopsProgramSpecs struct { + SockopsProg *ebpf.ProgramSpec `ebpf:"sockops_prog"` +} + +// KmeshSockopsMapSpecs contains maps before they are loaded into the kernel. +// +// It can be passed ebpf.CollectionSpec.Assign. +type KmeshSockopsMapSpecs struct { + KmClusterSock *ebpf.MapSpec `ebpf:"km_cluster_sock"` + KmClusterstats *ebpf.MapSpec `ebpf:"km_clusterstats"` + KmLogEvent *ebpf.MapSpec `ebpf:"km_log_event"` + KmManage *ebpf.MapSpec `ebpf:"km_manage"` + KmSockstorage *ebpf.MapSpec `ebpf:"km_sockstorage"` + KmTmpbuf *ebpf.MapSpec `ebpf:"km_tmpbuf"` + KmeshMap1600 *ebpf.MapSpec `ebpf:"kmesh_map1600"` + KmeshMap192 *ebpf.MapSpec `ebpf:"kmesh_map192"` + KmeshMap296 *ebpf.MapSpec `ebpf:"kmesh_map296"` + KmeshMap64 *ebpf.MapSpec `ebpf:"kmesh_map64"` +} + +// KmeshSockopsVariableSpecs contains global variables before they are loaded into the kernel. +// +// It can be passed ebpf.CollectionSpec.Assign. +type KmeshSockopsVariableSpecs struct { + BpfLogLevel *ebpf.VariableSpec `ebpf:"bpf_log_level"` +} + +// KmeshSockopsObjects contains all objects after they have been loaded into the kernel. +// +// It can be passed to LoadKmeshSockopsObjects or ebpf.CollectionSpec.LoadAndAssign. +type KmeshSockopsObjects struct { + KmeshSockopsPrograms + KmeshSockopsMaps + KmeshSockopsVariables +} + +func (o *KmeshSockopsObjects) Close() error { + return _KmeshSockopsClose( + &o.KmeshSockopsPrograms, + &o.KmeshSockopsMaps, + ) +} + +// KmeshSockopsMaps contains all maps after they have been loaded into the kernel. +// +// It can be passed to LoadKmeshSockopsObjects or ebpf.CollectionSpec.LoadAndAssign. +type KmeshSockopsMaps struct { + KmClusterSock *ebpf.Map `ebpf:"km_cluster_sock"` + KmClusterstats *ebpf.Map `ebpf:"km_clusterstats"` + KmLogEvent *ebpf.Map `ebpf:"km_log_event"` + KmManage *ebpf.Map `ebpf:"km_manage"` + KmSockstorage *ebpf.Map `ebpf:"km_sockstorage"` + KmTmpbuf *ebpf.Map `ebpf:"km_tmpbuf"` + KmeshMap1600 *ebpf.Map `ebpf:"kmesh_map1600"` + KmeshMap192 *ebpf.Map `ebpf:"kmesh_map192"` + KmeshMap296 *ebpf.Map `ebpf:"kmesh_map296"` + KmeshMap64 *ebpf.Map `ebpf:"kmesh_map64"` +} + +func (m *KmeshSockopsMaps) Close() error { + return _KmeshSockopsClose( + m.KmClusterSock, + m.KmClusterstats, + m.KmLogEvent, + m.KmManage, + m.KmSockstorage, + m.KmTmpbuf, + m.KmeshMap1600, + m.KmeshMap192, + m.KmeshMap296, + m.KmeshMap64, + ) +} + +// KmeshSockopsVariables contains all global variables after they have been loaded into the kernel. +// +// It can be passed to LoadKmeshSockopsObjects or ebpf.CollectionSpec.LoadAndAssign. +type KmeshSockopsVariables struct { + BpfLogLevel *ebpf.Variable `ebpf:"bpf_log_level"` +} + +// KmeshSockopsPrograms contains all programs after they have been loaded into the kernel. +// +// It can be passed to LoadKmeshSockopsObjects or ebpf.CollectionSpec.LoadAndAssign. +type KmeshSockopsPrograms struct { + SockopsProg *ebpf.Program `ebpf:"sockops_prog"` +} + +func (p *KmeshSockopsPrograms) Close() error { + return _KmeshSockopsClose( + p.SockopsProg, + ) +} + +func _KmeshSockopsClose(closers ...io.Closer) error { + for _, closer := range closers { + if err := closer.Close(); err != nil { + return err + } + } + return nil +} + +// Do not access this directly. +// +//go:embed kmeshsockops_bpfel.o +var _KmeshSockopsBytes []byte diff --git a/bpf/kmesh/bpf2go/kernelnative/kmeshsockopscompat_bpfeb.go b/bpf/kmesh/bpf2go/kernelnative/kmeshsockopscompat_bpfeb.go new file mode 100644 index 000000000..066bab11e --- /dev/null +++ b/bpf/kmesh/bpf2go/kernelnative/kmeshsockopscompat_bpfeb.go @@ -0,0 +1,192 @@ +// Code generated by bpf2go; DO NOT EDIT. +//go:build mips || mips64 || ppc64 || s390x + +package bpf2go + +import ( + "bytes" + _ "embed" + "fmt" + "io" + + "github.com/cilium/ebpf" +) + +type KmeshSockopsCompatBuf struct{ Data [40]int8 } + +type KmeshSockopsCompatClusterSockData struct{ ClusterId uint32 } + +type KmeshSockopsCompatManagerKey struct { + NetnsCookie uint64 + _ [8]byte +} + +type KmeshSockopsCompatSockStorageData struct { + ConnectNs uint64 + LastReportNs uint64 + Direction uint8 + ConnectSuccess uint8 + ViaWaypoint bool + HasEncoded bool + HasSetIp bool + _ [3]byte + SkTuple struct { + Ipv4 struct { + Saddr uint32 + Daddr uint32 + Sport uint16 + Dport uint16 + } + _ [24]byte + } + _ [4]byte +} + +// LoadKmeshSockopsCompat returns the embedded CollectionSpec for KmeshSockopsCompat. +func LoadKmeshSockopsCompat() (*ebpf.CollectionSpec, error) { + reader := bytes.NewReader(_KmeshSockopsCompatBytes) + spec, err := ebpf.LoadCollectionSpecFromReader(reader) + if err != nil { + return nil, fmt.Errorf("can't load KmeshSockopsCompat: %w", err) + } + + return spec, err +} + +// LoadKmeshSockopsCompatObjects loads KmeshSockopsCompat and converts it into a struct. +// +// The following types are suitable as obj argument: +// +// *KmeshSockopsCompatObjects +// *KmeshSockopsCompatPrograms +// *KmeshSockopsCompatMaps +// +// See ebpf.CollectionSpec.LoadAndAssign documentation for details. +func LoadKmeshSockopsCompatObjects(obj interface{}, opts *ebpf.CollectionOptions) error { + spec, err := LoadKmeshSockopsCompat() + if err != nil { + return err + } + + return spec.LoadAndAssign(obj, opts) +} + +// KmeshSockopsCompatSpecs contains maps and programs before they are loaded into the kernel. +// +// It can be passed ebpf.CollectionSpec.Assign. +type KmeshSockopsCompatSpecs struct { + KmeshSockopsCompatProgramSpecs + KmeshSockopsCompatMapSpecs + KmeshSockopsCompatVariableSpecs +} + +// KmeshSockopsCompatProgramSpecs contains programs before they are loaded into the kernel. +// +// It can be passed ebpf.CollectionSpec.Assign. +type KmeshSockopsCompatProgramSpecs struct { + SockopsProg *ebpf.ProgramSpec `ebpf:"sockops_prog"` +} + +// KmeshSockopsCompatMapSpecs contains maps before they are loaded into the kernel. +// +// It can be passed ebpf.CollectionSpec.Assign. +type KmeshSockopsCompatMapSpecs struct { + KmClusterSock *ebpf.MapSpec `ebpf:"km_cluster_sock"` + KmClusterstats *ebpf.MapSpec `ebpf:"km_clusterstats"` + KmLogEvent *ebpf.MapSpec `ebpf:"km_log_event"` + KmManage *ebpf.MapSpec `ebpf:"km_manage"` + KmSockstorage *ebpf.MapSpec `ebpf:"km_sockstorage"` + KmTmpbuf *ebpf.MapSpec `ebpf:"km_tmpbuf"` + KmeshMap1600 *ebpf.MapSpec `ebpf:"kmesh_map1600"` + KmeshMap192 *ebpf.MapSpec `ebpf:"kmesh_map192"` + KmeshMap296 *ebpf.MapSpec `ebpf:"kmesh_map296"` + KmeshMap64 *ebpf.MapSpec `ebpf:"kmesh_map64"` +} + +// KmeshSockopsCompatVariableSpecs contains global variables before they are loaded into the kernel. +// +// It can be passed ebpf.CollectionSpec.Assign. +type KmeshSockopsCompatVariableSpecs struct { + BpfLogLevel *ebpf.VariableSpec `ebpf:"bpf_log_level"` +} + +// KmeshSockopsCompatObjects contains all objects after they have been loaded into the kernel. +// +// It can be passed to LoadKmeshSockopsCompatObjects or ebpf.CollectionSpec.LoadAndAssign. +type KmeshSockopsCompatObjects struct { + KmeshSockopsCompatPrograms + KmeshSockopsCompatMaps + KmeshSockopsCompatVariables +} + +func (o *KmeshSockopsCompatObjects) Close() error { + return _KmeshSockopsCompatClose( + &o.KmeshSockopsCompatPrograms, + &o.KmeshSockopsCompatMaps, + ) +} + +// KmeshSockopsCompatMaps contains all maps after they have been loaded into the kernel. +// +// It can be passed to LoadKmeshSockopsCompatObjects or ebpf.CollectionSpec.LoadAndAssign. +type KmeshSockopsCompatMaps struct { + KmClusterSock *ebpf.Map `ebpf:"km_cluster_sock"` + KmClusterstats *ebpf.Map `ebpf:"km_clusterstats"` + KmLogEvent *ebpf.Map `ebpf:"km_log_event"` + KmManage *ebpf.Map `ebpf:"km_manage"` + KmSockstorage *ebpf.Map `ebpf:"km_sockstorage"` + KmTmpbuf *ebpf.Map `ebpf:"km_tmpbuf"` + KmeshMap1600 *ebpf.Map `ebpf:"kmesh_map1600"` + KmeshMap192 *ebpf.Map `ebpf:"kmesh_map192"` + KmeshMap296 *ebpf.Map `ebpf:"kmesh_map296"` + KmeshMap64 *ebpf.Map `ebpf:"kmesh_map64"` +} + +func (m *KmeshSockopsCompatMaps) Close() error { + return _KmeshSockopsCompatClose( + m.KmClusterSock, + m.KmClusterstats, + m.KmLogEvent, + m.KmManage, + m.KmSockstorage, + m.KmTmpbuf, + m.KmeshMap1600, + m.KmeshMap192, + m.KmeshMap296, + m.KmeshMap64, + ) +} + +// KmeshSockopsCompatVariables contains all global variables after they have been loaded into the kernel. +// +// It can be passed to LoadKmeshSockopsCompatObjects or ebpf.CollectionSpec.LoadAndAssign. +type KmeshSockopsCompatVariables struct { + BpfLogLevel *ebpf.Variable `ebpf:"bpf_log_level"` +} + +// KmeshSockopsCompatPrograms contains all programs after they have been loaded into the kernel. +// +// It can be passed to LoadKmeshSockopsCompatObjects or ebpf.CollectionSpec.LoadAndAssign. +type KmeshSockopsCompatPrograms struct { + SockopsProg *ebpf.Program `ebpf:"sockops_prog"` +} + +func (p *KmeshSockopsCompatPrograms) Close() error { + return _KmeshSockopsCompatClose( + p.SockopsProg, + ) +} + +func _KmeshSockopsCompatClose(closers ...io.Closer) error { + for _, closer := range closers { + if err := closer.Close(); err != nil { + return err + } + } + return nil +} + +// Do not access this directly. +// +//go:embed kmeshsockopscompat_bpfeb.o +var _KmeshSockopsCompatBytes []byte diff --git a/bpf/kmesh/bpf2go/kernelnative/kmeshsockopscompat_bpfel.go b/bpf/kmesh/bpf2go/kernelnative/kmeshsockopscompat_bpfel.go new file mode 100644 index 000000000..6a07cdbef --- /dev/null +++ b/bpf/kmesh/bpf2go/kernelnative/kmeshsockopscompat_bpfel.go @@ -0,0 +1,192 @@ +// Code generated by bpf2go; DO NOT EDIT. +//go:build 386 || amd64 || arm || arm64 || loong64 || mips64le || mipsle || ppc64le || riscv64 + +package bpf2go + +import ( + "bytes" + _ "embed" + "fmt" + "io" + + "github.com/cilium/ebpf" +) + +type KmeshSockopsCompatBuf struct{ Data [40]int8 } + +type KmeshSockopsCompatClusterSockData struct{ ClusterId uint32 } + +type KmeshSockopsCompatManagerKey struct { + NetnsCookie uint64 + _ [8]byte +} + +type KmeshSockopsCompatSockStorageData struct { + ConnectNs uint64 + LastReportNs uint64 + Direction uint8 + ConnectSuccess uint8 + ViaWaypoint bool + HasEncoded bool + HasSetIp bool + _ [3]byte + SkTuple struct { + Ipv4 struct { + Saddr uint32 + Daddr uint32 + Sport uint16 + Dport uint16 + } + _ [24]byte + } + _ [4]byte +} + +// LoadKmeshSockopsCompat returns the embedded CollectionSpec for KmeshSockopsCompat. +func LoadKmeshSockopsCompat() (*ebpf.CollectionSpec, error) { + reader := bytes.NewReader(_KmeshSockopsCompatBytes) + spec, err := ebpf.LoadCollectionSpecFromReader(reader) + if err != nil { + return nil, fmt.Errorf("can't load KmeshSockopsCompat: %w", err) + } + + return spec, err +} + +// LoadKmeshSockopsCompatObjects loads KmeshSockopsCompat and converts it into a struct. +// +// The following types are suitable as obj argument: +// +// *KmeshSockopsCompatObjects +// *KmeshSockopsCompatPrograms +// *KmeshSockopsCompatMaps +// +// See ebpf.CollectionSpec.LoadAndAssign documentation for details. +func LoadKmeshSockopsCompatObjects(obj interface{}, opts *ebpf.CollectionOptions) error { + spec, err := LoadKmeshSockopsCompat() + if err != nil { + return err + } + + return spec.LoadAndAssign(obj, opts) +} + +// KmeshSockopsCompatSpecs contains maps and programs before they are loaded into the kernel. +// +// It can be passed ebpf.CollectionSpec.Assign. +type KmeshSockopsCompatSpecs struct { + KmeshSockopsCompatProgramSpecs + KmeshSockopsCompatMapSpecs + KmeshSockopsCompatVariableSpecs +} + +// KmeshSockopsCompatProgramSpecs contains programs before they are loaded into the kernel. +// +// It can be passed ebpf.CollectionSpec.Assign. +type KmeshSockopsCompatProgramSpecs struct { + SockopsProg *ebpf.ProgramSpec `ebpf:"sockops_prog"` +} + +// KmeshSockopsCompatMapSpecs contains maps before they are loaded into the kernel. +// +// It can be passed ebpf.CollectionSpec.Assign. +type KmeshSockopsCompatMapSpecs struct { + KmClusterSock *ebpf.MapSpec `ebpf:"km_cluster_sock"` + KmClusterstats *ebpf.MapSpec `ebpf:"km_clusterstats"` + KmLogEvent *ebpf.MapSpec `ebpf:"km_log_event"` + KmManage *ebpf.MapSpec `ebpf:"km_manage"` + KmSockstorage *ebpf.MapSpec `ebpf:"km_sockstorage"` + KmTmpbuf *ebpf.MapSpec `ebpf:"km_tmpbuf"` + KmeshMap1600 *ebpf.MapSpec `ebpf:"kmesh_map1600"` + KmeshMap192 *ebpf.MapSpec `ebpf:"kmesh_map192"` + KmeshMap296 *ebpf.MapSpec `ebpf:"kmesh_map296"` + KmeshMap64 *ebpf.MapSpec `ebpf:"kmesh_map64"` +} + +// KmeshSockopsCompatVariableSpecs contains global variables before they are loaded into the kernel. +// +// It can be passed ebpf.CollectionSpec.Assign. +type KmeshSockopsCompatVariableSpecs struct { + BpfLogLevel *ebpf.VariableSpec `ebpf:"bpf_log_level"` +} + +// KmeshSockopsCompatObjects contains all objects after they have been loaded into the kernel. +// +// It can be passed to LoadKmeshSockopsCompatObjects or ebpf.CollectionSpec.LoadAndAssign. +type KmeshSockopsCompatObjects struct { + KmeshSockopsCompatPrograms + KmeshSockopsCompatMaps + KmeshSockopsCompatVariables +} + +func (o *KmeshSockopsCompatObjects) Close() error { + return _KmeshSockopsCompatClose( + &o.KmeshSockopsCompatPrograms, + &o.KmeshSockopsCompatMaps, + ) +} + +// KmeshSockopsCompatMaps contains all maps after they have been loaded into the kernel. +// +// It can be passed to LoadKmeshSockopsCompatObjects or ebpf.CollectionSpec.LoadAndAssign. +type KmeshSockopsCompatMaps struct { + KmClusterSock *ebpf.Map `ebpf:"km_cluster_sock"` + KmClusterstats *ebpf.Map `ebpf:"km_clusterstats"` + KmLogEvent *ebpf.Map `ebpf:"km_log_event"` + KmManage *ebpf.Map `ebpf:"km_manage"` + KmSockstorage *ebpf.Map `ebpf:"km_sockstorage"` + KmTmpbuf *ebpf.Map `ebpf:"km_tmpbuf"` + KmeshMap1600 *ebpf.Map `ebpf:"kmesh_map1600"` + KmeshMap192 *ebpf.Map `ebpf:"kmesh_map192"` + KmeshMap296 *ebpf.Map `ebpf:"kmesh_map296"` + KmeshMap64 *ebpf.Map `ebpf:"kmesh_map64"` +} + +func (m *KmeshSockopsCompatMaps) Close() error { + return _KmeshSockopsCompatClose( + m.KmClusterSock, + m.KmClusterstats, + m.KmLogEvent, + m.KmManage, + m.KmSockstorage, + m.KmTmpbuf, + m.KmeshMap1600, + m.KmeshMap192, + m.KmeshMap296, + m.KmeshMap64, + ) +} + +// KmeshSockopsCompatVariables contains all global variables after they have been loaded into the kernel. +// +// It can be passed to LoadKmeshSockopsCompatObjects or ebpf.CollectionSpec.LoadAndAssign. +type KmeshSockopsCompatVariables struct { + BpfLogLevel *ebpf.Variable `ebpf:"bpf_log_level"` +} + +// KmeshSockopsCompatPrograms contains all programs after they have been loaded into the kernel. +// +// It can be passed to LoadKmeshSockopsCompatObjects or ebpf.CollectionSpec.LoadAndAssign. +type KmeshSockopsCompatPrograms struct { + SockopsProg *ebpf.Program `ebpf:"sockops_prog"` +} + +func (p *KmeshSockopsCompatPrograms) Close() error { + return _KmeshSockopsCompatClose( + p.SockopsProg, + ) +} + +func _KmeshSockopsCompatClose(closers ...io.Closer) error { + for _, closer := range closers { + if err := closer.Close(); err != nil { + return err + } + } + return nil +} + +// Do not access this directly. +// +//go:embed kmeshsockopscompat_bpfel.o +var _KmeshSockopsCompatBytes []byte diff --git a/pkg/status/status_server_test.go b/pkg/status/status_server_test.go index dea4b7313..097991a82 100644 --- a/pkg/status/status_server_test.go +++ b/pkg/status/status_server_test.go @@ -21,11 +21,14 @@ import ( "encoding/json" "fmt" "io" + "math/rand" "net/http" "net/http/httptest" "net/netip" + "os" "sort" "testing" + "time" "github.com/sirupsen/logrus" "github.com/stretchr/testify/assert" @@ -133,11 +136,11 @@ func TestServer_setLoggerLevel(t *testing.T) { } } -func TestServer_configDumpWorkload(t *testing.T) { - w1 := &workloadapi.Workload{ +func buildWorkload(name string) *workloadapi.Workload { + return &workloadapi.Workload{ Uid: "cluster0//Pod/ns/name", Namespace: "ns", - Name: "name", + Name: name, Addresses: [][]byte{netip.AddrFrom4([4]byte{1, 2, 3, 4}).AsSlice()}, Network: "testnetwork", CanonicalName: "foo", @@ -173,10 +176,13 @@ func TestServer_configDumpWorkload(t *testing.T) { }, }, } - svc := &workloadapi.Service{ - Name: "svc", +} + +func buildService(name, hostname string) *workloadapi.Service { + return &workloadapi.Service{ + Name: name, Namespace: "ns", - Hostname: "hostname", + Hostname: hostname, Ports: []*workloadapi.Port{ { ServicePort: 80, @@ -199,6 +205,12 @@ func TestServer_configDumpWorkload(t *testing.T) { }, }, }} +} + +func TestServer_configDumpWorkload(t *testing.T) { + w := buildWorkload("name") + svc := buildService("svc", "hostname") + policy := &security.Authorization{ Name: "policy", Namespace: "ns", @@ -207,7 +219,7 @@ func TestServer_configDumpWorkload(t *testing.T) { } fakeWorkloadCache := cache.NewWorkloadCache() fakeServiceCache := cache.NewServiceCache() - fakeWorkloadCache.AddOrUpdateWorkload(w1) + fakeWorkloadCache.AddOrUpdateWorkload(w) fakeServiceCache.AddOrUpdateService(svc) fakeAuth := auth.NewRbac(fakeWorkloadCache) fakeAuth.UpdatePolicy(policy) @@ -225,20 +237,148 @@ func TestServer_configDumpWorkload(t *testing.T) { } // Create a new HTTP request and response - req := httptest.NewRequest(http.MethodGet, "/configDumpWorkload", nil) - w := httptest.NewRecorder() + req1 := httptest.NewRequest(http.MethodGet, "/configDumpWorkload", nil) + w1 := httptest.NewRecorder() // Call the configDumpWorkload function - server.configDumpWorkload(w, req) + server.configDumpWorkload(w1, req1) // Check the response status code - if w.Code != http.StatusOK { - t.Errorf("Expected status code %d, but got %d", http.StatusOK, w.Code) + if w1.Code != http.StatusOK { + t.Errorf("Expected status code %d, but got %d", http.StatusOK, w1.Code) + } + + util.RefreshGoldenFile(t, w1.Body.Bytes(), "./testdata/workload_configdump.json") + + util.CompareContent(t, w1.Body.Bytes(), "./testdata/workload_configdump.json") + + fakeWorkloadCache = cache.NewWorkloadCache() + fakeServiceCache = cache.NewServiceCache() + + workloads := []*workloadapi.Workload{} + services := []*workloadapi.Service{} + + for i := 0; i < 10; i++ { + w := buildWorkload(fmt.Sprintf("workload-%d", i)) + w.Uid = fmt.Sprintf("cluster0//Pod/ns/workload-%d", i) + workloads = append(workloads, w) + svc := buildService(fmt.Sprintf("service-%d", i), fmt.Sprintf("hostname-%d", i)) + services = append(services, svc) + + fakeWorkloadCache.AddOrUpdateWorkload(w) + fakeServiceCache.AddOrUpdateService(svc) } - util.RefreshGoldenFile(t, w.Body.Bytes(), "./testdata/workload_configdump.json") + // Create a new HTTP request and response + req2 := httptest.NewRequest(http.MethodGet, "/configDumpWorkload", nil) + w2 := httptest.NewRecorder() - util.CompareContent(t, w.Body.Bytes(), "./testdata/workload_configdump.json") + server = &Server{ + xdsClient: &controller.XdsClient{ + WorkloadController: &workload.Controller{ + Processor: &workload.Processor{ + WorkloadCache: fakeWorkloadCache, + ServiceCache: fakeServiceCache, + }, + Rbac: fakeAuth, + }, + }, + } + + // Call the configDumpWorkload function + server.configDumpWorkload(w2, req2) + + // Check the response status code + if w2.Code != http.StatusOK { + t.Errorf("Expected status code %d, but got %d", http.StatusOK, w2.Code) + } + + fakeWorkloadCache = cache.NewWorkloadCache() + fakeServiceCache = cache.NewServiceCache() + // Modify workloads and services properties + for i := 0; i < 5; i++ { // Modify first 5 items + // Modify workload properties + w := buildWorkload(fmt.Sprintf("workload-%d-modified", i)) + w.ClusterId = "cluster1" // Changed cluster + w.Uid = fmt.Sprintf("cluster1//Pod/ns/workload-%d-modified", i) + w.Status = workloadapi.WorkloadStatus_UNHEALTHY + + workloads[i] = w + // Modify service properties + svc := buildService(fmt.Sprintf("service-%d-modified", i), fmt.Sprintf("hostname-%d-modified", i)) + // Modify service ports + svc.Ports = []*workloadapi.Port{ + { + ServicePort: 90, + TargetPort: 9090, + }, + { + ServicePort: 91, + TargetPort: 0, + }, + { + ServicePort: 92, + TargetPort: 0, + }, + } + services[i] = svc + } + + for _, w := range workloads { + fakeWorkloadCache.AddOrUpdateWorkload(w) + } + for _, svc := range services { + fakeServiceCache.AddOrUpdateService(svc) + } + + // Second dump - save modified state to JSON + req3 := httptest.NewRequest(http.MethodGet, "/configDumpWorkload", nil) + w3 := httptest.NewRecorder() + + server = &Server{ + xdsClient: &controller.XdsClient{ + WorkloadController: &workload.Controller{ + Processor: &workload.Processor{ + WorkloadCache: fakeWorkloadCache, + ServiceCache: fakeServiceCache, + }, + Rbac: fakeAuth, + }, + }, + } + + rand.New(rand.NewSource(time.Now().UnixNano())) + rand.Shuffle(len(workloads), func(i, j int) { + workloads[i], workloads[j] = workloads[j], workloads[i] + }) + rand.Shuffle(len(services), func(i, j int) { + services[i], services[j] = services[j], services[i] + }) + + server.configDumpWorkload(w3, req3) + + if w3.Code != http.StatusOK { + t.Errorf("Expected status code %d, but got %d", http.StatusOK, w3.Code) + } + + // compare the modified dump with the original + err := util.Compare(w3.Body.Bytes(), w2.Body.Bytes()) + if err != nil { + fmt.Printf("Modified dump differs from original: %v\n", err) + } else { + t.Error("Modified dump should differ from original, but they are the same") + } + + // save original and modified dumps to json files + err = os.WriteFile("./testdata/workload_configdump_original.json", w2.Body.Bytes(), 0644) + if err != nil { + t.Errorf("Failed to write original dump to file: %v", err) + } + + err = os.WriteFile("./testdata/workload_configdump_modified.json", w3.Body.Bytes(), 0644) + if err != nil { + t.Errorf("Failed to write modified dump to file: %v", err) + } } func TestServer_dumpWorkloadBpfMap(t *testing.T) { diff --git a/pkg/status/testdata/workload_configdump_modified.json b/pkg/status/testdata/workload_configdump_modified.json new file mode 100644 index 000000000..c983043b5 --- /dev/null +++ b/pkg/status/testdata/workload_configdump_modified.json @@ -0,0 +1,495 @@ +{ + "workloads": [ + { + "uid": "cluster1//Pod/ns/workload-0-modified", + "addresses": [ + "1.2.3.4" + ], + "waypoint": "testnetwork/192.168.1.10", + "protocol": "NONE", + "name": "workload-0-modified", + "namespace": "ns", + "serviceAccount": "", + "workloadName": "name", + "workloadType": "POD", + "canonicalName": "foo", + "canonicalRevision": "latest", + "clusterId": "cluster1", + "locality": {}, + "node": "", + "network": "testnetwork", + "status": "UNHEALTHY", + "applicationTunnel": { + "protocol": "" + }, + "services": [ + "ns/hostname" + ] + }, + { + "uid": "cluster1//Pod/ns/workload-1-modified", + "addresses": [ + "1.2.3.4" + ], + "waypoint": "testnetwork/192.168.1.10", + "protocol": "NONE", + "name": "workload-1-modified", + "namespace": "ns", + "serviceAccount": "", + "workloadName": "name", + "workloadType": "POD", + "canonicalName": "foo", + "canonicalRevision": "latest", + "clusterId": "cluster1", + "locality": {}, + "node": "", + "network": "testnetwork", + "status": "UNHEALTHY", + "applicationTunnel": { + "protocol": "" + }, + "services": [ + "ns/hostname" + ] + }, + { + "uid": "cluster1//Pod/ns/workload-2-modified", + "addresses": [ + "1.2.3.4" + ], + "waypoint": "testnetwork/192.168.1.10", + "protocol": "NONE", + "name": "workload-2-modified", + "namespace": "ns", + "serviceAccount": "", + "workloadName": "name", + "workloadType": "POD", + "canonicalName": "foo", + "canonicalRevision": "latest", + "clusterId": "cluster1", + "locality": {}, + "node": "", + "network": "testnetwork", + "status": "UNHEALTHY", + "applicationTunnel": { + "protocol": "" + }, + "services": [ + "ns/hostname" + ] + }, + { + "uid": "cluster1//Pod/ns/workload-3-modified", + "addresses": [ + "1.2.3.4" + ], + "waypoint": "testnetwork/192.168.1.10", + "protocol": "NONE", + "name": "workload-3-modified", + "namespace": "ns", + "serviceAccount": "", + "workloadName": "name", + "workloadType": "POD", + "canonicalName": "foo", + "canonicalRevision": "latest", + "clusterId": "cluster1", + "locality": {}, + "node": "", + "network": "testnetwork", + "status": "UNHEALTHY", + "applicationTunnel": { + "protocol": "" + }, + "services": [ + "ns/hostname" + ] + }, + { + "uid": "cluster1//Pod/ns/workload-4-modified", + "addresses": [ + "1.2.3.4" + ], + "waypoint": "testnetwork/192.168.1.10", + "protocol": "NONE", + "name": "workload-4-modified", + "namespace": "ns", + "serviceAccount": "", + "workloadName": "name", + "workloadType": "POD", + "canonicalName": "foo", + "canonicalRevision": "latest", + "clusterId": "cluster1", + "locality": {}, + "node": "", + "network": "testnetwork", + "status": "UNHEALTHY", + "applicationTunnel": { + "protocol": "" + }, + "services": [ + "ns/hostname" + ] + }, + { + "uid": "cluster0//Pod/ns/workload-5", + "addresses": [ + "1.2.3.4" + ], + "waypoint": "testnetwork/192.168.1.10", + "protocol": "NONE", + "name": "workload-5", + "namespace": "ns", + "serviceAccount": "", + "workloadName": "name", + "workloadType": "POD", + "canonicalName": "foo", + "canonicalRevision": "latest", + "clusterId": "cluster0", + "locality": {}, + "node": "", + "network": "testnetwork", + "status": "HEALTHY", + "applicationTunnel": { + "protocol": "" + }, + "services": [ + "ns/hostname" + ] + }, + { + "uid": "cluster0//Pod/ns/workload-6", + "addresses": [ + "1.2.3.4" + ], + "waypoint": "testnetwork/192.168.1.10", + "protocol": "NONE", + "name": "workload-6", + "namespace": "ns", + "serviceAccount": "", + "workloadName": "name", + "workloadType": "POD", + "canonicalName": "foo", + "canonicalRevision": "latest", + "clusterId": "cluster0", + "locality": {}, + "node": "", + "network": "testnetwork", + "status": "HEALTHY", + "applicationTunnel": { + "protocol": "" + }, + "services": [ + "ns/hostname" + ] + }, + { + "uid": "cluster0//Pod/ns/workload-7", + "addresses": [ + "1.2.3.4" + ], + "waypoint": "testnetwork/192.168.1.10", + "protocol": "NONE", + "name": "workload-7", + "namespace": "ns", + "serviceAccount": "", + "workloadName": "name", + "workloadType": "POD", + "canonicalName": "foo", + "canonicalRevision": "latest", + "clusterId": "cluster0", + "locality": {}, + "node": "", + "network": "testnetwork", + "status": "HEALTHY", + "applicationTunnel": { + "protocol": "" + }, + "services": [ + "ns/hostname" + ] + }, + { + "uid": "cluster0//Pod/ns/workload-8", + "addresses": [ + "1.2.3.4" + ], + "waypoint": "testnetwork/192.168.1.10", + "protocol": "NONE", + "name": "workload-8", + "namespace": "ns", + "serviceAccount": "", + "workloadName": "name", + "workloadType": "POD", + "canonicalName": "foo", + "canonicalRevision": "latest", + "clusterId": "cluster0", + "locality": {}, + "node": "", + "network": "testnetwork", + "status": "HEALTHY", + "applicationTunnel": { + "protocol": "" + }, + "services": [ + "ns/hostname" + ] + }, + { + "uid": "cluster0//Pod/ns/workload-9", + "addresses": [ + "1.2.3.4" + ], + "waypoint": "testnetwork/192.168.1.10", + "protocol": "NONE", + "name": "workload-9", + "namespace": "ns", + "serviceAccount": "", + "workloadName": "name", + "workloadType": "POD", + "canonicalName": "foo", + "canonicalRevision": "latest", + "clusterId": "cluster0", + "locality": {}, + "node": "", + "network": "testnetwork", + "status": "HEALTHY", + "applicationTunnel": { + "protocol": "" + }, + "services": [ + "ns/hostname" + ] + } + ], + "services": [ + { + "name": "service-0-modified", + "namespace": "ns", + "hostname": "hostname-0-modified", + "vips": [], + "ports": [ + { + "service_port": 90, + "target_port": 9090 + }, + { + "service_port": 91 + }, + { + "service_port": 92 + } + ], + "loadBalancer": null, + "waypoint": { + "destination": "testnetwork/192.168.1.11" + } + }, + { + "name": "service-1-modified", + "namespace": "ns", + "hostname": "hostname-1-modified", + "vips": [], + "ports": [ + { + "service_port": 90, + "target_port": 9090 + }, + { + "service_port": 91 + }, + { + "service_port": 92 + } + ], + "loadBalancer": null, + "waypoint": { + "destination": "testnetwork/192.168.1.11" + } + }, + { + "name": "service-2-modified", + "namespace": "ns", + "hostname": "hostname-2-modified", + "vips": [], + "ports": [ + { + "service_port": 90, + "target_port": 9090 + }, + { + "service_port": 91 + }, + { + "service_port": 92 + } + ], + "loadBalancer": null, + "waypoint": { + "destination": "testnetwork/192.168.1.11" + } + }, + { + "name": "service-3-modified", + "namespace": "ns", + "hostname": "hostname-3-modified", + "vips": [], + "ports": [ + { + "service_port": 90, + "target_port": 9090 + }, + { + "service_port": 91 + }, + { + "service_port": 92 + } + ], + "loadBalancer": null, + "waypoint": { + "destination": "testnetwork/192.168.1.11" + } + }, + { + "name": "service-4-modified", + "namespace": "ns", + "hostname": "hostname-4-modified", + "vips": [], + "ports": [ + { + "service_port": 90, + "target_port": 9090 + }, + { + "service_port": 91 + }, + { + "service_port": 92 + } + ], + "loadBalancer": null, + "waypoint": { + "destination": "testnetwork/192.168.1.11" + } + }, + { + "name": "service-5", + "namespace": "ns", + "hostname": "hostname-5", + "vips": [], + "ports": [ + { + "service_port": 80, + "target_port": 8080 + }, + { + "service_port": 81 + }, + { + "service_port": 82 + } + ], + "loadBalancer": null, + "waypoint": { + "destination": "testnetwork/192.168.1.11" + } + }, + { + "name": "service-6", + "namespace": "ns", + "hostname": "hostname-6", + "vips": [], + "ports": [ + { + "service_port": 80, + "target_port": 8080 + }, + { + "service_port": 81 + }, + { + "service_port": 82 + } + ], + "loadBalancer": null, + "waypoint": { + "destination": "testnetwork/192.168.1.11" + } + }, + { + "name": "service-7", + "namespace": "ns", + "hostname": "hostname-7", + "vips": [], + "ports": [ + { + "service_port": 80, + "target_port": 8080 + }, + { + "service_port": 81 + }, + { + "service_port": 82 + } + ], + "loadBalancer": null, + "waypoint": { + "destination": "testnetwork/192.168.1.11" + } + }, + { + "name": "service-8", + "namespace": "ns", + "hostname": "hostname-8", + "vips": [], + "ports": [ + { + "service_port": 80, + "target_port": 8080 + }, + { + "service_port": 81 + }, + { + "service_port": 82 + } + ], + "loadBalancer": null, + "waypoint": { + "destination": "testnetwork/192.168.1.11" + } + }, + { + "name": "service-9", + "namespace": "ns", + "hostname": "hostname-9", + "vips": [], + "ports": [ + { + "service_port": 80, + "target_port": 8080 + }, + { + "service_port": 81 + }, + { + "service_port": 82 + } + ], + "loadBalancer": null, + "waypoint": { + "destination": "testnetwork/192.168.1.11" + } + } + ], + "policies": [ + { + "name": "policy", + "namespace": "ns", + "scope": "GLOBAL", + "action": "ALLOW", + "rules": null + } + ] +} \ No newline at end of file diff --git a/pkg/status/testdata/workload_configdump_original.json b/pkg/status/testdata/workload_configdump_original.json new file mode 100644 index 000000000..40834898f --- /dev/null +++ b/pkg/status/testdata/workload_configdump_original.json @@ -0,0 +1,495 @@ +{ + "workloads": [ + { + "uid": "cluster0//Pod/ns/workload-0", + "addresses": [ + "1.2.3.4" + ], + "waypoint": "testnetwork/192.168.1.10", + "protocol": "NONE", + "name": "workload-0", + "namespace": "ns", + "serviceAccount": "", + "workloadName": "name", + "workloadType": "POD", + "canonicalName": "foo", + "canonicalRevision": "latest", + "clusterId": "cluster0", + "locality": {}, + "node": "", + "network": "testnetwork", + "status": "HEALTHY", + "applicationTunnel": { + "protocol": "" + }, + "services": [ + "ns/hostname" + ] + }, + { + "uid": "cluster0//Pod/ns/workload-1", + "addresses": [ + "1.2.3.4" + ], + "waypoint": "testnetwork/192.168.1.10", + "protocol": "NONE", + "name": "workload-1", + "namespace": "ns", + "serviceAccount": "", + "workloadName": "name", + "workloadType": "POD", + "canonicalName": "foo", + "canonicalRevision": "latest", + "clusterId": "cluster0", + "locality": {}, + "node": "", + "network": "testnetwork", + "status": "HEALTHY", + "applicationTunnel": { + "protocol": "" + }, + "services": [ + "ns/hostname" + ] + }, + { + "uid": "cluster0//Pod/ns/workload-2", + "addresses": [ + "1.2.3.4" + ], + "waypoint": "testnetwork/192.168.1.10", + "protocol": "NONE", + "name": "workload-2", + "namespace": "ns", + "serviceAccount": "", + "workloadName": "name", + "workloadType": "POD", + "canonicalName": "foo", + "canonicalRevision": "latest", + "clusterId": "cluster0", + "locality": {}, + "node": "", + "network": "testnetwork", + "status": "HEALTHY", + "applicationTunnel": { + "protocol": "" + }, + "services": [ + "ns/hostname" + ] + }, + { + "uid": "cluster0//Pod/ns/workload-3", + "addresses": [ + "1.2.3.4" + ], + "waypoint": "testnetwork/192.168.1.10", + "protocol": "NONE", + "name": "workload-3", + "namespace": "ns", + "serviceAccount": "", + "workloadName": "name", + "workloadType": "POD", + "canonicalName": "foo", + "canonicalRevision": "latest", + "clusterId": "cluster0", + "locality": {}, + "node": "", + "network": "testnetwork", + "status": "HEALTHY", + "applicationTunnel": { + "protocol": "" + }, + "services": [ + "ns/hostname" + ] + }, + { + "uid": "cluster0//Pod/ns/workload-4", + "addresses": [ + "1.2.3.4" + ], + "waypoint": "testnetwork/192.168.1.10", + "protocol": "NONE", + "name": "workload-4", + "namespace": "ns", + "serviceAccount": "", + "workloadName": "name", + "workloadType": "POD", + "canonicalName": "foo", + "canonicalRevision": "latest", + "clusterId": "cluster0", + "locality": {}, + "node": "", + "network": "testnetwork", + "status": "HEALTHY", + "applicationTunnel": { + "protocol": "" + }, + "services": [ + "ns/hostname" + ] + }, + { + "uid": "cluster0//Pod/ns/workload-5", + "addresses": [ + "1.2.3.4" + ], + "waypoint": "testnetwork/192.168.1.10", + "protocol": "NONE", + "name": "workload-5", + "namespace": "ns", + "serviceAccount": "", + "workloadName": "name", + "workloadType": "POD", + "canonicalName": "foo", + "canonicalRevision": "latest", + "clusterId": "cluster0", + "locality": {}, + "node": "", + "network": "testnetwork", + "status": "HEALTHY", + "applicationTunnel": { + "protocol": "" + }, + "services": [ + "ns/hostname" + ] + }, + { + "uid": "cluster0//Pod/ns/workload-6", + "addresses": [ + "1.2.3.4" + ], + "waypoint": "testnetwork/192.168.1.10", + "protocol": "NONE", + "name": "workload-6", + "namespace": "ns", + "serviceAccount": "", + "workloadName": "name", + "workloadType": "POD", + "canonicalName": "foo", + "canonicalRevision": "latest", + "clusterId": "cluster0", + "locality": {}, + "node": "", + "network": "testnetwork", + "status": "HEALTHY", + "applicationTunnel": { + "protocol": "" + }, + "services": [ + "ns/hostname" + ] + }, + { + "uid": "cluster0//Pod/ns/workload-7", + "addresses": [ + "1.2.3.4" + ], + "waypoint": "testnetwork/192.168.1.10", + "protocol": "NONE", + "name": "workload-7", + "namespace": "ns", + "serviceAccount": "", + "workloadName": "name", + "workloadType": "POD", + "canonicalName": "foo", + "canonicalRevision": "latest", + "clusterId": "cluster0", + "locality": {}, + "node": "", + "network": "testnetwork", + "status": "HEALTHY", + "applicationTunnel": { + "protocol": "" + }, + "services": [ + "ns/hostname" + ] + }, + { + "uid": "cluster0//Pod/ns/workload-8", + "addresses": [ + "1.2.3.4" + ], + "waypoint": "testnetwork/192.168.1.10", + "protocol": "NONE", + "name": "workload-8", + "namespace": "ns", + "serviceAccount": "", + "workloadName": "name", + "workloadType": "POD", + "canonicalName": "foo", + "canonicalRevision": "latest", + "clusterId": "cluster0", + "locality": {}, + "node": "", + "network": "testnetwork", + "status": "HEALTHY", + "applicationTunnel": { + "protocol": "" + }, + "services": [ + "ns/hostname" + ] + }, + { + "uid": "cluster0//Pod/ns/workload-9", + "addresses": [ + "1.2.3.4" + ], + "waypoint": "testnetwork/192.168.1.10", + "protocol": "NONE", + "name": "workload-9", + "namespace": "ns", + "serviceAccount": "", + "workloadName": "name", + "workloadType": "POD", + "canonicalName": "foo", + "canonicalRevision": "latest", + "clusterId": "cluster0", + "locality": {}, + "node": "", + "network": "testnetwork", + "status": "HEALTHY", + "applicationTunnel": { + "protocol": "" + }, + "services": [ + "ns/hostname" + ] + } + ], + "services": [ + { + "name": "service-0", + "namespace": "ns", + "hostname": "hostname-0", + "vips": [], + "ports": [ + { + "service_port": 80, + "target_port": 8080 + }, + { + "service_port": 81 + }, + { + "service_port": 82 + } + ], + "loadBalancer": null, + "waypoint": { + "destination": "testnetwork/192.168.1.11" + } + }, + { + "name": "service-1", + "namespace": "ns", + "hostname": "hostname-1", + "vips": [], + "ports": [ + { + "service_port": 80, + "target_port": 8080 + }, + { + "service_port": 81 + }, + { + "service_port": 82 + } + ], + "loadBalancer": null, + "waypoint": { + "destination": "testnetwork/192.168.1.11" + } + }, + { + "name": "service-2", + "namespace": "ns", + "hostname": "hostname-2", + "vips": [], + "ports": [ + { + "service_port": 80, + "target_port": 8080 + }, + { + "service_port": 81 + }, + { + "service_port": 82 + } + ], + "loadBalancer": null, + "waypoint": { + "destination": "testnetwork/192.168.1.11" + } + }, + { + "name": "service-3", + "namespace": "ns", + "hostname": "hostname-3", + "vips": [], + "ports": [ + { + "service_port": 80, + "target_port": 8080 + }, + { + "service_port": 81 + }, + { + "service_port": 82 + } + ], + "loadBalancer": null, + "waypoint": { + "destination": "testnetwork/192.168.1.11" + } + }, + { + "name": "service-4", + "namespace": "ns", + "hostname": "hostname-4", + "vips": [], + "ports": [ + { + "service_port": 80, + "target_port": 8080 + }, + { + "service_port": 81 + }, + { + "service_port": 82 + } + ], + "loadBalancer": null, + "waypoint": { + "destination": "testnetwork/192.168.1.11" + } + }, + { + "name": "service-5", + "namespace": "ns", + "hostname": "hostname-5", + "vips": [], + "ports": [ + { + "service_port": 80, + "target_port": 8080 + }, + { + "service_port": 81 + }, + { + "service_port": 82 + } + ], + "loadBalancer": null, + "waypoint": { + "destination": "testnetwork/192.168.1.11" + } + }, + { + "name": "service-6", + "namespace": "ns", + "hostname": "hostname-6", + "vips": [], + "ports": [ + { + "service_port": 80, + "target_port": 8080 + }, + { + "service_port": 81 + }, + { + "service_port": 82 + } + ], + "loadBalancer": null, + "waypoint": { + "destination": "testnetwork/192.168.1.11" + } + }, + { + "name": "service-7", + "namespace": "ns", + "hostname": "hostname-7", + "vips": [], + "ports": [ + { + "service_port": 80, + "target_port": 8080 + }, + { + "service_port": 81 + }, + { + "service_port": 82 + } + ], + "loadBalancer": null, + "waypoint": { + "destination": "testnetwork/192.168.1.11" + } + }, + { + "name": "service-8", + "namespace": "ns", + "hostname": "hostname-8", + "vips": [], + "ports": [ + { + "service_port": 80, + "target_port": 8080 + }, + { + "service_port": 81 + }, + { + "service_port": 82 + } + ], + "loadBalancer": null, + "waypoint": { + "destination": "testnetwork/192.168.1.11" + } + }, + { + "name": "service-9", + "namespace": "ns", + "hostname": "hostname-9", + "vips": [], + "ports": [ + { + "service_port": 80, + "target_port": 8080 + }, + { + "service_port": 81 + }, + { + "service_port": 82 + } + ], + "loadBalancer": null, + "waypoint": { + "destination": "testnetwork/192.168.1.11" + } + } + ], + "policies": [ + { + "name": "policy", + "namespace": "ns", + "scope": "GLOBAL", + "action": "ALLOW", + "rules": null + } + ] +} \ No newline at end of file From 52bc681304688c7db223174461dbe85e64abda28 Mon Sep 17 00:00:00 2001 From: aicee Date: Thu, 3 Jul 2025 14:42:59 +0800 Subject: [PATCH 3/6] add unit test for sorting dump output by name, and revise the code according to the code review results. Signed-off-by: aicee --- .../kernelnative/kmeshcgroupsock_bpfeb.go | 242 ------------------ .../kernelnative/kmeshcgroupsock_bpfel.go | 242 ------------------ .../kmeshcgroupsockcompat_bpfeb.go | 242 ------------------ .../kmeshcgroupsockcompat_bpfel.go | 242 ------------------ .../bpf2go/kernelnative/kmeshsockops_bpfeb.go | 192 -------------- .../bpf2go/kernelnative/kmeshsockops_bpfel.go | 192 -------------- .../kernelnative/kmeshsockopscompat_bpfeb.go | 192 -------------- .../kernelnative/kmeshsockopscompat_bpfel.go | 192 -------------- pkg/status/status_server_test.go | 44 +--- ... workload_configdump_modified_sorted.json} | 0 ... workload_configdump_original_sorted.json} | 0 11 files changed, 8 insertions(+), 1772 deletions(-) delete mode 100644 bpf/kmesh/bpf2go/kernelnative/kmeshcgroupsock_bpfeb.go delete mode 100644 bpf/kmesh/bpf2go/kernelnative/kmeshcgroupsock_bpfel.go delete mode 100644 bpf/kmesh/bpf2go/kernelnative/kmeshcgroupsockcompat_bpfeb.go delete mode 100644 bpf/kmesh/bpf2go/kernelnative/kmeshcgroupsockcompat_bpfel.go delete mode 100644 bpf/kmesh/bpf2go/kernelnative/kmeshsockops_bpfeb.go delete mode 100644 bpf/kmesh/bpf2go/kernelnative/kmeshsockops_bpfel.go delete mode 100644 bpf/kmesh/bpf2go/kernelnative/kmeshsockopscompat_bpfeb.go delete mode 100644 bpf/kmesh/bpf2go/kernelnative/kmeshsockopscompat_bpfel.go rename pkg/status/testdata/{workload_configdump_modified.json => workload_configdump_modified_sorted.json} (100%) rename pkg/status/testdata/{workload_configdump_original.json => workload_configdump_original_sorted.json} (100%) diff --git a/bpf/kmesh/bpf2go/kernelnative/kmeshcgroupsock_bpfeb.go b/bpf/kmesh/bpf2go/kernelnative/kmeshcgroupsock_bpfeb.go deleted file mode 100644 index e9a4db93e..000000000 --- a/bpf/kmesh/bpf2go/kernelnative/kmeshcgroupsock_bpfeb.go +++ /dev/null @@ -1,242 +0,0 @@ -// Code generated by bpf2go; DO NOT EDIT. -//go:build mips || mips64 || ppc64 || s390x - -package bpf2go - -import ( - "bytes" - _ "embed" - "fmt" - "io" - - "github.com/cilium/ebpf" -) - -type KmeshCgroupSockBuf struct{ Data [40]int8 } - -type KmeshCgroupSockClusterSockData struct{ ClusterId uint32 } - -type KmeshCgroupSockManagerKey struct { - NetnsCookie uint64 - _ [8]byte -} - -type KmeshCgroupSockRatelimitKey struct { - Key struct { - SkSkb struct { - Netns uint64 - Ipv4 uint32 - Port uint32 - Family uint32 - _ [4]byte - } - } -} - -type KmeshCgroupSockRatelimitValue struct { - LastTopup uint64 - Tokens uint64 -} - -type KmeshCgroupSockSockStorageData struct { - ConnectNs uint64 - LastReportNs uint64 - Direction uint8 - ConnectSuccess uint8 - ViaWaypoint bool - HasEncoded bool - HasSetIp bool - _ [3]byte - SkTuple struct { - Ipv4 struct { - Saddr uint32 - Daddr uint32 - Sport uint16 - Dport uint16 - } - _ [24]byte - } - _ [4]byte -} - -// LoadKmeshCgroupSock returns the embedded CollectionSpec for KmeshCgroupSock. -func LoadKmeshCgroupSock() (*ebpf.CollectionSpec, error) { - reader := bytes.NewReader(_KmeshCgroupSockBytes) - spec, err := ebpf.LoadCollectionSpecFromReader(reader) - if err != nil { - return nil, fmt.Errorf("can't load KmeshCgroupSock: %w", err) - } - - return spec, err -} - -// LoadKmeshCgroupSockObjects loads KmeshCgroupSock and converts it into a struct. -// -// The following types are suitable as obj argument: -// -// *KmeshCgroupSockObjects -// *KmeshCgroupSockPrograms -// *KmeshCgroupSockMaps -// -// See ebpf.CollectionSpec.LoadAndAssign documentation for details. -func LoadKmeshCgroupSockObjects(obj interface{}, opts *ebpf.CollectionOptions) error { - spec, err := LoadKmeshCgroupSock() - if err != nil { - return err - } - - return spec.LoadAndAssign(obj, opts) -} - -// KmeshCgroupSockSpecs contains maps and programs before they are loaded into the kernel. -// -// It can be passed ebpf.CollectionSpec.Assign. -type KmeshCgroupSockSpecs struct { - KmeshCgroupSockProgramSpecs - KmeshCgroupSockMapSpecs - KmeshCgroupSockVariableSpecs -} - -// KmeshCgroupSockProgramSpecs contains programs before they are loaded into the kernel. -// -// It can be passed ebpf.CollectionSpec.Assign. -type KmeshCgroupSockProgramSpecs struct { - CgroupConnect4Prog *ebpf.ProgramSpec `ebpf:"cgroup_connect4_prog"` - ClusterManager *ebpf.ProgramSpec `ebpf:"cluster_manager"` - FilterChainManager *ebpf.ProgramSpec `ebpf:"filter_chain_manager"` - FilterManager *ebpf.ProgramSpec `ebpf:"filter_manager"` -} - -// KmeshCgroupSockMapSpecs contains maps before they are loaded into the kernel. -// -// It can be passed ebpf.CollectionSpec.Assign. -type KmeshCgroupSockMapSpecs struct { - KmCgrptailcall *ebpf.MapSpec `ebpf:"km_cgrptailcall"` - KmCluster *ebpf.MapSpec `ebpf:"km_cluster"` - KmClusterEps *ebpf.MapSpec `ebpf:"km_cluster_eps"` - KmClusterSock *ebpf.MapSpec `ebpf:"km_cluster_sock"` - KmClusterstats *ebpf.MapSpec `ebpf:"km_clusterstats"` - KmEpsData *ebpf.MapSpec `ebpf:"km_eps_data"` - KmListener *ebpf.MapSpec `ebpf:"km_listener"` - KmLogEvent *ebpf.MapSpec `ebpf:"km_log_event"` - KmMaglevOuter *ebpf.MapSpec `ebpf:"km_maglev_outer"` - KmManage *ebpf.MapSpec `ebpf:"km_manage"` - KmRatelimit *ebpf.MapSpec `ebpf:"km_ratelimit"` - KmSockstorage *ebpf.MapSpec `ebpf:"km_sockstorage"` - KmTailcallCtx *ebpf.MapSpec `ebpf:"km_tailcall_ctx"` - KmTmpbuf *ebpf.MapSpec `ebpf:"km_tmpbuf"` - KmeshMap1600 *ebpf.MapSpec `ebpf:"kmesh_map1600"` - KmeshMap192 *ebpf.MapSpec `ebpf:"kmesh_map192"` - KmeshMap296 *ebpf.MapSpec `ebpf:"kmesh_map296"` - KmeshMap64 *ebpf.MapSpec `ebpf:"kmesh_map64"` -} - -// KmeshCgroupSockVariableSpecs contains global variables before they are loaded into the kernel. -// -// It can be passed ebpf.CollectionSpec.Assign. -type KmeshCgroupSockVariableSpecs struct { - BpfLogLevel *ebpf.VariableSpec `ebpf:"bpf_log_level"` -} - -// KmeshCgroupSockObjects contains all objects after they have been loaded into the kernel. -// -// It can be passed to LoadKmeshCgroupSockObjects or ebpf.CollectionSpec.LoadAndAssign. -type KmeshCgroupSockObjects struct { - KmeshCgroupSockPrograms - KmeshCgroupSockMaps - KmeshCgroupSockVariables -} - -func (o *KmeshCgroupSockObjects) Close() error { - return _KmeshCgroupSockClose( - &o.KmeshCgroupSockPrograms, - &o.KmeshCgroupSockMaps, - ) -} - -// KmeshCgroupSockMaps contains all maps after they have been loaded into the kernel. -// -// It can be passed to LoadKmeshCgroupSockObjects or ebpf.CollectionSpec.LoadAndAssign. -type KmeshCgroupSockMaps struct { - KmCgrptailcall *ebpf.Map `ebpf:"km_cgrptailcall"` - KmCluster *ebpf.Map `ebpf:"km_cluster"` - KmClusterEps *ebpf.Map `ebpf:"km_cluster_eps"` - KmClusterSock *ebpf.Map `ebpf:"km_cluster_sock"` - KmClusterstats *ebpf.Map `ebpf:"km_clusterstats"` - KmEpsData *ebpf.Map `ebpf:"km_eps_data"` - KmListener *ebpf.Map `ebpf:"km_listener"` - KmLogEvent *ebpf.Map `ebpf:"km_log_event"` - KmMaglevOuter *ebpf.Map `ebpf:"km_maglev_outer"` - KmManage *ebpf.Map `ebpf:"km_manage"` - KmRatelimit *ebpf.Map `ebpf:"km_ratelimit"` - KmSockstorage *ebpf.Map `ebpf:"km_sockstorage"` - KmTailcallCtx *ebpf.Map `ebpf:"km_tailcall_ctx"` - KmTmpbuf *ebpf.Map `ebpf:"km_tmpbuf"` - KmeshMap1600 *ebpf.Map `ebpf:"kmesh_map1600"` - KmeshMap192 *ebpf.Map `ebpf:"kmesh_map192"` - KmeshMap296 *ebpf.Map `ebpf:"kmesh_map296"` - KmeshMap64 *ebpf.Map `ebpf:"kmesh_map64"` -} - -func (m *KmeshCgroupSockMaps) Close() error { - return _KmeshCgroupSockClose( - m.KmCgrptailcall, - m.KmCluster, - m.KmClusterEps, - m.KmClusterSock, - m.KmClusterstats, - m.KmEpsData, - m.KmListener, - m.KmLogEvent, - m.KmMaglevOuter, - m.KmManage, - m.KmRatelimit, - m.KmSockstorage, - m.KmTailcallCtx, - m.KmTmpbuf, - m.KmeshMap1600, - m.KmeshMap192, - m.KmeshMap296, - m.KmeshMap64, - ) -} - -// KmeshCgroupSockVariables contains all global variables after they have been loaded into the kernel. -// -// It can be passed to LoadKmeshCgroupSockObjects or ebpf.CollectionSpec.LoadAndAssign. -type KmeshCgroupSockVariables struct { - BpfLogLevel *ebpf.Variable `ebpf:"bpf_log_level"` -} - -// KmeshCgroupSockPrograms contains all programs after they have been loaded into the kernel. -// -// It can be passed to LoadKmeshCgroupSockObjects or ebpf.CollectionSpec.LoadAndAssign. -type KmeshCgroupSockPrograms struct { - CgroupConnect4Prog *ebpf.Program `ebpf:"cgroup_connect4_prog"` - ClusterManager *ebpf.Program `ebpf:"cluster_manager"` - FilterChainManager *ebpf.Program `ebpf:"filter_chain_manager"` - FilterManager *ebpf.Program `ebpf:"filter_manager"` -} - -func (p *KmeshCgroupSockPrograms) Close() error { - return _KmeshCgroupSockClose( - p.CgroupConnect4Prog, - p.ClusterManager, - p.FilterChainManager, - p.FilterManager, - ) -} - -func _KmeshCgroupSockClose(closers ...io.Closer) error { - for _, closer := range closers { - if err := closer.Close(); err != nil { - return err - } - } - return nil -} - -// Do not access this directly. -// -//go:embed kmeshcgroupsock_bpfeb.o -var _KmeshCgroupSockBytes []byte diff --git a/bpf/kmesh/bpf2go/kernelnative/kmeshcgroupsock_bpfel.go b/bpf/kmesh/bpf2go/kernelnative/kmeshcgroupsock_bpfel.go deleted file mode 100644 index c318859f4..000000000 --- a/bpf/kmesh/bpf2go/kernelnative/kmeshcgroupsock_bpfel.go +++ /dev/null @@ -1,242 +0,0 @@ -// Code generated by bpf2go; DO NOT EDIT. -//go:build 386 || amd64 || arm || arm64 || loong64 || mips64le || mipsle || ppc64le || riscv64 - -package bpf2go - -import ( - "bytes" - _ "embed" - "fmt" - "io" - - "github.com/cilium/ebpf" -) - -type KmeshCgroupSockBuf struct{ Data [40]int8 } - -type KmeshCgroupSockClusterSockData struct{ ClusterId uint32 } - -type KmeshCgroupSockManagerKey struct { - NetnsCookie uint64 - _ [8]byte -} - -type KmeshCgroupSockRatelimitKey struct { - Key struct { - SkSkb struct { - Netns uint64 - Ipv4 uint32 - Port uint32 - Family uint32 - _ [4]byte - } - } -} - -type KmeshCgroupSockRatelimitValue struct { - LastTopup uint64 - Tokens uint64 -} - -type KmeshCgroupSockSockStorageData struct { - ConnectNs uint64 - LastReportNs uint64 - Direction uint8 - ConnectSuccess uint8 - ViaWaypoint bool - HasEncoded bool - HasSetIp bool - _ [3]byte - SkTuple struct { - Ipv4 struct { - Saddr uint32 - Daddr uint32 - Sport uint16 - Dport uint16 - } - _ [24]byte - } - _ [4]byte -} - -// LoadKmeshCgroupSock returns the embedded CollectionSpec for KmeshCgroupSock. -func LoadKmeshCgroupSock() (*ebpf.CollectionSpec, error) { - reader := bytes.NewReader(_KmeshCgroupSockBytes) - spec, err := ebpf.LoadCollectionSpecFromReader(reader) - if err != nil { - return nil, fmt.Errorf("can't load KmeshCgroupSock: %w", err) - } - - return spec, err -} - -// LoadKmeshCgroupSockObjects loads KmeshCgroupSock and converts it into a struct. -// -// The following types are suitable as obj argument: -// -// *KmeshCgroupSockObjects -// *KmeshCgroupSockPrograms -// *KmeshCgroupSockMaps -// -// See ebpf.CollectionSpec.LoadAndAssign documentation for details. -func LoadKmeshCgroupSockObjects(obj interface{}, opts *ebpf.CollectionOptions) error { - spec, err := LoadKmeshCgroupSock() - if err != nil { - return err - } - - return spec.LoadAndAssign(obj, opts) -} - -// KmeshCgroupSockSpecs contains maps and programs before they are loaded into the kernel. -// -// It can be passed ebpf.CollectionSpec.Assign. -type KmeshCgroupSockSpecs struct { - KmeshCgroupSockProgramSpecs - KmeshCgroupSockMapSpecs - KmeshCgroupSockVariableSpecs -} - -// KmeshCgroupSockProgramSpecs contains programs before they are loaded into the kernel. -// -// It can be passed ebpf.CollectionSpec.Assign. -type KmeshCgroupSockProgramSpecs struct { - CgroupConnect4Prog *ebpf.ProgramSpec `ebpf:"cgroup_connect4_prog"` - ClusterManager *ebpf.ProgramSpec `ebpf:"cluster_manager"` - FilterChainManager *ebpf.ProgramSpec `ebpf:"filter_chain_manager"` - FilterManager *ebpf.ProgramSpec `ebpf:"filter_manager"` -} - -// KmeshCgroupSockMapSpecs contains maps before they are loaded into the kernel. -// -// It can be passed ebpf.CollectionSpec.Assign. -type KmeshCgroupSockMapSpecs struct { - KmCgrptailcall *ebpf.MapSpec `ebpf:"km_cgrptailcall"` - KmCluster *ebpf.MapSpec `ebpf:"km_cluster"` - KmClusterEps *ebpf.MapSpec `ebpf:"km_cluster_eps"` - KmClusterSock *ebpf.MapSpec `ebpf:"km_cluster_sock"` - KmClusterstats *ebpf.MapSpec `ebpf:"km_clusterstats"` - KmEpsData *ebpf.MapSpec `ebpf:"km_eps_data"` - KmListener *ebpf.MapSpec `ebpf:"km_listener"` - KmLogEvent *ebpf.MapSpec `ebpf:"km_log_event"` - KmMaglevOuter *ebpf.MapSpec `ebpf:"km_maglev_outer"` - KmManage *ebpf.MapSpec `ebpf:"km_manage"` - KmRatelimit *ebpf.MapSpec `ebpf:"km_ratelimit"` - KmSockstorage *ebpf.MapSpec `ebpf:"km_sockstorage"` - KmTailcallCtx *ebpf.MapSpec `ebpf:"km_tailcall_ctx"` - KmTmpbuf *ebpf.MapSpec `ebpf:"km_tmpbuf"` - KmeshMap1600 *ebpf.MapSpec `ebpf:"kmesh_map1600"` - KmeshMap192 *ebpf.MapSpec `ebpf:"kmesh_map192"` - KmeshMap296 *ebpf.MapSpec `ebpf:"kmesh_map296"` - KmeshMap64 *ebpf.MapSpec `ebpf:"kmesh_map64"` -} - -// KmeshCgroupSockVariableSpecs contains global variables before they are loaded into the kernel. -// -// It can be passed ebpf.CollectionSpec.Assign. -type KmeshCgroupSockVariableSpecs struct { - BpfLogLevel *ebpf.VariableSpec `ebpf:"bpf_log_level"` -} - -// KmeshCgroupSockObjects contains all objects after they have been loaded into the kernel. -// -// It can be passed to LoadKmeshCgroupSockObjects or ebpf.CollectionSpec.LoadAndAssign. -type KmeshCgroupSockObjects struct { - KmeshCgroupSockPrograms - KmeshCgroupSockMaps - KmeshCgroupSockVariables -} - -func (o *KmeshCgroupSockObjects) Close() error { - return _KmeshCgroupSockClose( - &o.KmeshCgroupSockPrograms, - &o.KmeshCgroupSockMaps, - ) -} - -// KmeshCgroupSockMaps contains all maps after they have been loaded into the kernel. -// -// It can be passed to LoadKmeshCgroupSockObjects or ebpf.CollectionSpec.LoadAndAssign. -type KmeshCgroupSockMaps struct { - KmCgrptailcall *ebpf.Map `ebpf:"km_cgrptailcall"` - KmCluster *ebpf.Map `ebpf:"km_cluster"` - KmClusterEps *ebpf.Map `ebpf:"km_cluster_eps"` - KmClusterSock *ebpf.Map `ebpf:"km_cluster_sock"` - KmClusterstats *ebpf.Map `ebpf:"km_clusterstats"` - KmEpsData *ebpf.Map `ebpf:"km_eps_data"` - KmListener *ebpf.Map `ebpf:"km_listener"` - KmLogEvent *ebpf.Map `ebpf:"km_log_event"` - KmMaglevOuter *ebpf.Map `ebpf:"km_maglev_outer"` - KmManage *ebpf.Map `ebpf:"km_manage"` - KmRatelimit *ebpf.Map `ebpf:"km_ratelimit"` - KmSockstorage *ebpf.Map `ebpf:"km_sockstorage"` - KmTailcallCtx *ebpf.Map `ebpf:"km_tailcall_ctx"` - KmTmpbuf *ebpf.Map `ebpf:"km_tmpbuf"` - KmeshMap1600 *ebpf.Map `ebpf:"kmesh_map1600"` - KmeshMap192 *ebpf.Map `ebpf:"kmesh_map192"` - KmeshMap296 *ebpf.Map `ebpf:"kmesh_map296"` - KmeshMap64 *ebpf.Map `ebpf:"kmesh_map64"` -} - -func (m *KmeshCgroupSockMaps) Close() error { - return _KmeshCgroupSockClose( - m.KmCgrptailcall, - m.KmCluster, - m.KmClusterEps, - m.KmClusterSock, - m.KmClusterstats, - m.KmEpsData, - m.KmListener, - m.KmLogEvent, - m.KmMaglevOuter, - m.KmManage, - m.KmRatelimit, - m.KmSockstorage, - m.KmTailcallCtx, - m.KmTmpbuf, - m.KmeshMap1600, - m.KmeshMap192, - m.KmeshMap296, - m.KmeshMap64, - ) -} - -// KmeshCgroupSockVariables contains all global variables after they have been loaded into the kernel. -// -// It can be passed to LoadKmeshCgroupSockObjects or ebpf.CollectionSpec.LoadAndAssign. -type KmeshCgroupSockVariables struct { - BpfLogLevel *ebpf.Variable `ebpf:"bpf_log_level"` -} - -// KmeshCgroupSockPrograms contains all programs after they have been loaded into the kernel. -// -// It can be passed to LoadKmeshCgroupSockObjects or ebpf.CollectionSpec.LoadAndAssign. -type KmeshCgroupSockPrograms struct { - CgroupConnect4Prog *ebpf.Program `ebpf:"cgroup_connect4_prog"` - ClusterManager *ebpf.Program `ebpf:"cluster_manager"` - FilterChainManager *ebpf.Program `ebpf:"filter_chain_manager"` - FilterManager *ebpf.Program `ebpf:"filter_manager"` -} - -func (p *KmeshCgroupSockPrograms) Close() error { - return _KmeshCgroupSockClose( - p.CgroupConnect4Prog, - p.ClusterManager, - p.FilterChainManager, - p.FilterManager, - ) -} - -func _KmeshCgroupSockClose(closers ...io.Closer) error { - for _, closer := range closers { - if err := closer.Close(); err != nil { - return err - } - } - return nil -} - -// Do not access this directly. -// -//go:embed kmeshcgroupsock_bpfel.o -var _KmeshCgroupSockBytes []byte diff --git a/bpf/kmesh/bpf2go/kernelnative/kmeshcgroupsockcompat_bpfeb.go b/bpf/kmesh/bpf2go/kernelnative/kmeshcgroupsockcompat_bpfeb.go deleted file mode 100644 index 6400c64ef..000000000 --- a/bpf/kmesh/bpf2go/kernelnative/kmeshcgroupsockcompat_bpfeb.go +++ /dev/null @@ -1,242 +0,0 @@ -// Code generated by bpf2go; DO NOT EDIT. -//go:build mips || mips64 || ppc64 || s390x - -package bpf2go - -import ( - "bytes" - _ "embed" - "fmt" - "io" - - "github.com/cilium/ebpf" -) - -type KmeshCgroupSockCompatBuf struct{ Data [40]int8 } - -type KmeshCgroupSockCompatClusterSockData struct{ ClusterId uint32 } - -type KmeshCgroupSockCompatManagerKey struct { - NetnsCookie uint64 - _ [8]byte -} - -type KmeshCgroupSockCompatRatelimitKey struct { - Key struct { - SkSkb struct { - Netns uint64 - Ipv4 uint32 - Port uint32 - Family uint32 - _ [4]byte - } - } -} - -type KmeshCgroupSockCompatRatelimitValue struct { - LastTopup uint64 - Tokens uint64 -} - -type KmeshCgroupSockCompatSockStorageData struct { - ConnectNs uint64 - LastReportNs uint64 - Direction uint8 - ConnectSuccess uint8 - ViaWaypoint bool - HasEncoded bool - HasSetIp bool - _ [3]byte - SkTuple struct { - Ipv4 struct { - Saddr uint32 - Daddr uint32 - Sport uint16 - Dport uint16 - } - _ [24]byte - } - _ [4]byte -} - -// LoadKmeshCgroupSockCompat returns the embedded CollectionSpec for KmeshCgroupSockCompat. -func LoadKmeshCgroupSockCompat() (*ebpf.CollectionSpec, error) { - reader := bytes.NewReader(_KmeshCgroupSockCompatBytes) - spec, err := ebpf.LoadCollectionSpecFromReader(reader) - if err != nil { - return nil, fmt.Errorf("can't load KmeshCgroupSockCompat: %w", err) - } - - return spec, err -} - -// LoadKmeshCgroupSockCompatObjects loads KmeshCgroupSockCompat and converts it into a struct. -// -// The following types are suitable as obj argument: -// -// *KmeshCgroupSockCompatObjects -// *KmeshCgroupSockCompatPrograms -// *KmeshCgroupSockCompatMaps -// -// See ebpf.CollectionSpec.LoadAndAssign documentation for details. -func LoadKmeshCgroupSockCompatObjects(obj interface{}, opts *ebpf.CollectionOptions) error { - spec, err := LoadKmeshCgroupSockCompat() - if err != nil { - return err - } - - return spec.LoadAndAssign(obj, opts) -} - -// KmeshCgroupSockCompatSpecs contains maps and programs before they are loaded into the kernel. -// -// It can be passed ebpf.CollectionSpec.Assign. -type KmeshCgroupSockCompatSpecs struct { - KmeshCgroupSockCompatProgramSpecs - KmeshCgroupSockCompatMapSpecs - KmeshCgroupSockCompatVariableSpecs -} - -// KmeshCgroupSockCompatProgramSpecs contains programs before they are loaded into the kernel. -// -// It can be passed ebpf.CollectionSpec.Assign. -type KmeshCgroupSockCompatProgramSpecs struct { - CgroupConnect4Prog *ebpf.ProgramSpec `ebpf:"cgroup_connect4_prog"` - ClusterManager *ebpf.ProgramSpec `ebpf:"cluster_manager"` - FilterChainManager *ebpf.ProgramSpec `ebpf:"filter_chain_manager"` - FilterManager *ebpf.ProgramSpec `ebpf:"filter_manager"` -} - -// KmeshCgroupSockCompatMapSpecs contains maps before they are loaded into the kernel. -// -// It can be passed ebpf.CollectionSpec.Assign. -type KmeshCgroupSockCompatMapSpecs struct { - KmCgrptailcall *ebpf.MapSpec `ebpf:"km_cgrptailcall"` - KmCluster *ebpf.MapSpec `ebpf:"km_cluster"` - KmClusterEps *ebpf.MapSpec `ebpf:"km_cluster_eps"` - KmClusterSock *ebpf.MapSpec `ebpf:"km_cluster_sock"` - KmClusterstats *ebpf.MapSpec `ebpf:"km_clusterstats"` - KmEpsData *ebpf.MapSpec `ebpf:"km_eps_data"` - KmListener *ebpf.MapSpec `ebpf:"km_listener"` - KmLogEvent *ebpf.MapSpec `ebpf:"km_log_event"` - KmMaglevOuter *ebpf.MapSpec `ebpf:"km_maglev_outer"` - KmManage *ebpf.MapSpec `ebpf:"km_manage"` - KmRatelimit *ebpf.MapSpec `ebpf:"km_ratelimit"` - KmSockstorage *ebpf.MapSpec `ebpf:"km_sockstorage"` - KmTailcallCtx *ebpf.MapSpec `ebpf:"km_tailcall_ctx"` - KmTmpbuf *ebpf.MapSpec `ebpf:"km_tmpbuf"` - KmeshMap1600 *ebpf.MapSpec `ebpf:"kmesh_map1600"` - KmeshMap192 *ebpf.MapSpec `ebpf:"kmesh_map192"` - KmeshMap296 *ebpf.MapSpec `ebpf:"kmesh_map296"` - KmeshMap64 *ebpf.MapSpec `ebpf:"kmesh_map64"` -} - -// KmeshCgroupSockCompatVariableSpecs contains global variables before they are loaded into the kernel. -// -// It can be passed ebpf.CollectionSpec.Assign. -type KmeshCgroupSockCompatVariableSpecs struct { - BpfLogLevel *ebpf.VariableSpec `ebpf:"bpf_log_level"` -} - -// KmeshCgroupSockCompatObjects contains all objects after they have been loaded into the kernel. -// -// It can be passed to LoadKmeshCgroupSockCompatObjects or ebpf.CollectionSpec.LoadAndAssign. -type KmeshCgroupSockCompatObjects struct { - KmeshCgroupSockCompatPrograms - KmeshCgroupSockCompatMaps - KmeshCgroupSockCompatVariables -} - -func (o *KmeshCgroupSockCompatObjects) Close() error { - return _KmeshCgroupSockCompatClose( - &o.KmeshCgroupSockCompatPrograms, - &o.KmeshCgroupSockCompatMaps, - ) -} - -// KmeshCgroupSockCompatMaps contains all maps after they have been loaded into the kernel. -// -// It can be passed to LoadKmeshCgroupSockCompatObjects or ebpf.CollectionSpec.LoadAndAssign. -type KmeshCgroupSockCompatMaps struct { - KmCgrptailcall *ebpf.Map `ebpf:"km_cgrptailcall"` - KmCluster *ebpf.Map `ebpf:"km_cluster"` - KmClusterEps *ebpf.Map `ebpf:"km_cluster_eps"` - KmClusterSock *ebpf.Map `ebpf:"km_cluster_sock"` - KmClusterstats *ebpf.Map `ebpf:"km_clusterstats"` - KmEpsData *ebpf.Map `ebpf:"km_eps_data"` - KmListener *ebpf.Map `ebpf:"km_listener"` - KmLogEvent *ebpf.Map `ebpf:"km_log_event"` - KmMaglevOuter *ebpf.Map `ebpf:"km_maglev_outer"` - KmManage *ebpf.Map `ebpf:"km_manage"` - KmRatelimit *ebpf.Map `ebpf:"km_ratelimit"` - KmSockstorage *ebpf.Map `ebpf:"km_sockstorage"` - KmTailcallCtx *ebpf.Map `ebpf:"km_tailcall_ctx"` - KmTmpbuf *ebpf.Map `ebpf:"km_tmpbuf"` - KmeshMap1600 *ebpf.Map `ebpf:"kmesh_map1600"` - KmeshMap192 *ebpf.Map `ebpf:"kmesh_map192"` - KmeshMap296 *ebpf.Map `ebpf:"kmesh_map296"` - KmeshMap64 *ebpf.Map `ebpf:"kmesh_map64"` -} - -func (m *KmeshCgroupSockCompatMaps) Close() error { - return _KmeshCgroupSockCompatClose( - m.KmCgrptailcall, - m.KmCluster, - m.KmClusterEps, - m.KmClusterSock, - m.KmClusterstats, - m.KmEpsData, - m.KmListener, - m.KmLogEvent, - m.KmMaglevOuter, - m.KmManage, - m.KmRatelimit, - m.KmSockstorage, - m.KmTailcallCtx, - m.KmTmpbuf, - m.KmeshMap1600, - m.KmeshMap192, - m.KmeshMap296, - m.KmeshMap64, - ) -} - -// KmeshCgroupSockCompatVariables contains all global variables after they have been loaded into the kernel. -// -// It can be passed to LoadKmeshCgroupSockCompatObjects or ebpf.CollectionSpec.LoadAndAssign. -type KmeshCgroupSockCompatVariables struct { - BpfLogLevel *ebpf.Variable `ebpf:"bpf_log_level"` -} - -// KmeshCgroupSockCompatPrograms contains all programs after they have been loaded into the kernel. -// -// It can be passed to LoadKmeshCgroupSockCompatObjects or ebpf.CollectionSpec.LoadAndAssign. -type KmeshCgroupSockCompatPrograms struct { - CgroupConnect4Prog *ebpf.Program `ebpf:"cgroup_connect4_prog"` - ClusterManager *ebpf.Program `ebpf:"cluster_manager"` - FilterChainManager *ebpf.Program `ebpf:"filter_chain_manager"` - FilterManager *ebpf.Program `ebpf:"filter_manager"` -} - -func (p *KmeshCgroupSockCompatPrograms) Close() error { - return _KmeshCgroupSockCompatClose( - p.CgroupConnect4Prog, - p.ClusterManager, - p.FilterChainManager, - p.FilterManager, - ) -} - -func _KmeshCgroupSockCompatClose(closers ...io.Closer) error { - for _, closer := range closers { - if err := closer.Close(); err != nil { - return err - } - } - return nil -} - -// Do not access this directly. -// -//go:embed kmeshcgroupsockcompat_bpfeb.o -var _KmeshCgroupSockCompatBytes []byte diff --git a/bpf/kmesh/bpf2go/kernelnative/kmeshcgroupsockcompat_bpfel.go b/bpf/kmesh/bpf2go/kernelnative/kmeshcgroupsockcompat_bpfel.go deleted file mode 100644 index 2d40c5040..000000000 --- a/bpf/kmesh/bpf2go/kernelnative/kmeshcgroupsockcompat_bpfel.go +++ /dev/null @@ -1,242 +0,0 @@ -// Code generated by bpf2go; DO NOT EDIT. -//go:build 386 || amd64 || arm || arm64 || loong64 || mips64le || mipsle || ppc64le || riscv64 - -package bpf2go - -import ( - "bytes" - _ "embed" - "fmt" - "io" - - "github.com/cilium/ebpf" -) - -type KmeshCgroupSockCompatBuf struct{ Data [40]int8 } - -type KmeshCgroupSockCompatClusterSockData struct{ ClusterId uint32 } - -type KmeshCgroupSockCompatManagerKey struct { - NetnsCookie uint64 - _ [8]byte -} - -type KmeshCgroupSockCompatRatelimitKey struct { - Key struct { - SkSkb struct { - Netns uint64 - Ipv4 uint32 - Port uint32 - Family uint32 - _ [4]byte - } - } -} - -type KmeshCgroupSockCompatRatelimitValue struct { - LastTopup uint64 - Tokens uint64 -} - -type KmeshCgroupSockCompatSockStorageData struct { - ConnectNs uint64 - LastReportNs uint64 - Direction uint8 - ConnectSuccess uint8 - ViaWaypoint bool - HasEncoded bool - HasSetIp bool - _ [3]byte - SkTuple struct { - Ipv4 struct { - Saddr uint32 - Daddr uint32 - Sport uint16 - Dport uint16 - } - _ [24]byte - } - _ [4]byte -} - -// LoadKmeshCgroupSockCompat returns the embedded CollectionSpec for KmeshCgroupSockCompat. -func LoadKmeshCgroupSockCompat() (*ebpf.CollectionSpec, error) { - reader := bytes.NewReader(_KmeshCgroupSockCompatBytes) - spec, err := ebpf.LoadCollectionSpecFromReader(reader) - if err != nil { - return nil, fmt.Errorf("can't load KmeshCgroupSockCompat: %w", err) - } - - return spec, err -} - -// LoadKmeshCgroupSockCompatObjects loads KmeshCgroupSockCompat and converts it into a struct. -// -// The following types are suitable as obj argument: -// -// *KmeshCgroupSockCompatObjects -// *KmeshCgroupSockCompatPrograms -// *KmeshCgroupSockCompatMaps -// -// See ebpf.CollectionSpec.LoadAndAssign documentation for details. -func LoadKmeshCgroupSockCompatObjects(obj interface{}, opts *ebpf.CollectionOptions) error { - spec, err := LoadKmeshCgroupSockCompat() - if err != nil { - return err - } - - return spec.LoadAndAssign(obj, opts) -} - -// KmeshCgroupSockCompatSpecs contains maps and programs before they are loaded into the kernel. -// -// It can be passed ebpf.CollectionSpec.Assign. -type KmeshCgroupSockCompatSpecs struct { - KmeshCgroupSockCompatProgramSpecs - KmeshCgroupSockCompatMapSpecs - KmeshCgroupSockCompatVariableSpecs -} - -// KmeshCgroupSockCompatProgramSpecs contains programs before they are loaded into the kernel. -// -// It can be passed ebpf.CollectionSpec.Assign. -type KmeshCgroupSockCompatProgramSpecs struct { - CgroupConnect4Prog *ebpf.ProgramSpec `ebpf:"cgroup_connect4_prog"` - ClusterManager *ebpf.ProgramSpec `ebpf:"cluster_manager"` - FilterChainManager *ebpf.ProgramSpec `ebpf:"filter_chain_manager"` - FilterManager *ebpf.ProgramSpec `ebpf:"filter_manager"` -} - -// KmeshCgroupSockCompatMapSpecs contains maps before they are loaded into the kernel. -// -// It can be passed ebpf.CollectionSpec.Assign. -type KmeshCgroupSockCompatMapSpecs struct { - KmCgrptailcall *ebpf.MapSpec `ebpf:"km_cgrptailcall"` - KmCluster *ebpf.MapSpec `ebpf:"km_cluster"` - KmClusterEps *ebpf.MapSpec `ebpf:"km_cluster_eps"` - KmClusterSock *ebpf.MapSpec `ebpf:"km_cluster_sock"` - KmClusterstats *ebpf.MapSpec `ebpf:"km_clusterstats"` - KmEpsData *ebpf.MapSpec `ebpf:"km_eps_data"` - KmListener *ebpf.MapSpec `ebpf:"km_listener"` - KmLogEvent *ebpf.MapSpec `ebpf:"km_log_event"` - KmMaglevOuter *ebpf.MapSpec `ebpf:"km_maglev_outer"` - KmManage *ebpf.MapSpec `ebpf:"km_manage"` - KmRatelimit *ebpf.MapSpec `ebpf:"km_ratelimit"` - KmSockstorage *ebpf.MapSpec `ebpf:"km_sockstorage"` - KmTailcallCtx *ebpf.MapSpec `ebpf:"km_tailcall_ctx"` - KmTmpbuf *ebpf.MapSpec `ebpf:"km_tmpbuf"` - KmeshMap1600 *ebpf.MapSpec `ebpf:"kmesh_map1600"` - KmeshMap192 *ebpf.MapSpec `ebpf:"kmesh_map192"` - KmeshMap296 *ebpf.MapSpec `ebpf:"kmesh_map296"` - KmeshMap64 *ebpf.MapSpec `ebpf:"kmesh_map64"` -} - -// KmeshCgroupSockCompatVariableSpecs contains global variables before they are loaded into the kernel. -// -// It can be passed ebpf.CollectionSpec.Assign. -type KmeshCgroupSockCompatVariableSpecs struct { - BpfLogLevel *ebpf.VariableSpec `ebpf:"bpf_log_level"` -} - -// KmeshCgroupSockCompatObjects contains all objects after they have been loaded into the kernel. -// -// It can be passed to LoadKmeshCgroupSockCompatObjects or ebpf.CollectionSpec.LoadAndAssign. -type KmeshCgroupSockCompatObjects struct { - KmeshCgroupSockCompatPrograms - KmeshCgroupSockCompatMaps - KmeshCgroupSockCompatVariables -} - -func (o *KmeshCgroupSockCompatObjects) Close() error { - return _KmeshCgroupSockCompatClose( - &o.KmeshCgroupSockCompatPrograms, - &o.KmeshCgroupSockCompatMaps, - ) -} - -// KmeshCgroupSockCompatMaps contains all maps after they have been loaded into the kernel. -// -// It can be passed to LoadKmeshCgroupSockCompatObjects or ebpf.CollectionSpec.LoadAndAssign. -type KmeshCgroupSockCompatMaps struct { - KmCgrptailcall *ebpf.Map `ebpf:"km_cgrptailcall"` - KmCluster *ebpf.Map `ebpf:"km_cluster"` - KmClusterEps *ebpf.Map `ebpf:"km_cluster_eps"` - KmClusterSock *ebpf.Map `ebpf:"km_cluster_sock"` - KmClusterstats *ebpf.Map `ebpf:"km_clusterstats"` - KmEpsData *ebpf.Map `ebpf:"km_eps_data"` - KmListener *ebpf.Map `ebpf:"km_listener"` - KmLogEvent *ebpf.Map `ebpf:"km_log_event"` - KmMaglevOuter *ebpf.Map `ebpf:"km_maglev_outer"` - KmManage *ebpf.Map `ebpf:"km_manage"` - KmRatelimit *ebpf.Map `ebpf:"km_ratelimit"` - KmSockstorage *ebpf.Map `ebpf:"km_sockstorage"` - KmTailcallCtx *ebpf.Map `ebpf:"km_tailcall_ctx"` - KmTmpbuf *ebpf.Map `ebpf:"km_tmpbuf"` - KmeshMap1600 *ebpf.Map `ebpf:"kmesh_map1600"` - KmeshMap192 *ebpf.Map `ebpf:"kmesh_map192"` - KmeshMap296 *ebpf.Map `ebpf:"kmesh_map296"` - KmeshMap64 *ebpf.Map `ebpf:"kmesh_map64"` -} - -func (m *KmeshCgroupSockCompatMaps) Close() error { - return _KmeshCgroupSockCompatClose( - m.KmCgrptailcall, - m.KmCluster, - m.KmClusterEps, - m.KmClusterSock, - m.KmClusterstats, - m.KmEpsData, - m.KmListener, - m.KmLogEvent, - m.KmMaglevOuter, - m.KmManage, - m.KmRatelimit, - m.KmSockstorage, - m.KmTailcallCtx, - m.KmTmpbuf, - m.KmeshMap1600, - m.KmeshMap192, - m.KmeshMap296, - m.KmeshMap64, - ) -} - -// KmeshCgroupSockCompatVariables contains all global variables after they have been loaded into the kernel. -// -// It can be passed to LoadKmeshCgroupSockCompatObjects or ebpf.CollectionSpec.LoadAndAssign. -type KmeshCgroupSockCompatVariables struct { - BpfLogLevel *ebpf.Variable `ebpf:"bpf_log_level"` -} - -// KmeshCgroupSockCompatPrograms contains all programs after they have been loaded into the kernel. -// -// It can be passed to LoadKmeshCgroupSockCompatObjects or ebpf.CollectionSpec.LoadAndAssign. -type KmeshCgroupSockCompatPrograms struct { - CgroupConnect4Prog *ebpf.Program `ebpf:"cgroup_connect4_prog"` - ClusterManager *ebpf.Program `ebpf:"cluster_manager"` - FilterChainManager *ebpf.Program `ebpf:"filter_chain_manager"` - FilterManager *ebpf.Program `ebpf:"filter_manager"` -} - -func (p *KmeshCgroupSockCompatPrograms) Close() error { - return _KmeshCgroupSockCompatClose( - p.CgroupConnect4Prog, - p.ClusterManager, - p.FilterChainManager, - p.FilterManager, - ) -} - -func _KmeshCgroupSockCompatClose(closers ...io.Closer) error { - for _, closer := range closers { - if err := closer.Close(); err != nil { - return err - } - } - return nil -} - -// Do not access this directly. -// -//go:embed kmeshcgroupsockcompat_bpfel.o -var _KmeshCgroupSockCompatBytes []byte diff --git a/bpf/kmesh/bpf2go/kernelnative/kmeshsockops_bpfeb.go b/bpf/kmesh/bpf2go/kernelnative/kmeshsockops_bpfeb.go deleted file mode 100644 index 84bbb6cc8..000000000 --- a/bpf/kmesh/bpf2go/kernelnative/kmeshsockops_bpfeb.go +++ /dev/null @@ -1,192 +0,0 @@ -// Code generated by bpf2go; DO NOT EDIT. -//go:build mips || mips64 || ppc64 || s390x - -package bpf2go - -import ( - "bytes" - _ "embed" - "fmt" - "io" - - "github.com/cilium/ebpf" -) - -type KmeshSockopsBuf struct{ Data [40]int8 } - -type KmeshSockopsClusterSockData struct{ ClusterId uint32 } - -type KmeshSockopsManagerKey struct { - NetnsCookie uint64 - _ [8]byte -} - -type KmeshSockopsSockStorageData struct { - ConnectNs uint64 - LastReportNs uint64 - Direction uint8 - ConnectSuccess uint8 - ViaWaypoint bool - HasEncoded bool - HasSetIp bool - _ [3]byte - SkTuple struct { - Ipv4 struct { - Saddr uint32 - Daddr uint32 - Sport uint16 - Dport uint16 - } - _ [24]byte - } - _ [4]byte -} - -// LoadKmeshSockops returns the embedded CollectionSpec for KmeshSockops. -func LoadKmeshSockops() (*ebpf.CollectionSpec, error) { - reader := bytes.NewReader(_KmeshSockopsBytes) - spec, err := ebpf.LoadCollectionSpecFromReader(reader) - if err != nil { - return nil, fmt.Errorf("can't load KmeshSockops: %w", err) - } - - return spec, err -} - -// LoadKmeshSockopsObjects loads KmeshSockops and converts it into a struct. -// -// The following types are suitable as obj argument: -// -// *KmeshSockopsObjects -// *KmeshSockopsPrograms -// *KmeshSockopsMaps -// -// See ebpf.CollectionSpec.LoadAndAssign documentation for details. -func LoadKmeshSockopsObjects(obj interface{}, opts *ebpf.CollectionOptions) error { - spec, err := LoadKmeshSockops() - if err != nil { - return err - } - - return spec.LoadAndAssign(obj, opts) -} - -// KmeshSockopsSpecs contains maps and programs before they are loaded into the kernel. -// -// It can be passed ebpf.CollectionSpec.Assign. -type KmeshSockopsSpecs struct { - KmeshSockopsProgramSpecs - KmeshSockopsMapSpecs - KmeshSockopsVariableSpecs -} - -// KmeshSockopsProgramSpecs contains programs before they are loaded into the kernel. -// -// It can be passed ebpf.CollectionSpec.Assign. -type KmeshSockopsProgramSpecs struct { - SockopsProg *ebpf.ProgramSpec `ebpf:"sockops_prog"` -} - -// KmeshSockopsMapSpecs contains maps before they are loaded into the kernel. -// -// It can be passed ebpf.CollectionSpec.Assign. -type KmeshSockopsMapSpecs struct { - KmClusterSock *ebpf.MapSpec `ebpf:"km_cluster_sock"` - KmClusterstats *ebpf.MapSpec `ebpf:"km_clusterstats"` - KmLogEvent *ebpf.MapSpec `ebpf:"km_log_event"` - KmManage *ebpf.MapSpec `ebpf:"km_manage"` - KmSockstorage *ebpf.MapSpec `ebpf:"km_sockstorage"` - KmTmpbuf *ebpf.MapSpec `ebpf:"km_tmpbuf"` - KmeshMap1600 *ebpf.MapSpec `ebpf:"kmesh_map1600"` - KmeshMap192 *ebpf.MapSpec `ebpf:"kmesh_map192"` - KmeshMap296 *ebpf.MapSpec `ebpf:"kmesh_map296"` - KmeshMap64 *ebpf.MapSpec `ebpf:"kmesh_map64"` -} - -// KmeshSockopsVariableSpecs contains global variables before they are loaded into the kernel. -// -// It can be passed ebpf.CollectionSpec.Assign. -type KmeshSockopsVariableSpecs struct { - BpfLogLevel *ebpf.VariableSpec `ebpf:"bpf_log_level"` -} - -// KmeshSockopsObjects contains all objects after they have been loaded into the kernel. -// -// It can be passed to LoadKmeshSockopsObjects or ebpf.CollectionSpec.LoadAndAssign. -type KmeshSockopsObjects struct { - KmeshSockopsPrograms - KmeshSockopsMaps - KmeshSockopsVariables -} - -func (o *KmeshSockopsObjects) Close() error { - return _KmeshSockopsClose( - &o.KmeshSockopsPrograms, - &o.KmeshSockopsMaps, - ) -} - -// KmeshSockopsMaps contains all maps after they have been loaded into the kernel. -// -// It can be passed to LoadKmeshSockopsObjects or ebpf.CollectionSpec.LoadAndAssign. -type KmeshSockopsMaps struct { - KmClusterSock *ebpf.Map `ebpf:"km_cluster_sock"` - KmClusterstats *ebpf.Map `ebpf:"km_clusterstats"` - KmLogEvent *ebpf.Map `ebpf:"km_log_event"` - KmManage *ebpf.Map `ebpf:"km_manage"` - KmSockstorage *ebpf.Map `ebpf:"km_sockstorage"` - KmTmpbuf *ebpf.Map `ebpf:"km_tmpbuf"` - KmeshMap1600 *ebpf.Map `ebpf:"kmesh_map1600"` - KmeshMap192 *ebpf.Map `ebpf:"kmesh_map192"` - KmeshMap296 *ebpf.Map `ebpf:"kmesh_map296"` - KmeshMap64 *ebpf.Map `ebpf:"kmesh_map64"` -} - -func (m *KmeshSockopsMaps) Close() error { - return _KmeshSockopsClose( - m.KmClusterSock, - m.KmClusterstats, - m.KmLogEvent, - m.KmManage, - m.KmSockstorage, - m.KmTmpbuf, - m.KmeshMap1600, - m.KmeshMap192, - m.KmeshMap296, - m.KmeshMap64, - ) -} - -// KmeshSockopsVariables contains all global variables after they have been loaded into the kernel. -// -// It can be passed to LoadKmeshSockopsObjects or ebpf.CollectionSpec.LoadAndAssign. -type KmeshSockopsVariables struct { - BpfLogLevel *ebpf.Variable `ebpf:"bpf_log_level"` -} - -// KmeshSockopsPrograms contains all programs after they have been loaded into the kernel. -// -// It can be passed to LoadKmeshSockopsObjects or ebpf.CollectionSpec.LoadAndAssign. -type KmeshSockopsPrograms struct { - SockopsProg *ebpf.Program `ebpf:"sockops_prog"` -} - -func (p *KmeshSockopsPrograms) Close() error { - return _KmeshSockopsClose( - p.SockopsProg, - ) -} - -func _KmeshSockopsClose(closers ...io.Closer) error { - for _, closer := range closers { - if err := closer.Close(); err != nil { - return err - } - } - return nil -} - -// Do not access this directly. -// -//go:embed kmeshsockops_bpfeb.o -var _KmeshSockopsBytes []byte diff --git a/bpf/kmesh/bpf2go/kernelnative/kmeshsockops_bpfel.go b/bpf/kmesh/bpf2go/kernelnative/kmeshsockops_bpfel.go deleted file mode 100644 index 8db351f13..000000000 --- a/bpf/kmesh/bpf2go/kernelnative/kmeshsockops_bpfel.go +++ /dev/null @@ -1,192 +0,0 @@ -// Code generated by bpf2go; DO NOT EDIT. -//go:build 386 || amd64 || arm || arm64 || loong64 || mips64le || mipsle || ppc64le || riscv64 - -package bpf2go - -import ( - "bytes" - _ "embed" - "fmt" - "io" - - "github.com/cilium/ebpf" -) - -type KmeshSockopsBuf struct{ Data [40]int8 } - -type KmeshSockopsClusterSockData struct{ ClusterId uint32 } - -type KmeshSockopsManagerKey struct { - NetnsCookie uint64 - _ [8]byte -} - -type KmeshSockopsSockStorageData struct { - ConnectNs uint64 - LastReportNs uint64 - Direction uint8 - ConnectSuccess uint8 - ViaWaypoint bool - HasEncoded bool - HasSetIp bool - _ [3]byte - SkTuple struct { - Ipv4 struct { - Saddr uint32 - Daddr uint32 - Sport uint16 - Dport uint16 - } - _ [24]byte - } - _ [4]byte -} - -// LoadKmeshSockops returns the embedded CollectionSpec for KmeshSockops. -func LoadKmeshSockops() (*ebpf.CollectionSpec, error) { - reader := bytes.NewReader(_KmeshSockopsBytes) - spec, err := ebpf.LoadCollectionSpecFromReader(reader) - if err != nil { - return nil, fmt.Errorf("can't load KmeshSockops: %w", err) - } - - return spec, err -} - -// LoadKmeshSockopsObjects loads KmeshSockops and converts it into a struct. -// -// The following types are suitable as obj argument: -// -// *KmeshSockopsObjects -// *KmeshSockopsPrograms -// *KmeshSockopsMaps -// -// See ebpf.CollectionSpec.LoadAndAssign documentation for details. -func LoadKmeshSockopsObjects(obj interface{}, opts *ebpf.CollectionOptions) error { - spec, err := LoadKmeshSockops() - if err != nil { - return err - } - - return spec.LoadAndAssign(obj, opts) -} - -// KmeshSockopsSpecs contains maps and programs before they are loaded into the kernel. -// -// It can be passed ebpf.CollectionSpec.Assign. -type KmeshSockopsSpecs struct { - KmeshSockopsProgramSpecs - KmeshSockopsMapSpecs - KmeshSockopsVariableSpecs -} - -// KmeshSockopsProgramSpecs contains programs before they are loaded into the kernel. -// -// It can be passed ebpf.CollectionSpec.Assign. -type KmeshSockopsProgramSpecs struct { - SockopsProg *ebpf.ProgramSpec `ebpf:"sockops_prog"` -} - -// KmeshSockopsMapSpecs contains maps before they are loaded into the kernel. -// -// It can be passed ebpf.CollectionSpec.Assign. -type KmeshSockopsMapSpecs struct { - KmClusterSock *ebpf.MapSpec `ebpf:"km_cluster_sock"` - KmClusterstats *ebpf.MapSpec `ebpf:"km_clusterstats"` - KmLogEvent *ebpf.MapSpec `ebpf:"km_log_event"` - KmManage *ebpf.MapSpec `ebpf:"km_manage"` - KmSockstorage *ebpf.MapSpec `ebpf:"km_sockstorage"` - KmTmpbuf *ebpf.MapSpec `ebpf:"km_tmpbuf"` - KmeshMap1600 *ebpf.MapSpec `ebpf:"kmesh_map1600"` - KmeshMap192 *ebpf.MapSpec `ebpf:"kmesh_map192"` - KmeshMap296 *ebpf.MapSpec `ebpf:"kmesh_map296"` - KmeshMap64 *ebpf.MapSpec `ebpf:"kmesh_map64"` -} - -// KmeshSockopsVariableSpecs contains global variables before they are loaded into the kernel. -// -// It can be passed ebpf.CollectionSpec.Assign. -type KmeshSockopsVariableSpecs struct { - BpfLogLevel *ebpf.VariableSpec `ebpf:"bpf_log_level"` -} - -// KmeshSockopsObjects contains all objects after they have been loaded into the kernel. -// -// It can be passed to LoadKmeshSockopsObjects or ebpf.CollectionSpec.LoadAndAssign. -type KmeshSockopsObjects struct { - KmeshSockopsPrograms - KmeshSockopsMaps - KmeshSockopsVariables -} - -func (o *KmeshSockopsObjects) Close() error { - return _KmeshSockopsClose( - &o.KmeshSockopsPrograms, - &o.KmeshSockopsMaps, - ) -} - -// KmeshSockopsMaps contains all maps after they have been loaded into the kernel. -// -// It can be passed to LoadKmeshSockopsObjects or ebpf.CollectionSpec.LoadAndAssign. -type KmeshSockopsMaps struct { - KmClusterSock *ebpf.Map `ebpf:"km_cluster_sock"` - KmClusterstats *ebpf.Map `ebpf:"km_clusterstats"` - KmLogEvent *ebpf.Map `ebpf:"km_log_event"` - KmManage *ebpf.Map `ebpf:"km_manage"` - KmSockstorage *ebpf.Map `ebpf:"km_sockstorage"` - KmTmpbuf *ebpf.Map `ebpf:"km_tmpbuf"` - KmeshMap1600 *ebpf.Map `ebpf:"kmesh_map1600"` - KmeshMap192 *ebpf.Map `ebpf:"kmesh_map192"` - KmeshMap296 *ebpf.Map `ebpf:"kmesh_map296"` - KmeshMap64 *ebpf.Map `ebpf:"kmesh_map64"` -} - -func (m *KmeshSockopsMaps) Close() error { - return _KmeshSockopsClose( - m.KmClusterSock, - m.KmClusterstats, - m.KmLogEvent, - m.KmManage, - m.KmSockstorage, - m.KmTmpbuf, - m.KmeshMap1600, - m.KmeshMap192, - m.KmeshMap296, - m.KmeshMap64, - ) -} - -// KmeshSockopsVariables contains all global variables after they have been loaded into the kernel. -// -// It can be passed to LoadKmeshSockopsObjects or ebpf.CollectionSpec.LoadAndAssign. -type KmeshSockopsVariables struct { - BpfLogLevel *ebpf.Variable `ebpf:"bpf_log_level"` -} - -// KmeshSockopsPrograms contains all programs after they have been loaded into the kernel. -// -// It can be passed to LoadKmeshSockopsObjects or ebpf.CollectionSpec.LoadAndAssign. -type KmeshSockopsPrograms struct { - SockopsProg *ebpf.Program `ebpf:"sockops_prog"` -} - -func (p *KmeshSockopsPrograms) Close() error { - return _KmeshSockopsClose( - p.SockopsProg, - ) -} - -func _KmeshSockopsClose(closers ...io.Closer) error { - for _, closer := range closers { - if err := closer.Close(); err != nil { - return err - } - } - return nil -} - -// Do not access this directly. -// -//go:embed kmeshsockops_bpfel.o -var _KmeshSockopsBytes []byte diff --git a/bpf/kmesh/bpf2go/kernelnative/kmeshsockopscompat_bpfeb.go b/bpf/kmesh/bpf2go/kernelnative/kmeshsockopscompat_bpfeb.go deleted file mode 100644 index 066bab11e..000000000 --- a/bpf/kmesh/bpf2go/kernelnative/kmeshsockopscompat_bpfeb.go +++ /dev/null @@ -1,192 +0,0 @@ -// Code generated by bpf2go; DO NOT EDIT. -//go:build mips || mips64 || ppc64 || s390x - -package bpf2go - -import ( - "bytes" - _ "embed" - "fmt" - "io" - - "github.com/cilium/ebpf" -) - -type KmeshSockopsCompatBuf struct{ Data [40]int8 } - -type KmeshSockopsCompatClusterSockData struct{ ClusterId uint32 } - -type KmeshSockopsCompatManagerKey struct { - NetnsCookie uint64 - _ [8]byte -} - -type KmeshSockopsCompatSockStorageData struct { - ConnectNs uint64 - LastReportNs uint64 - Direction uint8 - ConnectSuccess uint8 - ViaWaypoint bool - HasEncoded bool - HasSetIp bool - _ [3]byte - SkTuple struct { - Ipv4 struct { - Saddr uint32 - Daddr uint32 - Sport uint16 - Dport uint16 - } - _ [24]byte - } - _ [4]byte -} - -// LoadKmeshSockopsCompat returns the embedded CollectionSpec for KmeshSockopsCompat. -func LoadKmeshSockopsCompat() (*ebpf.CollectionSpec, error) { - reader := bytes.NewReader(_KmeshSockopsCompatBytes) - spec, err := ebpf.LoadCollectionSpecFromReader(reader) - if err != nil { - return nil, fmt.Errorf("can't load KmeshSockopsCompat: %w", err) - } - - return spec, err -} - -// LoadKmeshSockopsCompatObjects loads KmeshSockopsCompat and converts it into a struct. -// -// The following types are suitable as obj argument: -// -// *KmeshSockopsCompatObjects -// *KmeshSockopsCompatPrograms -// *KmeshSockopsCompatMaps -// -// See ebpf.CollectionSpec.LoadAndAssign documentation for details. -func LoadKmeshSockopsCompatObjects(obj interface{}, opts *ebpf.CollectionOptions) error { - spec, err := LoadKmeshSockopsCompat() - if err != nil { - return err - } - - return spec.LoadAndAssign(obj, opts) -} - -// KmeshSockopsCompatSpecs contains maps and programs before they are loaded into the kernel. -// -// It can be passed ebpf.CollectionSpec.Assign. -type KmeshSockopsCompatSpecs struct { - KmeshSockopsCompatProgramSpecs - KmeshSockopsCompatMapSpecs - KmeshSockopsCompatVariableSpecs -} - -// KmeshSockopsCompatProgramSpecs contains programs before they are loaded into the kernel. -// -// It can be passed ebpf.CollectionSpec.Assign. -type KmeshSockopsCompatProgramSpecs struct { - SockopsProg *ebpf.ProgramSpec `ebpf:"sockops_prog"` -} - -// KmeshSockopsCompatMapSpecs contains maps before they are loaded into the kernel. -// -// It can be passed ebpf.CollectionSpec.Assign. -type KmeshSockopsCompatMapSpecs struct { - KmClusterSock *ebpf.MapSpec `ebpf:"km_cluster_sock"` - KmClusterstats *ebpf.MapSpec `ebpf:"km_clusterstats"` - KmLogEvent *ebpf.MapSpec `ebpf:"km_log_event"` - KmManage *ebpf.MapSpec `ebpf:"km_manage"` - KmSockstorage *ebpf.MapSpec `ebpf:"km_sockstorage"` - KmTmpbuf *ebpf.MapSpec `ebpf:"km_tmpbuf"` - KmeshMap1600 *ebpf.MapSpec `ebpf:"kmesh_map1600"` - KmeshMap192 *ebpf.MapSpec `ebpf:"kmesh_map192"` - KmeshMap296 *ebpf.MapSpec `ebpf:"kmesh_map296"` - KmeshMap64 *ebpf.MapSpec `ebpf:"kmesh_map64"` -} - -// KmeshSockopsCompatVariableSpecs contains global variables before they are loaded into the kernel. -// -// It can be passed ebpf.CollectionSpec.Assign. -type KmeshSockopsCompatVariableSpecs struct { - BpfLogLevel *ebpf.VariableSpec `ebpf:"bpf_log_level"` -} - -// KmeshSockopsCompatObjects contains all objects after they have been loaded into the kernel. -// -// It can be passed to LoadKmeshSockopsCompatObjects or ebpf.CollectionSpec.LoadAndAssign. -type KmeshSockopsCompatObjects struct { - KmeshSockopsCompatPrograms - KmeshSockopsCompatMaps - KmeshSockopsCompatVariables -} - -func (o *KmeshSockopsCompatObjects) Close() error { - return _KmeshSockopsCompatClose( - &o.KmeshSockopsCompatPrograms, - &o.KmeshSockopsCompatMaps, - ) -} - -// KmeshSockopsCompatMaps contains all maps after they have been loaded into the kernel. -// -// It can be passed to LoadKmeshSockopsCompatObjects or ebpf.CollectionSpec.LoadAndAssign. -type KmeshSockopsCompatMaps struct { - KmClusterSock *ebpf.Map `ebpf:"km_cluster_sock"` - KmClusterstats *ebpf.Map `ebpf:"km_clusterstats"` - KmLogEvent *ebpf.Map `ebpf:"km_log_event"` - KmManage *ebpf.Map `ebpf:"km_manage"` - KmSockstorage *ebpf.Map `ebpf:"km_sockstorage"` - KmTmpbuf *ebpf.Map `ebpf:"km_tmpbuf"` - KmeshMap1600 *ebpf.Map `ebpf:"kmesh_map1600"` - KmeshMap192 *ebpf.Map `ebpf:"kmesh_map192"` - KmeshMap296 *ebpf.Map `ebpf:"kmesh_map296"` - KmeshMap64 *ebpf.Map `ebpf:"kmesh_map64"` -} - -func (m *KmeshSockopsCompatMaps) Close() error { - return _KmeshSockopsCompatClose( - m.KmClusterSock, - m.KmClusterstats, - m.KmLogEvent, - m.KmManage, - m.KmSockstorage, - m.KmTmpbuf, - m.KmeshMap1600, - m.KmeshMap192, - m.KmeshMap296, - m.KmeshMap64, - ) -} - -// KmeshSockopsCompatVariables contains all global variables after they have been loaded into the kernel. -// -// It can be passed to LoadKmeshSockopsCompatObjects or ebpf.CollectionSpec.LoadAndAssign. -type KmeshSockopsCompatVariables struct { - BpfLogLevel *ebpf.Variable `ebpf:"bpf_log_level"` -} - -// KmeshSockopsCompatPrograms contains all programs after they have been loaded into the kernel. -// -// It can be passed to LoadKmeshSockopsCompatObjects or ebpf.CollectionSpec.LoadAndAssign. -type KmeshSockopsCompatPrograms struct { - SockopsProg *ebpf.Program `ebpf:"sockops_prog"` -} - -func (p *KmeshSockopsCompatPrograms) Close() error { - return _KmeshSockopsCompatClose( - p.SockopsProg, - ) -} - -func _KmeshSockopsCompatClose(closers ...io.Closer) error { - for _, closer := range closers { - if err := closer.Close(); err != nil { - return err - } - } - return nil -} - -// Do not access this directly. -// -//go:embed kmeshsockopscompat_bpfeb.o -var _KmeshSockopsCompatBytes []byte diff --git a/bpf/kmesh/bpf2go/kernelnative/kmeshsockopscompat_bpfel.go b/bpf/kmesh/bpf2go/kernelnative/kmeshsockopscompat_bpfel.go deleted file mode 100644 index 6a07cdbef..000000000 --- a/bpf/kmesh/bpf2go/kernelnative/kmeshsockopscompat_bpfel.go +++ /dev/null @@ -1,192 +0,0 @@ -// Code generated by bpf2go; DO NOT EDIT. -//go:build 386 || amd64 || arm || arm64 || loong64 || mips64le || mipsle || ppc64le || riscv64 - -package bpf2go - -import ( - "bytes" - _ "embed" - "fmt" - "io" - - "github.com/cilium/ebpf" -) - -type KmeshSockopsCompatBuf struct{ Data [40]int8 } - -type KmeshSockopsCompatClusterSockData struct{ ClusterId uint32 } - -type KmeshSockopsCompatManagerKey struct { - NetnsCookie uint64 - _ [8]byte -} - -type KmeshSockopsCompatSockStorageData struct { - ConnectNs uint64 - LastReportNs uint64 - Direction uint8 - ConnectSuccess uint8 - ViaWaypoint bool - HasEncoded bool - HasSetIp bool - _ [3]byte - SkTuple struct { - Ipv4 struct { - Saddr uint32 - Daddr uint32 - Sport uint16 - Dport uint16 - } - _ [24]byte - } - _ [4]byte -} - -// LoadKmeshSockopsCompat returns the embedded CollectionSpec for KmeshSockopsCompat. -func LoadKmeshSockopsCompat() (*ebpf.CollectionSpec, error) { - reader := bytes.NewReader(_KmeshSockopsCompatBytes) - spec, err := ebpf.LoadCollectionSpecFromReader(reader) - if err != nil { - return nil, fmt.Errorf("can't load KmeshSockopsCompat: %w", err) - } - - return spec, err -} - -// LoadKmeshSockopsCompatObjects loads KmeshSockopsCompat and converts it into a struct. -// -// The following types are suitable as obj argument: -// -// *KmeshSockopsCompatObjects -// *KmeshSockopsCompatPrograms -// *KmeshSockopsCompatMaps -// -// See ebpf.CollectionSpec.LoadAndAssign documentation for details. -func LoadKmeshSockopsCompatObjects(obj interface{}, opts *ebpf.CollectionOptions) error { - spec, err := LoadKmeshSockopsCompat() - if err != nil { - return err - } - - return spec.LoadAndAssign(obj, opts) -} - -// KmeshSockopsCompatSpecs contains maps and programs before they are loaded into the kernel. -// -// It can be passed ebpf.CollectionSpec.Assign. -type KmeshSockopsCompatSpecs struct { - KmeshSockopsCompatProgramSpecs - KmeshSockopsCompatMapSpecs - KmeshSockopsCompatVariableSpecs -} - -// KmeshSockopsCompatProgramSpecs contains programs before they are loaded into the kernel. -// -// It can be passed ebpf.CollectionSpec.Assign. -type KmeshSockopsCompatProgramSpecs struct { - SockopsProg *ebpf.ProgramSpec `ebpf:"sockops_prog"` -} - -// KmeshSockopsCompatMapSpecs contains maps before they are loaded into the kernel. -// -// It can be passed ebpf.CollectionSpec.Assign. -type KmeshSockopsCompatMapSpecs struct { - KmClusterSock *ebpf.MapSpec `ebpf:"km_cluster_sock"` - KmClusterstats *ebpf.MapSpec `ebpf:"km_clusterstats"` - KmLogEvent *ebpf.MapSpec `ebpf:"km_log_event"` - KmManage *ebpf.MapSpec `ebpf:"km_manage"` - KmSockstorage *ebpf.MapSpec `ebpf:"km_sockstorage"` - KmTmpbuf *ebpf.MapSpec `ebpf:"km_tmpbuf"` - KmeshMap1600 *ebpf.MapSpec `ebpf:"kmesh_map1600"` - KmeshMap192 *ebpf.MapSpec `ebpf:"kmesh_map192"` - KmeshMap296 *ebpf.MapSpec `ebpf:"kmesh_map296"` - KmeshMap64 *ebpf.MapSpec `ebpf:"kmesh_map64"` -} - -// KmeshSockopsCompatVariableSpecs contains global variables before they are loaded into the kernel. -// -// It can be passed ebpf.CollectionSpec.Assign. -type KmeshSockopsCompatVariableSpecs struct { - BpfLogLevel *ebpf.VariableSpec `ebpf:"bpf_log_level"` -} - -// KmeshSockopsCompatObjects contains all objects after they have been loaded into the kernel. -// -// It can be passed to LoadKmeshSockopsCompatObjects or ebpf.CollectionSpec.LoadAndAssign. -type KmeshSockopsCompatObjects struct { - KmeshSockopsCompatPrograms - KmeshSockopsCompatMaps - KmeshSockopsCompatVariables -} - -func (o *KmeshSockopsCompatObjects) Close() error { - return _KmeshSockopsCompatClose( - &o.KmeshSockopsCompatPrograms, - &o.KmeshSockopsCompatMaps, - ) -} - -// KmeshSockopsCompatMaps contains all maps after they have been loaded into the kernel. -// -// It can be passed to LoadKmeshSockopsCompatObjects or ebpf.CollectionSpec.LoadAndAssign. -type KmeshSockopsCompatMaps struct { - KmClusterSock *ebpf.Map `ebpf:"km_cluster_sock"` - KmClusterstats *ebpf.Map `ebpf:"km_clusterstats"` - KmLogEvent *ebpf.Map `ebpf:"km_log_event"` - KmManage *ebpf.Map `ebpf:"km_manage"` - KmSockstorage *ebpf.Map `ebpf:"km_sockstorage"` - KmTmpbuf *ebpf.Map `ebpf:"km_tmpbuf"` - KmeshMap1600 *ebpf.Map `ebpf:"kmesh_map1600"` - KmeshMap192 *ebpf.Map `ebpf:"kmesh_map192"` - KmeshMap296 *ebpf.Map `ebpf:"kmesh_map296"` - KmeshMap64 *ebpf.Map `ebpf:"kmesh_map64"` -} - -func (m *KmeshSockopsCompatMaps) Close() error { - return _KmeshSockopsCompatClose( - m.KmClusterSock, - m.KmClusterstats, - m.KmLogEvent, - m.KmManage, - m.KmSockstorage, - m.KmTmpbuf, - m.KmeshMap1600, - m.KmeshMap192, - m.KmeshMap296, - m.KmeshMap64, - ) -} - -// KmeshSockopsCompatVariables contains all global variables after they have been loaded into the kernel. -// -// It can be passed to LoadKmeshSockopsCompatObjects or ebpf.CollectionSpec.LoadAndAssign. -type KmeshSockopsCompatVariables struct { - BpfLogLevel *ebpf.Variable `ebpf:"bpf_log_level"` -} - -// KmeshSockopsCompatPrograms contains all programs after they have been loaded into the kernel. -// -// It can be passed to LoadKmeshSockopsCompatObjects or ebpf.CollectionSpec.LoadAndAssign. -type KmeshSockopsCompatPrograms struct { - SockopsProg *ebpf.Program `ebpf:"sockops_prog"` -} - -func (p *KmeshSockopsCompatPrograms) Close() error { - return _KmeshSockopsCompatClose( - p.SockopsProg, - ) -} - -func _KmeshSockopsCompatClose(closers ...io.Closer) error { - for _, closer := range closers { - if err := closer.Close(); err != nil { - return err - } - } - return nil -} - -// Do not access this directly. -// -//go:embed kmeshsockopscompat_bpfel.o -var _KmeshSockopsCompatBytes []byte diff --git a/pkg/status/status_server_test.go b/pkg/status/status_server_test.go index 097991a82..39141730e 100644 --- a/pkg/status/status_server_test.go +++ b/pkg/status/status_server_test.go @@ -21,14 +21,11 @@ import ( "encoding/json" "fmt" "io" - "math/rand" "net/http" "net/http/httptest" "net/netip" - "os" "sort" "testing" - "time" "github.com/sirupsen/logrus" "github.com/stretchr/testify/assert" @@ -269,8 +266,7 @@ func TestServer_configDumpWorkload(t *testing.T) { fakeServiceCache.AddOrUpdateService(svc) } - // Create a new HTTP request and response - req2 := httptest.NewRequest(http.MethodGet, "/configDumpWorkload", nil) + // Create a new HTTP response w2 := httptest.NewRecorder() server = &Server{ @@ -286,13 +282,16 @@ func TestServer_configDumpWorkload(t *testing.T) { } // Call the configDumpWorkload function - server.configDumpWorkload(w2, req2) + server.configDumpWorkload(w2, req1) // Check the response status code if w2.Code != http.StatusOK { t.Errorf("Expected status code %d, but got %d", http.StatusOK, w2.Code) } + util.RefreshGoldenFile(t, w2.Body.Bytes(), "./testdata/workload_configdump_original_sorted.json") + util.CompareContent(t, w2.Body.Bytes(), "./testdata/workload_configdump_original_sorted.json") + fakeWorkloadCache = cache.NewWorkloadCache() fakeServiceCache = cache.NewServiceCache() // Modify workloads and services properties @@ -323,7 +322,6 @@ func TestServer_configDumpWorkload(t *testing.T) { } services[i] = svc } - for _, w := range workloads { fakeWorkloadCache.AddOrUpdateWorkload(w) } @@ -331,8 +329,6 @@ func TestServer_configDumpWorkload(t *testing.T) { fakeServiceCache.AddOrUpdateService(svc) } - // Second dump - save modified state to JSON - req3 := httptest.NewRequest(http.MethodGet, "/configDumpWorkload", nil) w3 := httptest.NewRecorder() server = &Server{ @@ -347,38 +343,14 @@ func TestServer_configDumpWorkload(t *testing.T) { }, } - rand.New(rand.NewSource(time.Now().UnixNano())) - rand.Shuffle(len(workloads), func(i, j int) { - workloads[i], workloads[j] = workloads[j], workloads[i] - }) - rand.Shuffle(len(services), func(i, j int) { - services[i], services[j] = services[j], services[i] - }) - - server.configDumpWorkload(w3, req3) + server.configDumpWorkload(w3, req1) if w3.Code != http.StatusOK { t.Errorf("Expected status code %d, but got %d", http.StatusOK, w3.Code) } - // compare the modified dump with the original - err := util.Compare(w3.Body.Bytes(), w2.Body.Bytes()) - if err != nil { - fmt.Printf("Modified dump differs from original: %v\n", err) - } else { - t.Error("Modified dump should differ from original, but they are the same") - } - - // save original and modified dumps to json files - err = os.WriteFile("./testdata/workload_configdump_original.json", w2.Body.Bytes(), 0644) - if err != nil { - t.Errorf("Failed to write original dump to file: %v", err) - } - - err = os.WriteFile("./testdata/workload_configdump_modified.json", w3.Body.Bytes(), 0644) - if err != nil { - t.Errorf("Failed to write modified dump to file: %v", err) - } + util.RefreshGoldenFile(t, w3.Body.Bytes(), "./testdata/workload_configdump_modified_sorted.json") + util.CompareContent(t, w3.Body.Bytes(), "./testdata/workload_configdump_modified_sorted.json") } func TestServer_dumpWorkloadBpfMap(t *testing.T) { diff --git a/pkg/status/testdata/workload_configdump_modified.json b/pkg/status/testdata/workload_configdump_modified_sorted.json similarity index 100% rename from pkg/status/testdata/workload_configdump_modified.json rename to pkg/status/testdata/workload_configdump_modified_sorted.json diff --git a/pkg/status/testdata/workload_configdump_original.json b/pkg/status/testdata/workload_configdump_original_sorted.json similarity index 100% rename from pkg/status/testdata/workload_configdump_original.json rename to pkg/status/testdata/workload_configdump_original_sorted.json From 0690f18c3ae8b2f2d403855a03b07a18575da660 Mon Sep 17 00:00:00 2001 From: aicee Date: Thu, 10 Jul 2025 09:42:11 +0800 Subject: [PATCH 4/6] fix: nil pointer dereference in runTestCertRotate function. Signed-off-by: aicee --- pkg/controller/security/manager_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/controller/security/manager_test.go b/pkg/controller/security/manager_test.go index 989878197..909dd4cc3 100644 --- a/pkg/controller/security/manager_test.go +++ b/pkg/controller/security/manager_test.go @@ -124,7 +124,7 @@ func runTestCertRotate(t *testing.T) { for { secretManager.certsCache.mu.RLock() cert2 := secretManager.certsCache.certs[identity1] - if cert2 != nil && cert2.cert.CreatedTime != oldCert.CreatedTime { + if cert2 != nil && cert2.cert != nil && cert2.cert.CreatedTime != oldCert.CreatedTime { newCert = *cert2.cert secretManager.certsCache.mu.RUnlock() break From 04935ed2868fdeee58a1229fa3c630c6201644b2 Mon Sep 17 00:00:00 2001 From: aicee Date: Mon, 14 Jul 2025 18:55:04 +0800 Subject: [PATCH 5/6] try to fix runTestretryFetchCert nil error Signed-off-by: aicee --- pkg/controller/security/manager_test.go | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/pkg/controller/security/manager_test.go b/pkg/controller/security/manager_test.go index 909dd4cc3..1140b8157 100644 --- a/pkg/controller/security/manager_test.go +++ b/pkg/controller/security/manager_test.go @@ -160,13 +160,30 @@ func runTestretryFetchCert(t *testing.T) { go secretManager.Run(stopCh) identity := "identity" - identity1 := "identity1" secretManager.SendCertRequest(identity, ADD) time.Sleep(100 * time.Millisecond) patches2.Reset() - secretManager.SendCertRequest(identity1, RETRY) + + secretManager.SendCertRequest(identity, RETRY) time.Sleep(2000 * time.Millisecond) - assert.NotNil(t, secretManager.GetCert(identity).cert) + for { + cert := secretManager.GetCert(identity) + if cert != nil { + secretManager.certsCache.mu.RLock() + hasCert := cert.cert != nil + secretManager.certsCache.mu.RUnlock() + if hasCert { + break + } + } + time.Sleep(100 * time.Millisecond) + } + + cert := secretManager.GetCert(identity) + assert.NotNil(t, cert) + secretManager.certsCache.mu.RLock() + assert.NotNil(t, cert.cert) + secretManager.certsCache.mu.RUnlock() close(stopCh) } From 81896f57f0265f30dbe57958a20a2835722ee2b0 Mon Sep 17 00:00:00 2001 From: aicee Date: Tue, 15 Jul 2025 15:28:00 +0800 Subject: [PATCH 6/6] use retry.UntilSucess Signed-off-by: aicee --- pkg/controller/security/manager_test.go | 37 +++++++++++++------------ 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/pkg/controller/security/manager_test.go b/pkg/controller/security/manager_test.go index 1140b8157..1c46c897d 100644 --- a/pkg/controller/security/manager_test.go +++ b/pkg/controller/security/manager_test.go @@ -24,6 +24,7 @@ import ( "github.com/agiledragon/gomonkey/v2" "github.com/stretchr/testify/assert" "istio.io/istio/pkg/security" + "istio.io/istio/pkg/test/util/retry" camock "kmesh.net/kmesh/pkg/controller/security/mock" ) @@ -165,25 +166,27 @@ func runTestretryFetchCert(t *testing.T) { patches2.Reset() secretManager.SendCertRequest(identity, RETRY) - time.Sleep(2000 * time.Millisecond) - for { - cert := secretManager.GetCert(identity) - if cert != nil { - secretManager.certsCache.mu.RLock() - hasCert := cert.cert != nil - secretManager.certsCache.mu.RUnlock() - if hasCert { - break + + err = retry.UntilSuccess( + func() error { + cert := secretManager.GetCert(identity) + if cert != nil { + secretManager.certsCache.mu.RLock() + hasCert := cert.cert != nil + secretManager.certsCache.mu.RUnlock() + if hasCert { + return nil + } } - } - time.Sleep(100 * time.Millisecond) + return fmt.Errorf("cert not found for identity %s", identity) + }, + retry.Delay(100*time.Millisecond), + retry.Timeout(6*time.Second), + ) + + if err != nil { + t.Errorf("Failed to fetch cert after retry: %v", err) } - cert := secretManager.GetCert(identity) - assert.NotNil(t, cert) - secretManager.certsCache.mu.RLock() - assert.NotNil(t, cert.cert) - secretManager.certsCache.mu.RUnlock() - close(stopCh) }