Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added grpc binary to dockerfile #24

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions relay-server/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,15 @@ WORKDIR /usr/src/kubearmor-relay-server
COPY . .

RUN cd relay-server && make
RUN GRPC_HEALTH_PROBE_VERSION=v0.4.15 && \
wget -qO/bin/grpc_health_probe https://github.com/grpc-ecosystem/grpc-health-probe/releases/download/${GRPC_HEALTH_PROBE_VERSION}/grpc_health_probe-linux-amd64 && \
chmod +x /bin/grpc_health_probe

### Copy executable image

FROM alpine:3.14

COPY --from=builder /usr/src/kubearmor-relay-server/relay-server/kubearmor-relay-server /KubeArmor/kubearmor-relay-server
COPY --from=builder /bin/grpc_health_probe ./grpc_health_probe

ENTRYPOINT ["/KubeArmor/kubearmor-relay-server"]
31 changes: 27 additions & 4 deletions relay-server/server/relayServer.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"context"
"encoding/json"
"fmt"
"google.golang.org/grpc/health/grpc_health_v1"
"math/rand"
"net"
"sync"
Expand Down Expand Up @@ -510,6 +511,24 @@ func (lc *LogClient) DestroyClient() error {
return nil
}

type HealthChecker struct{}

func (s *HealthChecker) Check(ctx context.Context, req *grpc_health_v1.HealthCheckRequest) (*grpc_health_v1.HealthCheckResponse, error) {

kg.Print("Serving the Check request for health check")

return &grpc_health_v1.HealthCheckResponse{
Status: grpc_health_v1.HealthCheckResponse_SERVING,
}, nil
}

func (s *HealthChecker) Watch(req *grpc_health_v1.HealthCheckRequest, server grpc_health_v1.Health_WatchServer) error {
kg.Print("Serving the Watch request for health check")
return server.Send(&grpc_health_v1.HealthCheckResponse{
Status: grpc_health_v1.HealthCheckResponse_SERVING,
})
}

// ================== //
// == Relay Server == //
// ================== //
Expand All @@ -523,7 +542,7 @@ type RelayServer struct {
Listener net.Listener

// log server
LogServer *grpc.Server
Server *grpc.Server

// wait group
WgServer sync.WaitGroup
Expand Down Expand Up @@ -553,11 +572,15 @@ func NewRelayServer(port string) *RelayServer {
}

// create a log server
rs.LogServer = grpc.NewServer(grpc.KeepaliveEnforcementPolicy(kaep), grpc.KeepaliveParams(kasp))
rs.Server = grpc.NewServer(grpc.KeepaliveEnforcementPolicy(kaep), grpc.KeepaliveParams(kasp))

// register a log service
logService := &LogService{}
pb.RegisterLogServiceServer(rs.LogServer, logService)
pb.RegisterLogServiceServer(rs.Server, logService)

//register health checker
healthService := &HealthChecker{}
grpc_health_v1.RegisterHealthServer(rs.Server, healthService)

// initialize msg structs
MsgStructs = make(map[string]MsgStruct)
Expand Down Expand Up @@ -609,7 +632,7 @@ func (rs *RelayServer) ServeLogFeeds() {
defer rs.WgServer.Done()

// feed logs
if err := rs.LogServer.Serve(rs.Listener); err != nil {
if err := rs.Server.Serve(rs.Listener); err != nil {
kg.Print("Terminated the gRPC service")
}
}
Expand Down