-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Add logic for finding next available port for gRPC if provided one is in use #1752
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,9 +18,12 @@ package event | |
|
||
import ( | ||
"context" | ||
"fmt" | ||
"net" | ||
|
||
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/constants" | ||
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/event/proto" | ||
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/util" | ||
|
||
empty "github.com/golang/protobuf/ptypes/empty" | ||
"github.com/pkg/errors" | ||
|
@@ -62,14 +65,19 @@ func (s *server) Handle(ctx context.Context, event *proto.Event) (*empty.Empty, | |
} | ||
|
||
// newStatusServer creates the grpc server for serving the state and event log. | ||
func newStatusServer(port string) (func() error, error) { | ||
if port == "" { | ||
func newStatusServer(originalPort int) (func() error, error) { | ||
if originalPort == -1 { | ||
return func() error { return nil }, nil | ||
} | ||
l, err := net.Listen("tcp", port) | ||
port := util.GetAvailablePort(originalPort) | ||
if port != originalPort && originalPort != constants.DefaultRPCPort { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. wouldn't port != constants.DefaultRPCPort suffice? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this logic is basically "if the user provided a different port than the skaffold default, but we couldn't use that port because it was already in use, warn them that we're using a different port than they might expect". if the user didn't provide a port, they probably don't care that skaffold didn't use its own default. the port being used will still be in the logs. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ah.. ok. |
||
logrus.Warnf("provided port %d already in use: using %d instead", originalPort, port) | ||
} | ||
l, err := net.Listen("tcp", fmt.Sprintf(":%d", port)) | ||
if err != nil { | ||
return func() error { return nil }, errors.Wrap(err, "creating listener") | ||
} | ||
logrus.Infof("starting gRPC server on port %d", port) | ||
|
||
s := grpc.NewServer() | ||
proto.RegisterSkaffoldServiceServer(s, &server{}) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see why this would be -1? i see its called here with default port 50051?
skaffold/pkg/skaffold/event/event.go
Line 103 in 80d0347
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this was for testing as a way to bypass creating an RPC server in some cases. I probably should have removed it.