From 11b2cd7f72864e802d4aeefa9cb549fff073c8c3 Mon Sep 17 00:00:00 2001 From: lumbrjx Date: Fri, 30 Aug 2024 14:29:37 +0100 Subject: [PATCH 1/4] Update --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 82e2bcb..d869e05 100644 --- a/Makefile +++ b/Makefile @@ -16,7 +16,7 @@ dev-to-staging: @git push origin $(STAGING_BRANCH) @echo "Merged $(DEV_BRANCH) to $(STAGING_BRANCH) and pushed to origin." -staging-to-release: dev-to-staging release +staging-to-release: dev-to-staging @git checkout $(RELEASE_BRANCH) @git merge $(STAGING_BRANCH) @git push origin $(RELEASE_BRANCH) From 4532f66a7cb3d2db43d9a9c0b896a459b8bd1c8b Mon Sep 17 00:00:00 2001 From: lumbrjx Date: Fri, 30 Aug 2024 17:24:29 +0100 Subject: [PATCH 2/4] Feat :sparkles: Add Ebpf Program For Tc I/O Observability --- daemon/api/grpc/Dockerfile | 79 ++++++++- daemon/api/grpc/Makefile | 58 +++++++ daemon/api/grpc/server.go | 5 + daemon/api/grpc/tcAnalyser/bpf/tc.c | 88 ++++++++++ daemon/api/grpc/tcAnalyser/bpfManager.go | 202 +++++++++++++++++++++++ daemon/api/grpc/tcAnalyser/helpers.go | 75 +++++++++ daemon/api/grpc/tcAnalyser/service.go | 1 + daemon/go.mod | 4 + daemon/go.sum | 10 ++ daemonset.yaml | 2 +- 10 files changed, 517 insertions(+), 7 deletions(-) create mode 100644 daemon/api/grpc/Makefile create mode 100644 daemon/api/grpc/tcAnalyser/bpf/tc.c create mode 100644 daemon/api/grpc/tcAnalyser/bpfManager.go create mode 100644 daemon/api/grpc/tcAnalyser/helpers.go diff --git a/daemon/api/grpc/Dockerfile b/daemon/api/grpc/Dockerfile index 3231d68..416dc58 100644 --- a/daemon/api/grpc/Dockerfile +++ b/daemon/api/grpc/Dockerfile @@ -1,29 +1,96 @@ -FROM golang:1.22.5-alpine AS builder +# FROM golang:1.22.5-alpine AS builder +# +# WORKDIR /app +# +# COPY daemon/go.mod daemon/go.sum ./ +# COPY common ./common +# COPY daemon/ . +# +# RUN sed -i 's|replace obzev0/common => ../common|replace obzev0/common => ./common|' go.mod +# RUN go mod download +# RUN CGO_ENABLED=0 GOOS=linux go build -o grpc-server ./api/grpc/server.go +# +# FROM alpine:latest AS grpc_health_probe_downloader +# RUN wget -qO /bin/grpc_health_probe https://github.com/grpc-ecosystem/grpc-health-probe/releases/download/v0.4.11/grpc_health_probe-linux-amd64 && \ +# chmod +x /bin/grpc_health_probe +# +# FROM alpine:latest +# +# WORKDIR /root/ +# +# COPY --from=builder /app/grpc-server . +# COPY --from=builder /app/common ./common +# COPY --from=grpc_health_probe_downloader /bin/grpc_health_probe /bin/grpc_health_probe +# +# EXPOSE 50051 +# EXPOSE 2112 +# +# CMD ["./grpc-server"] +# +# Stage 1: Build eBPF program and Go application +FROM golang:1.23.0-bookworm AS builder +# Install dependencies for building eBPF programs +RUN apt-get update && \ + apt-get install -y \ + clang \ + llvm \ + libelf-dev \ + linux-headers-$(uname -r) \ + build-essential \ + iproute2 \ + libbpf-dev \ + && apt-get clean && \ + rm -rf /var/lib/apt/lists/* + +# Set working directory WORKDIR /app +# Copy Go modules files and download dependencies COPY daemon/go.mod daemon/go.sum ./ COPY common ./common COPY daemon/ . +# Modify go.mod and build Go application RUN sed -i 's|replace obzev0/common => ../common|replace obzev0/common => ./common|' go.mod RUN go mod download RUN CGO_ENABLED=0 GOOS=linux go build -o grpc-server ./api/grpc/server.go -FROM alpine:latest AS grpc_health_probe_downloader -RUN wget -qO /bin/grpc_health_probe https://github.com/grpc-ecosystem/grpc-health-probe/releases/download/v0.4.11/grpc_health_probe-linux-amd64 && \ - chmod +x /bin/grpc_health_probe +# Copy and compile eBPF program +COPY daemon/api/grpc/tcAnalyser/bpf/ /app/bpf/ +WORKDIR /app/bpf +RUN clang -I/usr/include -I/usr/include/x86_64-linux-gnu -I/usr/include/x86_64-linux-gnu/bits -I/usr/include/x86_64-linux-gnu/sys -I/usr/include/bpf -O2 -g -target bpf -c tc.c -o tc.o -FROM alpine:latest +# Stage 2: Download grpc-health-probe +FROM debian:latest AS grpc_health_probe_downloader +RUN apt-get update && \ + apt-get install -y wget && \ + wget -qO /bin/grpc_health_probe https://github.com/grpc-ecosystem/grpc-health-probe/releases/download/v0.4.11/grpc_health_probe-linux-amd64 && \ + chmod +x /bin/grpc_health_probe && \ + apt-get clean && \ + rm -rf /var/lib/apt/lists/* +# Stage 3: Create final image +FROM debian:latest + +# Install iproute2 to handle network configuration +RUN apt-get update && \ + apt-get install -y iproute2 && \ + apt-get clean && \ + rm -rf /var/lib/apt/lists/* + +# Set working directory WORKDIR /root/ +# Copy compiled Go application and eBPF program COPY --from=builder /app/grpc-server . -COPY --from=builder /app/common ./common +COPY --from=builder /app/bpf/tc.o /root/ COPY --from=grpc_health_probe_downloader /bin/grpc_health_probe /bin/grpc_health_probe +# Expose ports EXPOSE 50051 EXPOSE 2112 +# Default command to run your application CMD ["./grpc-server"] diff --git a/daemon/api/grpc/Makefile b/daemon/api/grpc/Makefile new file mode 100644 index 0000000..90db5c4 --- /dev/null +++ b/daemon/api/grpc/Makefile @@ -0,0 +1,58 @@ +TARGET = tc.o +INTERFACE = enp1s0 +US_DIR = user_space +CFLAGS = -I/usr/include -I/usr/include/x86_64-linux-gnu -I/usr/include/x86_64-linux-gnu/bits -I/usr/include/x86_64-linux-gnu/sys -I/usr/include/bpf + +.PHONY: install-deps +install-deps: + sudo apt update + sudo apt install -y clang llvm libelf-dev linux-headers-$$(uname -r) build-essential + cd $(US_DIR) && go mod tidy + +# Compile the eBPF program +$(TARGET): main.c + clang $(CFLAGS) -O2 -g -target bpf -c bpf/tc.c -o $(TARGET) + +# Load the eBPF program manually +.PHONY: load +load: $(TARGET) + sudo tc qdisc add dev $(INTERFACE) clsact + sudo tc filter add dev $(INTERFACE) ingress bpf da obj $(TARGET) sec tc + sudo tc filter add dev $(INTERFACE) egress bpf da obj $(TARGET) sec tc + +# View bpf_printk output +.PHONY: view-manual +view: + sudo cat /sys/kernel/debug/tracing/trace_pipe + +.PHONY: view-tcp-manual +view-tcp: + sudo cat /sys/kernel/debug/tracing/trace_pipe | grep TCP + +.PHONY: view-udp-manual +view-udp: + sudo cat /sys/kernel/debug/tracing/trace_pipe | grep UDP + + +# build user space program +.PHONY: build-US +build-US: + cd user_space && go build -o tc_US tc.go + +# start user space program +.PHONY: start-US +start-US: + sudo ./user_space/tc_US $(INTERFACE) + +# Remove the filters and qdisc when done manually +.PHONY: clean +clean: + sudo tc filter del dev $(INTERFACE) ingress + sudo tc filter del dev $(INTERFACE) egress + sudo tc qdisc del dev $(INTERFACE) clsact + rm -f $(TARGET) + rm -f user_space/tc_US + +# All +.PHONY: all +all: install-deps $(TARGET) build-US start-US diff --git a/daemon/api/grpc/server.go b/daemon/api/grpc/server.go index 1e08358..8a38542 100644 --- a/daemon/api/grpc/server.go +++ b/daemon/api/grpc/server.go @@ -5,8 +5,10 @@ import ( "net" "net/http" ltc "obzev0/common/proto/latency" + tcanl "obzev0/common/proto/tcAnalyser" "obzev0/daemon/api/grpc/interceptors" "obzev0/daemon/api/grpc/latency" + tcanalyser "obzev0/daemon/api/grpc/tcAnalyser" "os" "time" @@ -96,6 +98,9 @@ func main() { s := latency.LatencyService{} ltc.RegisterLatencyServiceServer(grpcServer, &s) + tc := tcanalyser.TcAnalyserService{} + tcanl.RegisterTcAnalyserServiceServer(grpcServer, &tc) + healthSrv := health.NewServer() grpc_health_v1.RegisterHealthServer(grpcServer, healthSrv) diff --git a/daemon/api/grpc/tcAnalyser/bpf/tc.c b/daemon/api/grpc/tcAnalyser/bpf/tc.c new file mode 100644 index 0000000..71ca6be --- /dev/null +++ b/daemon/api/grpc/tcAnalyser/bpf/tc.c @@ -0,0 +1,88 @@ +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +struct { + __uint(type, BPF_MAP_TYPE_PERF_EVENT_ARRAY); + __uint(key_size, sizeof(int)); + __uint(value_size, sizeof(int)); + __uint(max_entries, 1024); +} events SEC(".maps"); + +struct event { + __u32 src_ip; + __u32 dst_ip; + __u16 src_port; + __u16 dst_port; + __u8 protocol; + __u8 direction; + __u8 tcp_flags; +}; + +// to avoid duplication :> +static __always_inline int process_packet(struct __sk_buff *skb, + unsigned char direction) { + void *data = (void *)(unsigned long)skb->data; + void *data_end = (void *)(unsigned long)skb->data_end; + + // eht header + struct ethhdr *eth = data; + if ((void *)(eth + 1) > data_end) + return TC_ACT_SHOT; + if (eth->h_proto != bpf_htons(ETH_P_IP)) + return TC_ACT_OK; + + // ip header + struct iphdr *ip = (struct iphdr *)(eth + 1); + if ((void *)(ip + 1) > data_end) + return TC_ACT_SHOT; + + // event creation + struct event e = {0}; + e.src_ip = ip->saddr; + e.dst_ip = ip->daddr; + e.protocol = ip->protocol; + e.direction = direction; + + if (ip->protocol == IPPROTO_TCP) { + struct tcphdr *tcp = (struct tcphdr *)(ip + 1); + if ((void *)(tcp + 1) > data_end) + return TC_ACT_SHOT; + + e.src_port = bpf_ntohs(tcp->source); + e.dst_port = bpf_ntohs(tcp->dest); + e.tcp_flags = tcp->fin | (tcp->syn << 1) | (tcp->rst << 2) | + (tcp->psh << 3) | (tcp->ack << 4) | (tcp->urg << 5) | + (tcp->ece << 6) | (tcp->cwr << 7); + } else if (ip->protocol == IPPROTO_UDP) { + struct udphdr *udp = (struct udphdr *)(ip + 1); + if ((void *)(udp + 1) > data_end) + return TC_ACT_SHOT; + + e.src_port = bpf_ntohs(udp->source); + e.dst_port = bpf_ntohs(udp->dest); + } else { + e.src_port = 0; + e.dst_port = 0; + e.tcp_flags = 0; + } + // outputing the data via a perf event array map + bpf_perf_event_output(skb, &events, BPF_F_CURRENT_CPU, &e, sizeof(e)); + + return TC_ACT_OK; +} + +SEC("tc") +int tc_ingress(struct __sk_buff *skb) { return process_packet(skb, 0); } + +SEC("tc") +int tc_egress(struct __sk_buff *skb) { return process_packet(skb, 1); } + +char _license[] SEC("license") = "GPL"; diff --git a/daemon/api/grpc/tcAnalyser/bpfManager.go b/daemon/api/grpc/tcAnalyser/bpfManager.go new file mode 100644 index 0000000..d703f8c --- /dev/null +++ b/daemon/api/grpc/tcAnalyser/bpfManager.go @@ -0,0 +1,202 @@ +package tcanalyser + +import ( + "bytes" + "encoding/binary" + "fmt" + "log" + "os" + "os/signal" + "syscall" + + "github.com/cilium/ebpf" + "github.com/cilium/ebpf/perf" + "github.com/vishvananda/netlink" +) + +type Event struct { + SrcIP uint32 + DstIP uint32 + SrcPort uint16 + DstPort uint16 + Protocol uint8 + Direction uint8 + TcpFlags uint8 +} + +func bpfLoader(interf string) { + ifaceName := interf + + spec, err := loadBpfSpec("tc.o") + if err != nil { + log.Fatalf("loading eBPF spec: %v", err) + } + + var objs struct { + TcIngress *ebpf.Program `ebpf:"tc_ingress"` + TcEgress *ebpf.Program `ebpf:"tc_egress"` + Events *ebpf.Map `ebpf:"events"` + } + if err := spec.LoadAndAssign(&objs, nil); err != nil { + log.Fatalf("loading objects: %v", err) + } + defer objs.TcIngress.Close() + defer objs.TcEgress.Close() + defer objs.Events.Close() + + link, err := netlink.LinkByName(ifaceName) + if err != nil { + log.Fatalf("getting interface: %v", err) + } + + // Ensure clsact qdisc exists + qdiscs, err := netlink.QdiscList(link) + if err != nil { + log.Fatalf("listing qdiscs: %v", err) + } + clsactExists := false + for _, qdisc := range qdiscs { + if _, ok := qdisc.(*netlink.GenericQdisc); ok && + qdisc.Type() == "clsact" { + clsactExists = true + break + } + } + if !clsactExists { + qdisc := &netlink.GenericQdisc{ + QdiscAttrs: netlink.QdiscAttrs{ + LinkIndex: link.Attrs().Index, + Handle: netlink.MakeHandle(0xffff, 0), + Parent: netlink.HANDLE_CLSACT, + }, + QdiscType: "clsact", + } + if err := netlink.QdiscAdd(qdisc); err != nil { + log.Fatalf("adding clsact qdisc: %v", err) + } + fmt.Println("Added clsact qdisc") + } else { + fmt.Println("clsact qdisc already exists") + } + + ingressFilter := &netlink.BpfFilter{ + FilterAttrs: netlink.FilterAttrs{ + LinkIndex: link.Attrs().Index, + Parent: netlink.HANDLE_MIN_INGRESS, + Handle: netlink.MakeHandle(0, 1), + Protocol: syscall.ETH_P_ALL, + }, + Fd: objs.TcIngress.FD(), + Name: "tc_ingress", + DirectAction: true, + } + if err := netlink.FilterAdd(ingressFilter); err != nil { + log.Fatalf("adding ingress filter: %v", err) + } + fmt.Println("Added ingress filter") + + egressFilter := &netlink.BpfFilter{ + FilterAttrs: netlink.FilterAttrs{ + LinkIndex: link.Attrs().Index, + Parent: netlink.HANDLE_MIN_EGRESS, + Handle: netlink.MakeHandle(0, 1), + Protocol: syscall.ETH_P_ALL, + }, + Fd: objs.TcEgress.FD(), + Name: "tc_egress", + DirectAction: true, + } + if err := netlink.FilterAdd(egressFilter); err != nil { + log.Fatalf("adding egress filter: %v", err) + } + fmt.Println("Added egress filter") + + // perf reader + reader, err := perf.NewReader(objs.Events, os.Getpagesize()) + if err != nil { + log.Fatalf("creating perf reader: %v", err) + } + defer reader.Close() + + // read events + go func() { + for { + record, err := reader.Read() + if err != nil { + if err == perf.ErrClosed { + return + } + log.Printf("reading from perf event reader: %s", err) + continue + } + + if record.LostSamples != 0 { + log.Printf( + "perf event ring buffer full, dropped %d samples", + record.LostSamples, + ) + continue + } + + var event Event + if err := binary.Read(bytes.NewBuffer(record.RawSample), binary.LittleEndian, &event); err != nil { + log.Printf("parsing perf event: %s", err) + continue + } + printPacket(event) + + } + }() + + fmt.Printf("eBPF programs attached to interface %s\n", ifaceName) + + c := make(chan os.Signal, 1) + signal.Notify(c, os.Interrupt, syscall.SIGTERM) + <-c + + fmt.Println("Received interrupt, cleaning up...") + + // Clean up filters + filters, err := netlink.FilterList(link, netlink.HANDLE_MIN_INGRESS) + if err != nil { + log.Printf("error listing ingress filters: %v", err) + } else { + for _, filter := range filters { + if bpfFilter, ok := filter.(*netlink.BpfFilter); ok && bpfFilter.Name == "tc_ingress" { + if err := netlink.FilterDel(bpfFilter); err != nil { + log.Printf("error removing ingress filter: %v", err) + } else { + fmt.Println("Removed ingress filter") + } + } + } + } + + filterss, err := netlink.FilterList(link, netlink.HANDLE_MIN_EGRESS) + if err != nil { + log.Printf("error listing egress filters: %v", err) + } else { + for _, filter := range filterss { + if bpfFilter, ok := filter.(*netlink.BpfFilter); ok && bpfFilter.Name == "tc_egress" { + if err := netlink.FilterDel(bpfFilter); err != nil { + log.Printf("error removing egress filter: %v", err) + } else { + fmt.Println("Removed egress filter") + } + } + } + } + + qdisc := &netlink.GenericQdisc{ + QdiscAttrs: netlink.QdiscAttrs{ + LinkIndex: link.Attrs().Index, + Handle: netlink.MakeHandle(0xffff, 0), + Parent: netlink.HANDLE_CLSACT, + }, + QdiscType: "clsact", + } + if err := netlink.QdiscDel(qdisc); err != nil { + log.Fatalf("deleting clsact qdisc: %v", err) + } + fmt.Println("Deleted clsact qdisc") +} diff --git a/daemon/api/grpc/tcAnalyser/helpers.go b/daemon/api/grpc/tcAnalyser/helpers.go new file mode 100644 index 0000000..9836ee6 --- /dev/null +++ b/daemon/api/grpc/tcAnalyser/helpers.go @@ -0,0 +1,75 @@ +package tcanalyser + +import ( + "fmt" + "net" + + "github.com/cilium/ebpf" +) + +func intToIP(ip uint32) net.IP { + return net.IPv4(byte(ip), byte(ip>>8), byte(ip>>16), byte(ip>>24)) +} + +func loadBpfSpec(path string) (*ebpf.CollectionSpec, error) { + spec, err := ebpf.LoadCollectionSpec(path) + if err != nil { + return nil, fmt.Errorf("failed to load BPF spec: %v", err) + } + if eventsMap, ok := spec.Maps["events"]; ok { + eventsMap.Type = ebpf.PerfEventArray + } + + return spec, nil +} +func tcpFlagsToString(flags uint8) string { + flagNames := []struct { + mask uint8 + name string + }{ + {0x01, "FIN"}, + {0x02, "SYN"}, + {0x04, "RST"}, + {0x08, "PSH"}, + {0x10, "ACK"}, + {0x20, "URG"}, + {0x40, "ECE"}, + {0x80, "CWR"}, + } + + var result []string + for _, f := range flagNames { + if flags&f.mask != 0 { + result = append(result, f.name) + } + } + if len(result) == 0 { + return "NONE" + } + return fmt.Sprintf("0x%x (%s)", flags, fmt.Sprintf("%s", result)) +} +func printPacket(event Event) { + direction := "Ingress" + if event.Direction == 1 { + direction = "Egress" + } + flags := "" + protoc := "?" + s_msg := "%s %s: src=%s:%d -> dst=%s:%d | proto=%d | flags=%s\n" + switch event.Protocol { + case 6: // TCP + flags = tcpFlagsToString(event.TcpFlags) + protoc = "TCP" + case 17: // UDP + protoc = "UDP" + s_msg = "%s %s: src=%s:%d -> dst=%s:%d | proto=%d\n" + } + fmt.Printf(s_msg, + direction, + protoc, + intToIP(event.SrcIP), event.SrcPort, + intToIP(event.DstIP), event.DstPort, + event.Protocol, + flags) + +} diff --git a/daemon/api/grpc/tcAnalyser/service.go b/daemon/api/grpc/tcAnalyser/service.go index 7520124..2bfcf33 100644 --- a/daemon/api/grpc/tcAnalyser/service.go +++ b/daemon/api/grpc/tcAnalyser/service.go @@ -31,6 +31,7 @@ func (s *TcAnalyserService) StartTcpServer( config := requestUserSpace.GetConfig() log.Printf("recived %s", config.Interface) + go bpfLoader(config.Interface) // conf := definitions.Config{ // Delays: definitions.DelaysConfig{ // ReqDelay: config.ReqDelay, diff --git a/daemon/go.mod b/daemon/go.mod index b1d9196..515548b 100644 --- a/daemon/go.mod +++ b/daemon/go.mod @@ -18,6 +18,7 @@ require github.com/sirupsen/logrus v1.9.3 require ( github.com/beorn7/perks v1.0.1 // indirect github.com/cespare/xxhash/v2 v2.3.0 // indirect + github.com/cilium/ebpf v0.16.0 // indirect github.com/envoyproxy/protoc-gen-validate v1.1.0 // indirect github.com/kr/text v0.2.0 // indirect github.com/prometheus/client_model v0.5.0 // indirect @@ -25,6 +26,9 @@ require ( github.com/prometheus/procfs v0.12.0 // indirect github.com/rogpeppe/go-internal v1.11.0 // indirect github.com/stretchr/testify v1.9.0 // indirect + github.com/vishvananda/netlink v1.3.0 // indirect + github.com/vishvananda/netns v0.0.4 // indirect + golang.org/x/exp v0.0.0-20230522175609-2e198f4a06a1 // indirect golang.org/x/sys v0.22.0 // indirect golang.org/x/text v0.16.0 // indirect google.golang.org/genproto/googleapis/rpc v0.0.0-20240709173604-40e1e62336c5 // indirect diff --git a/daemon/go.sum b/daemon/go.sum index be0554c..cfcd099 100644 --- a/daemon/go.sum +++ b/daemon/go.sum @@ -2,6 +2,8 @@ github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM= github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw= github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs= github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= +github.com/cilium/ebpf v0.16.0 h1:+BiEnHL6Z7lXnlGUsXQPPAE7+kenAd4ES8MQ5min0Ok= +github.com/cilium/ebpf v0.16.0/go.mod h1:L7u2Blt2jMM/vLAVgjxluxtBKlz3/GWjB0dMOEngfwE= github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= @@ -34,9 +36,17 @@ github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+ github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= +github.com/vishvananda/netlink v1.3.0 h1:X7l42GfcV4S6E4vHTsw48qbrV+9PVojNfIhZcwQdrZk= +github.com/vishvananda/netlink v1.3.0/go.mod h1:i6NetklAujEcC6fK0JPjT8qSwWyO0HLn4UKG+hGqeJs= +github.com/vishvananda/netns v0.0.4 h1:Oeaw1EM2JMxD51g9uhtC0D7erkIjgmj8+JZc26m1YX8= +github.com/vishvananda/netns v0.0.4/go.mod h1:SpkAiCQRtJ6TvvxPnOSyH3BMl6unz3xZlaprSwhNNJM= +golang.org/x/exp v0.0.0-20230522175609-2e198f4a06a1 h1:k/i9J1pBpvlfR+9QsetwPyERsqu1GIbi967PQMq3Ivc= +golang.org/x/exp v0.0.0-20230522175609-2e198f4a06a1/go.mod h1:V1LtkGg67GoY2N1AnLN78QLrzxkLyJw7RJb1gzOOz9w= golang.org/x/net v0.27.0 h1:5K3Njcw06/l2y9vpGCSdcxWOYHOUk3dVNGDXN+FvAys= golang.org/x/net v0.27.0/go.mod h1:dDi0PyhWNoiUOrAS8uXv/vnScO4wnHQO4mj9fn/RytE= golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.2.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.10.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.22.0 h1:RI27ohtqKCnwULzJLqkv897zojh5/DwS/ENaMzUOaWI= golang.org/x/sys v0.22.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/text v0.16.0 h1:a94ExnEXNtEwYLGJSIUxnWoxoRz/ZcCsV63ROupILh4= diff --git a/daemonset.yaml b/daemonset.yaml index e77a051..72e8630 100644 --- a/daemonset.yaml +++ b/daemonset.yaml @@ -13,7 +13,7 @@ spec: spec: containers: - name: grpc-server - image: lumbrjx/obzev0-grpc-daemon:1.0.6 + image: lumbrjx/obzev0-grpc-daemon:1.0.8-alpha ports: - containerPort: 50051 livenessProbe: From a539b7d03a9c3254d3068b2f1bd95760940dbb0e Mon Sep 17 00:00:00 2001 From: lumbrjx Date: Fri, 30 Aug 2024 22:13:15 +0100 Subject: [PATCH 3/4] Feat :sparkles: Integrate Ebpf Service --- .github/workflows/builds.yml | 13 +- Makefile | 13 ++ README.md | 6 + controller/README.md | 114 ------------------ controller/api/v1/obzev0resource_types.go | 11 +- controller/api/v1/zz_generated.deepcopy.go | 2 +- .../batch.github.com_obzev0resources.yaml | 7 +- controller/config/manager/kustomization.yaml | 2 +- .../samples/batch_v1_obzev0resource.yaml | 10 +- controller/go.mod | 1 + controller/go.sum | 2 + .../controller/obzev0resource_controller.go | 28 ++++- .../client/clientset/versioned/clientset.go | 18 --- .../pkg/client/clientset/versioned/doc.go | 19 --- .../versioned/fake/clientset_generated.go | 18 --- .../client/clientset/versioned/fake/doc.go | 19 --- .../clientset/versioned/fake/register.go | 18 --- .../client/clientset/versioned/scheme/doc.go | 19 --- .../clientset/versioned/scheme/register.go | 18 --- .../v1/batch.github.com_client.go | 18 --- .../typed/batch.github.com/v1/doc.go | 19 --- .../typed/batch.github.com/v1/fake/doc.go | 19 --- .../v1/fake/fake_batch.github.com_client.go | 18 --- .../v1/generated_expansion.go | 18 --- daemon/api/grpc/tcAnalyser/service.go | 2 +- daemon/cmd/cli/main.go | 38 +++--- daemonset.yaml | 15 ++- 27 files changed, 110 insertions(+), 375 deletions(-) delete mode 100644 controller/README.md delete mode 100644 controller/pkg/client/clientset/versioned/clientset.go delete mode 100644 controller/pkg/client/clientset/versioned/doc.go delete mode 100644 controller/pkg/client/clientset/versioned/fake/clientset_generated.go delete mode 100644 controller/pkg/client/clientset/versioned/fake/doc.go delete mode 100644 controller/pkg/client/clientset/versioned/fake/register.go delete mode 100644 controller/pkg/client/clientset/versioned/scheme/doc.go delete mode 100644 controller/pkg/client/clientset/versioned/scheme/register.go delete mode 100644 controller/pkg/client/clientset/versioned/typed/batch.github.com/v1/batch.github.com_client.go delete mode 100644 controller/pkg/client/clientset/versioned/typed/batch.github.com/v1/doc.go delete mode 100644 controller/pkg/client/clientset/versioned/typed/batch.github.com/v1/fake/doc.go delete mode 100644 controller/pkg/client/clientset/versioned/typed/batch.github.com/v1/fake/fake_batch.github.com_client.go delete mode 100644 controller/pkg/client/clientset/versioned/typed/batch.github.com/v1/generated_expansion.go diff --git a/.github/workflows/builds.yml b/.github/workflows/builds.yml index e070f0b..428a526 100644 --- a/.github/workflows/builds.yml +++ b/.github/workflows/builds.yml @@ -23,7 +23,7 @@ jobs: steps: - uses: actions/checkout@v3 - name: Run tests - run: echo "Running tests..." # Replace with actual test command + run: echo "No tests for now..." # Replace with actual test command build-and-push-staging: needs: test @@ -41,12 +41,16 @@ jobs: username: ${{ secrets.DOCKERHUB_USERNAME }} password: ${{ secrets.DOCKERHUB_TOKEN }} - - name: Build and push Daemon Docker image + - name: Build and push Daemon, Controller Docker images run: | make build-daemon TAG=${{ github.sha }} make push-daemon TAG=${{ github.sha }} docker tag ${{ env.DAEMON_IMAGE_NAME }}:${{ github.sha }} ${{ env.DAEMON_IMAGE_NAME }}:staging docker push ${{ env.DAEMON_IMAGE_NAME }}:staging + make build-controller TAG=${{ github.sha }} + make push-controller TAG=${{ github.sha }} + docker tag ${{ env.CONTROLLER_IMAGE_NAME }}:${{ github.sha }} ${{ env.CONTROLLER_IMAGE_NAME}}:staging + docker push ${{ env.CONTROLLER_IMAGE_NAME}}:staging create-release: if: github.ref == 'refs/heads/release' @@ -72,6 +76,11 @@ jobs: docker push ${{ env.DAEMON_IMAGE_NAME }}:v${{ github.run_number }} docker tag ${{ env.DAEMON_IMAGE_NAME }}:v${{ github.run_number }} ${{ env.DAEMON_IMAGE_NAME }}:latest docker push ${{ env.DAEMON_IMAGE_NAME }}:latest + docker pull ${{ env.CONTROLLER_IMAGE_NAME}}:staging + docker tag ${{ env.CONTROLLER_IMAGE_NAME}}:staging ${{ env.CONTROLLER_IMAGE_NAME}}:v${{ github.run_number }} + docker push ${{ env.CONTROLLER_IMAGE_NAME}}:v${{ github.run_number }} + docker tag ${{ env.CONTROLLER_IMAGE_NAME}}:v${{ github.run_number }} ${{ env.CONTROLLER_IMAGE_NAME}}:latest + docker push ${{ env.CONTROLLER_IMAGE_NAME}}:latest - name: Create GitHub Release uses: actions/create-release@v1 diff --git a/Makefile b/Makefile index d869e05..86dd59c 100644 --- a/Makefile +++ b/Makefile @@ -39,6 +39,13 @@ build-daemon: fi docker build -f daemon/api/grpc/Dockerfile -t lumbrjx/obzev0-grpc-daemon:$$TAG . +build-controller: + @if [ -z "$$TAG" ]; then \ + echo "Usage: make build-controller TAG="; \ + exit 1; \ + fi + docker build -f controller/Dockerfile -t lumbrjx/obzev0poc:$$TAG . + push-daemon: @if [ -z "$$TAG" ]; then \ echo "Usage: make push-daemon TAG="; \ @@ -46,6 +53,12 @@ push-daemon: fi docker push lumbrjx/obzev0-grpc-daemon:$$TAG +push-controller: + @if [ -z "$$TAG" ]; then \ + echo "Usage: make push-controller TAG="; \ + exit 1; \ + fi + docker push lumbrjx/obzev0poc:$$TAG generate-proto: @if [ -z "$$PROTO_PATH" ]; then \ diff --git a/README.md b/README.md index 04415bc..d8c129a 100644 --- a/README.md +++ b/README.md @@ -21,3 +21,9 @@ Obzev0 is built using a microservices architecture, with the following component - **Controller:** Responsible for watching Custom Resource Definitions (CRDs) representing chaos scenarios and dispatching work to the DaemonSet. - **DaemonSet:** Runs on every node in the Kubernetes cluster and acts as a gRPC server. It executes the chaos scenarios and communicates with the eBPF program in the kernel space. - **eBPF Program:** Written in C, it runs in the kernel space and is responsible for monitoring and manipulating network traffic for performance monitoring. + +## ToDo + +[ ] complete Update/Delete informer functions +[ ] integrate tcAnalyser service in k8s controller grpc calls + diff --git a/controller/README.md b/controller/README.md deleted file mode 100644 index eaf0a19..0000000 --- a/controller/README.md +++ /dev/null @@ -1,114 +0,0 @@ -# controller -// TODO(user): Add simple overview of use/purpose - -## Description -// TODO(user): An in-depth paragraph about your project and overview of use - -## Getting Started - -### Prerequisites -- go version v1.22.0+ -- docker version 17.03+. -- kubectl version v1.11.3+. -- Access to a Kubernetes v1.11.3+ cluster. - -### To Deploy on the cluster -**Build and push your image to the location specified by `IMG`:** - -```sh -make docker-build docker-push IMG=/controller:tag -``` - -**NOTE:** This image ought to be published in the personal registry you specified. -And it is required to have access to pull the image from the working environment. -Make sure you have the proper permission to the registry if the above commands don’t work. - -**Install the CRDs into the cluster:** - -```sh -make install -``` - -**Deploy the Manager to the cluster with the image specified by `IMG`:** - -```sh -make deploy IMG=/controller:tag -``` - -> **NOTE**: If you encounter RBAC errors, you may need to grant yourself cluster-admin -privileges or be logged in as admin. - -**Create instances of your solution** -You can apply the samples (examples) from the config/sample: - -```sh -kubectl apply -k config/samples/ -``` - ->**NOTE**: Ensure that the samples has default values to test it out. - -### To Uninstall -**Delete the instances (CRs) from the cluster:** - -```sh -kubectl delete -k config/samples/ -``` - -**Delete the APIs(CRDs) from the cluster:** - -```sh -make uninstall -``` - -**UnDeploy the controller from the cluster:** - -```sh -make undeploy -``` - -## Project Distribution - -Following are the steps to build the installer and distribute this project to users. - -1. Build the installer for the image built and published in the registry: - -```sh -make build-installer IMG=/controller:tag -``` - -NOTE: The makefile target mentioned above generates an 'install.yaml' -file in the dist directory. This file contains all the resources built -with Kustomize, which are necessary to install this project without -its dependencies. - -2. Using the installer - -Users can just run kubectl apply -f to install the project, i.e.: - -```sh -kubectl apply -f https://raw.githubusercontent.com//controller//dist/install.yaml -``` - -## Contributing -// TODO(user): Add detailed information on how you would like others to contribute to this project - -**NOTE:** Run `make help` for more information on all potential `make` targets - -More information can be found via the [Kubebuilder Documentation](https://book.kubebuilder.io/introduction.html) - -## License - -Copyright 2024. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. - diff --git a/controller/api/v1/obzev0resource_types.go b/controller/api/v1/obzev0resource_types.go index 15ad534..9caa4e8 100644 --- a/controller/api/v1/obzev0resource_types.go +++ b/controller/api/v1/obzev0resource_types.go @@ -36,13 +36,18 @@ type TcpConfig struct { Client string `json:"client,omitempty"` } +type TcAnalyserConfig struct { + NetIFace string `json:"netIFace,omitempty"` +} + // Obzev0ResourceSpec defines the desired state of Obzev0Resource type Obzev0ResourceSpec struct { // INSERT ADDITIONAL SPEC FIELDS - desired state of cluster // Important: Run "make" to regenerate code after modifying this file // Foo is an example field of Obzev0Resource. Edit obzev0resource_types.go to remove/update - Config TcpConfig `json:"config,omitempty"` + LatencyServiceConfig TcpConfig `json:"latencySvcConfig,omitempty"` + TcAnalyserServiceConfig TcAnalyserConfig `json:"tcAnalyserSvcConfig,omitempty"` } // Obzev0ResourceStatus defines the observed state of Obzev0Resource @@ -68,8 +73,8 @@ type Obzev0Resource struct { // Obzev0ResourceList contains a list of Obzev0Resource type Obzev0ResourceList struct { - metav1.TypeMeta `json:",inline"` - metav1.ListMeta `json:"metadata,omitempty"` + metav1.TypeMeta ` json:",inline"` + metav1.ListMeta ` json:"metadata,omitempty"` Items []Obzev0Resource `json:"items"` } diff --git a/controller/api/v1/zz_generated.deepcopy.go b/controller/api/v1/zz_generated.deepcopy.go index b9de90e..dcab3d3 100644 --- a/controller/api/v1/zz_generated.deepcopy.go +++ b/controller/api/v1/zz_generated.deepcopy.go @@ -86,7 +86,7 @@ func (in *Obzev0ResourceList) DeepCopyObject() runtime.Object { // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *Obzev0ResourceSpec) DeepCopyInto(out *Obzev0ResourceSpec) { *out = *in - out.Config = in.Config + out.LatencyServiceConfig = in.LatencyServiceConfig } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Obzev0ResourceSpec. diff --git a/controller/config/crd/bases/batch.github.com_obzev0resources.yaml b/controller/config/crd/bases/batch.github.com_obzev0resources.yaml index 6885694..6286203 100644 --- a/controller/config/crd/bases/batch.github.com_obzev0resources.yaml +++ b/controller/config/crd/bases/batch.github.com_obzev0resources.yaml @@ -39,7 +39,7 @@ spec: spec: description: Obzev0ResourceSpec defines the desired state of Obzev0Resource properties: - config: + latencySvcConfig: description: Foo is an example field of Obzev0Resource. Edit obzev0resource_types.go to remove/update properties: @@ -58,6 +58,11 @@ spec: description: TCP server address type: string type: object + tcAnalyserSvcConfig: + properties: + netIFace: + type: string + type: object type: object status: description: Obzev0ResourceStatus defines the observed state of Obzev0Resource diff --git a/controller/config/manager/kustomization.yaml b/controller/config/manager/kustomization.yaml index 633dcb7..5d52359 100644 --- a/controller/config/manager/kustomization.yaml +++ b/controller/config/manager/kustomization.yaml @@ -5,4 +5,4 @@ kind: Kustomization images: - name: controller newName: lumbrjx/obzev0poc - newTag: 1.0.4 + newTag: 1.0.5-alpha diff --git a/controller/config/samples/batch_v1_obzev0resource.yaml b/controller/config/samples/batch_v1_obzev0resource.yaml index bf97a80..58fc077 100644 --- a/controller/config/samples/batch_v1_obzev0resource.yaml +++ b/controller/config/samples/batch_v1_obzev0resource.yaml @@ -6,11 +6,15 @@ metadata: app.kubernetes.io/managed-by: kustomize name: obzev0resource-sample spec: - config: - reqDelay: 10 - resDelay: 20 + latencySvcConfig: + reqDelay: 0 + resDelay: 0 server: "7090" client: "8080" + tcAnalyserSvcConfig: + netIFace: "eth0" + + status: message: "Server started successfully" diff --git a/controller/go.mod b/controller/go.mod index 6b7a783..97bd97e 100644 --- a/controller/go.mod +++ b/controller/go.mod @@ -16,6 +16,7 @@ require ( require ( github.com/antlr/antlr4/runtime/Go/antlr/v4 v4.0.0-20230305170008-8188dc5388df // indirect + github.com/envoyproxy/protoc-gen-validate v1.0.4 // indirect k8s.io/apiserver v0.30.2 // indirect ) diff --git a/controller/go.sum b/controller/go.sum index 1748cd8..7942446 100644 --- a/controller/go.sum +++ b/controller/go.sum @@ -13,6 +13,8 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/emicklei/go-restful/v3 v3.12.1 h1:PJMDIM/ak7btuL8Ex0iYET9hxM3CI2sjZtzpL63nKAU= github.com/emicklei/go-restful/v3 v3.12.1/go.mod h1:6n3XBCmQQb25CM2LCACGz8ukIrRry+4bhvbpWn3mrbc= +github.com/envoyproxy/protoc-gen-validate v1.0.4 h1:gVPz/FMfvh57HdSJQyvBtF00j8JU4zdyUgIUNhlgg0A= +github.com/envoyproxy/protoc-gen-validate v1.0.4/go.mod h1:qys6tmnRsYrQqIhm2bvKZH4Blx/1gTIZ2UKVY1M+Yew= github.com/evanphx/json-patch v4.12.0+incompatible h1:4onqiflcdA9EOZ4RxV643DvftH5pOlLGNtQ5lPWQu84= github.com/evanphx/json-patch v4.12.0+incompatible/go.mod h1:50XU6AFN0ol/bzJsmQLiYLvXMP4fmwYFNcr97nuDLSk= github.com/evanphx/json-patch/v5 v5.9.0 h1:kcBlZQbplgElYIlo/n1hJbls2z/1awpXxpRi0/FOJfg= diff --git a/controller/internal/controller/obzev0resource_controller.go b/controller/internal/controller/obzev0resource_controller.go index cd9c283..7cc209d 100644 --- a/controller/internal/controller/obzev0resource_controller.go +++ b/controller/internal/controller/obzev0resource_controller.go @@ -9,6 +9,7 @@ import ( "obzev0/common/proto/latency" pb "obzev0/common/proto/latency" + tca "obzev0/common/proto/tcAnalyser" v1 "obzev0/controller/api/v1" @@ -148,27 +149,42 @@ func handleAdd(obj interface{}, conn *grpc.ClientConn) { name := obz.GetName() namespace := obz.GetNamespace() - config := obz.Spec.Config + latencyConfig := obz.Spec.LatencyServiceConfig + tcAConfig := obz.Spec.TcAnalyserServiceConfig klog.Infof("Custom Resource added: %s/%s", namespace, name) - klog.Infof("TCP Server Configuration: %+v", config) + klog.Infof("TCP Server Configuration: %+v", latencyConfig) client := pb.NewLatencyServiceClient(conn) ctx, cancel := context.WithTimeout(context.Background(), time.Second*10) defer cancel() response, err := client.StartTcpServer( ctx, &pb.RequestForTcp{Config: &latency.TcpConfig{ - ReqDelay: config.ReqDelay, - ResDelay: config.ResDelay, - Server: config.Server, - Client: config.Client, + ReqDelay: latencyConfig.ReqDelay, + ResDelay: latencyConfig.ResDelay, + Server: latencyConfig.Server, + Client: latencyConfig.Client, }}, ) + if err != nil { log.Printf("Error calling gRPC method: %v\n", err) } else { fmt.Printf("Response from gRPC server: %s\n", response.Message) } + client2 := tca.NewTcAnalyserServiceClient(conn) + rsp, err := client2.StartUserSpace( + ctx, + &tca.RequestForUserSpace{Config: &tca.TcConfig{ + Interface: tcAConfig.NetIFace, + }}, + ) + + if err != nil { + log.Printf("Error calling gRPC method: %v\n", err) + } else { + fmt.Printf("Response from gRPC server: %s\n", rsp.Message) + } defer conn.Close() } diff --git a/controller/pkg/client/clientset/versioned/clientset.go b/controller/pkg/client/clientset/versioned/clientset.go deleted file mode 100644 index b84dbb0..0000000 --- a/controller/pkg/client/clientset/versioned/clientset.go +++ /dev/null @@ -1,18 +0,0 @@ -/* -Copyright 2024. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ -// Code generated by client-gen. DO NOT EDIT. - -package versioned diff --git a/controller/pkg/client/clientset/versioned/doc.go b/controller/pkg/client/clientset/versioned/doc.go deleted file mode 100644 index 980ac30..0000000 --- a/controller/pkg/client/clientset/versioned/doc.go +++ /dev/null @@ -1,19 +0,0 @@ -/* -Copyright 2024. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ -// Code generated by client-gen. DO NOT EDIT. - -// This package has the automatically generated clientset. -package versioned diff --git a/controller/pkg/client/clientset/versioned/fake/clientset_generated.go b/controller/pkg/client/clientset/versioned/fake/clientset_generated.go deleted file mode 100644 index cce90c0..0000000 --- a/controller/pkg/client/clientset/versioned/fake/clientset_generated.go +++ /dev/null @@ -1,18 +0,0 @@ -/* -Copyright 2024. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ -// Code generated by client-gen. DO NOT EDIT. - -package fake diff --git a/controller/pkg/client/clientset/versioned/fake/doc.go b/controller/pkg/client/clientset/versioned/fake/doc.go deleted file mode 100644 index 57c8c1b..0000000 --- a/controller/pkg/client/clientset/versioned/fake/doc.go +++ /dev/null @@ -1,19 +0,0 @@ -/* -Copyright 2024. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ -// Code generated by client-gen. DO NOT EDIT. - -// This package has the automatically generated fake clientset. -package fake diff --git a/controller/pkg/client/clientset/versioned/fake/register.go b/controller/pkg/client/clientset/versioned/fake/register.go deleted file mode 100644 index cce90c0..0000000 --- a/controller/pkg/client/clientset/versioned/fake/register.go +++ /dev/null @@ -1,18 +0,0 @@ -/* -Copyright 2024. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ -// Code generated by client-gen. DO NOT EDIT. - -package fake diff --git a/controller/pkg/client/clientset/versioned/scheme/doc.go b/controller/pkg/client/clientset/versioned/scheme/doc.go deleted file mode 100644 index b00a2a6..0000000 --- a/controller/pkg/client/clientset/versioned/scheme/doc.go +++ /dev/null @@ -1,19 +0,0 @@ -/* -Copyright 2024. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ -// Code generated by client-gen. DO NOT EDIT. - -// This package contains the scheme of the automatically generated clientset. -package scheme diff --git a/controller/pkg/client/clientset/versioned/scheme/register.go b/controller/pkg/client/clientset/versioned/scheme/register.go deleted file mode 100644 index 942fefc..0000000 --- a/controller/pkg/client/clientset/versioned/scheme/register.go +++ /dev/null @@ -1,18 +0,0 @@ -/* -Copyright 2024. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ -// Code generated by client-gen. DO NOT EDIT. - -package scheme diff --git a/controller/pkg/client/clientset/versioned/typed/batch.github.com/v1/batch.github.com_client.go b/controller/pkg/client/clientset/versioned/typed/batch.github.com/v1/batch.github.com_client.go deleted file mode 100644 index ec7f672..0000000 --- a/controller/pkg/client/clientset/versioned/typed/batch.github.com/v1/batch.github.com_client.go +++ /dev/null @@ -1,18 +0,0 @@ -/* -Copyright 2024. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ -// Code generated by client-gen. DO NOT EDIT. - -package v1 diff --git a/controller/pkg/client/clientset/versioned/typed/batch.github.com/v1/doc.go b/controller/pkg/client/clientset/versioned/typed/batch.github.com/v1/doc.go deleted file mode 100644 index 035a225..0000000 --- a/controller/pkg/client/clientset/versioned/typed/batch.github.com/v1/doc.go +++ /dev/null @@ -1,19 +0,0 @@ -/* -Copyright 2024. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ -// Code generated by client-gen. DO NOT EDIT. - -// This package has the automatically generated typed clients. -package v1 diff --git a/controller/pkg/client/clientset/versioned/typed/batch.github.com/v1/fake/doc.go b/controller/pkg/client/clientset/versioned/typed/batch.github.com/v1/fake/doc.go deleted file mode 100644 index 3514f7d..0000000 --- a/controller/pkg/client/clientset/versioned/typed/batch.github.com/v1/fake/doc.go +++ /dev/null @@ -1,19 +0,0 @@ -/* -Copyright 2024. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ -// Code generated by client-gen. DO NOT EDIT. - -// Package fake has the automatically generated clients. -package fake diff --git a/controller/pkg/client/clientset/versioned/typed/batch.github.com/v1/fake/fake_batch.github.com_client.go b/controller/pkg/client/clientset/versioned/typed/batch.github.com/v1/fake/fake_batch.github.com_client.go deleted file mode 100644 index cce90c0..0000000 --- a/controller/pkg/client/clientset/versioned/typed/batch.github.com/v1/fake/fake_batch.github.com_client.go +++ /dev/null @@ -1,18 +0,0 @@ -/* -Copyright 2024. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ -// Code generated by client-gen. DO NOT EDIT. - -package fake diff --git a/controller/pkg/client/clientset/versioned/typed/batch.github.com/v1/generated_expansion.go b/controller/pkg/client/clientset/versioned/typed/batch.github.com/v1/generated_expansion.go deleted file mode 100644 index ec7f672..0000000 --- a/controller/pkg/client/clientset/versioned/typed/batch.github.com/v1/generated_expansion.go +++ /dev/null @@ -1,18 +0,0 @@ -/* -Copyright 2024. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ -// Code generated by client-gen. DO NOT EDIT. - -package v1 diff --git a/daemon/api/grpc/tcAnalyser/service.go b/daemon/api/grpc/tcAnalyser/service.go index 2bfcf33..adfd0f1 100644 --- a/daemon/api/grpc/tcAnalyser/service.go +++ b/daemon/api/grpc/tcAnalyser/service.go @@ -17,7 +17,7 @@ type TcAnalyserService struct { // metricsChan chan MetricsData } -func (s *TcAnalyserService) StartTcpServer( +func (s *TcAnalyserService) StartUserSpace( ctx context.Context, requestUserSpace *tcAnalyser.RequestForUserSpace, ) (*tcAnalyser.ResponseFromUserSpace, error) { diff --git a/daemon/cmd/cli/main.go b/daemon/cmd/cli/main.go index eb942e5..1d5d1cc 100644 --- a/daemon/cmd/cli/main.go +++ b/daemon/cmd/cli/main.go @@ -5,7 +5,7 @@ import ( "fmt" "log" "obzev0/common/definitions" - "obzev0/common/proto/latency" + "obzev0/common/proto/tcAnalyser" "os" "time" @@ -38,27 +38,31 @@ func main() { log.Fatalf("did not connect: %v", err) } defer conn.Close() - c := latency.NewLatencyServiceClient(conn) + // c := latency.NewLatencyServiceClient(conn) + t := tcAnalyser.NewTcAnalyserServiceClient(conn) - cnf, err := LoadConfig("obzevConf.yaml") - config := &latency.TcpConfig{ - ReqDelay: cnf.Delays.ReqDelay, - ResDelay: cnf.Delays.ResDelay, - Server: cnf.Server.Port, - Client: cnf.Client.Port, - } - println( - config.Client, - config.Server, - config.ResDelay, - config.ReqDelay, - ) + // cnf, err := LoadConfig("obzevConf.yaml") + // config := &latency.TcpConfig{ + // ReqDelay: cnf.Delays.ReqDelay, + // ResDelay: cnf.Delays.ResDelay, + // Server: cnf.Server.Port, + // Client: cnf.Client.Port, + // } + // println( + // config.Client, + // config.Server, + // config.ResDelay, + // config.ReqDelay, + // ) - req := &latency.RequestForTcp{Config: config} + req2 := &tcAnalyser.RequestForUserSpace{ + Config: &tcAnalyser.TcConfig{Interface: "eth0"}, + } + // req := &latency.RequestForTcp{Config: &la} ctx, cancel := context.WithTimeout(context.Background(), time.Second) defer cancel() - res, err := c.StartTcpServer(ctx, req) + res, err := t.StartUserSpace(ctx, req2) if err != nil { log.Fatalf("could not greet: %v", err) } diff --git a/daemonset.yaml b/daemonset.yaml index 72e8630..b7c8ece 100644 --- a/daemonset.yaml +++ b/daemonset.yaml @@ -13,7 +13,7 @@ spec: spec: containers: - name: grpc-server - image: lumbrjx/obzev0-grpc-daemon:1.0.8-alpha + image: lumbrjx/obzev0-grpc-daemon:1.0.8-pre ports: - containerPort: 50051 livenessProbe: @@ -33,6 +33,14 @@ spec: requests: cpu: 250m memory: 64Mi + securityContext: + capabilities: + add: ["SYS_RESOURCE", "SYS_ADMIN"] + runAsUser: 0 + runAsGroup: 0 + privileged: true + allowPrivilegeEscalation: true + readOnlyRootFilesystem: false nodeSelector: node-role.kubernetes.io/worker: "" tolerations: @@ -57,7 +65,4 @@ spec: - key: "node.kubernetes.io/unschedulable" operator: "Exists" effect: "NoSchedule" -# kubectl label node kind-worker node-role.kubernetes.io/worker= -# kubectl label node kind-worker2 node-role.kubernetes.io/worker= -# kubectl label node kind-worker3 node-role.kubernetes.io/worker= -# + From 6bd9691bf517ea736791e50dd63558f05d59aff5 Mon Sep 17 00:00:00 2001 From: lumbrjx Date: Fri, 30 Aug 2024 22:37:14 +0100 Subject: [PATCH 4/4] BugFix :bug: Fix Linux Headers Compatibility --- daemon/api/grpc/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/daemon/api/grpc/Dockerfile b/daemon/api/grpc/Dockerfile index 416dc58..124592d 100644 --- a/daemon/api/grpc/Dockerfile +++ b/daemon/api/grpc/Dockerfile @@ -36,7 +36,7 @@ RUN apt-get update && \ clang \ llvm \ libelf-dev \ - linux-headers-$(uname -r) \ + linux-headers-6.1.0-22-amd64 \ build-essential \ iproute2 \ libbpf-dev \