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

[Enhancement] Api port #75

Merged
merged 9 commits into from
Jun 6, 2019
Merged

[Enhancement] Api port #75

merged 9 commits into from
Jun 6, 2019

Conversation

andyz-dev
Copy link
Contributor

Add support for --api-port to take [host]:port as argument.

--api-port only takes the port as argument. This patch modifies it to
take a string argument, in the form of host:port.
The APIs of createServer() and createWorker() takes too many arguments.
It is getting harder to maintain.

Use a new struct ClusterSpec to make API simpler. This also reduces
some code duplications.
Now that --api-port takes a string argument, add a parser function to
handle error checking for this argument.
Pass the apiPort sturct directly via ClusterSpec.
To allow some flexibilities in how user specifies the --api-port
argument.  In case the 'host' is an string, We will try to convert
it into an IP address for port mapping. IP address is also allowed.
Copy link
Member

@iwilltry42 iwilltry42 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great! LGTM

cli/commands.go Outdated

// When the 'host' is not provided by --api-port, try to fill it using Docker Machine's IP address.
if apiPort.Host == "" {
if apiPort.Host, err = getDockerMachineIp(); apiPort.Host != "" || err != nil {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the reason for having apiPort.Host != "" in this condiftional? There's no action if this is true, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right. I have refactored code and forgot to remove this check. The line below should also be removed. Will fix before merge. Thanks for catching it!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated.

@@ -20,6 +20,20 @@ import (
"github.com/docker/docker/client"
)

type ClusterSpec struct {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe at some point we can add a new level here for server and agents, if we add more options?
E.g. you would call the server args via clusterSpec["server"].Args
Achieved by a new struct for ServerSpec and one for AgentSpec and embedding them into the ClusterSpec struct.
WDYT?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see your view point and agree that we should consider this approach down the road.

Right now, both server and agent share a lot of information, the clusterSpec is a simple union of serverSpec and agentSpec. It seems to be a good abstraction. At the same time, I do not oppose the way you have suggested.

Based on review comments from @iwilltry42
@andyz-dev andyz-dev merged commit 8a59078 into k3d-io:master Jun 6, 2019
@andyz-dev andyz-dev deleted the api-port branch June 6, 2019 13:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants