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

fixup server address when port is not present #896

Merged
merged 2 commits into from
Apr 7, 2023
Merged
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
6 changes: 3 additions & 3 deletions cmd/tetragon/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -457,10 +457,10 @@ func startExporter(ctx context.Context, server *server.Server) error {
return nil
}

func Serve(ctx context.Context, listenAddr string, server *server.Server) error {
func Serve(ctx context.Context, listenAddr string, srv *server.Server) error {
grpcServer := grpc.NewServer()
tetragon.RegisterFineGuidanceSensorsServer(grpcServer, server)
proto, addr, err := splitListenAddr(listenAddr)
tetragon.RegisterFineGuidanceSensorsServer(grpcServer, srv)
proto, addr, err := server.SplitListenAddr(listenAddr)
if err != nil {
return fmt.Errorf("failed to parse listen address: %w", err)
}
Expand Down
12 changes: 10 additions & 2 deletions cmd/tetragon/addr.go → pkg/server/addr.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package main
package server

import (
"fmt"
Expand All @@ -20,7 +20,7 @@ import (
// "ipv6" for tcp connections.
// Hence, because we want the same string to work the same way both on the client and the server, we
// only support the two addresses above.
func splitListenAddr(arg string) (string, string, error) {
func SplitListenAddr(arg string) (string, string, error) {

if strings.HasPrefix(arg, "unix://") {
path := strings.TrimPrefix(arg, "unix://")
Expand All @@ -30,6 +30,14 @@ func splitListenAddr(arg string) (string, string, error) {
return "unix", path, nil
}

// Some recent changes to the way we input the address string in Helm have introduced
// an unfortunate compatibility breakage with the old default values which did not
// include a port number in the address string. To provide backward compatibility
// here, let's just assume a default of `:54321` when the port is not present.
if !strings.Contains(arg, ":") {
arg += ":54321"
}

// assume everything else is TCP to support strings such as "localhost:51234" and let
// net.Listen figure things out.
return "tcp", arg, nil
Expand Down
12 changes: 8 additions & 4 deletions cmd/tetragon/addr_test.go → pkg/server/addr_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package main
package server

import "testing"

Expand All @@ -15,9 +15,13 @@ func TestSplitListenAddr(t *testing.T) {
proto: "unix",
addr: "/var/run/tetragon/tetragon.sock",
}, {
arg: "localhost:51234",
arg: "localhost:54321",
proto: "tcp",
addr: "localhost:51234",
addr: "localhost:54321",
}, {
arg: "localhost",
proto: "tcp",
addr: "localhost:54321",
}, {
// NB: expect error on relative paths
arg: "unix://var/run/tetragon/tetragon.sock",
Expand All @@ -26,7 +30,7 @@ func TestSplitListenAddr(t *testing.T) {
}

for _, c := range testCases {
proto, addr, err := splitListenAddr(c.arg)
proto, addr, err := SplitListenAddr(c.arg)
if c.expectedErr {
if err == nil {
t.Fatalf("expected error for %s", c.arg)
Expand Down