-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Allow custom ports for services and checks when using driver address_mode #3619
Merged
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
2556928
Allow custom ports for services and checks
schmichael 74e7d57
Test Consul from TaskRunner thoroughly
schmichael 29e6f7c
Fix interpolation bug with service/check updates
schmichael f2d4715
Document service/check address_mode/port changes
schmichael f11360a
Add `Using Driver Address Mode` docs
schmichael b999358
Validate port label for host address mode
schmichael fa5faa5
Prevent using port 0 with address_mode=driver
schmichael 7bf5cec
Improve port label validation and diff testing
schmichael 65bfbe5
Hash fields used in task service IDs
schmichael afd5bca
Move service hash logic to Service.Hash method
schmichael 6f124eb
Be more defensive in port checks
schmichael 4196360
Expand port and address_mode docs
schmichael 2a33e10
Improve validation and testing of service/check ports
schmichael e857225
Fix port labels on mock Alloc/Job/Node
schmichael 63d515d
Lowercase service IDs to prevent eye bleeding
schmichael b79194f
Fix test broken by mock updates
schmichael File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,7 @@ import ( | |
"log" | ||
"os" | ||
"strconv" | ||
"strings" | ||
"time" | ||
|
||
"github.com/mitchellh/mapstructure" | ||
|
@@ -61,6 +62,17 @@ type MockDriverConfig struct { | |
|
||
// SignalErr is the error message that the task returns if signalled | ||
SignalErr string `mapstructure:"signal_error"` | ||
|
||
// DriverIP will be returned as the DriverNetwork.IP from Start() | ||
DriverIP string `mapstructure:"driver_ip"` | ||
|
||
// DriverAdvertise will be returned as DriverNetwork.AutoAdvertise from | ||
// Start(). | ||
DriverAdvertise bool `mapstructure:"driver_advertise"` | ||
|
||
// DriverPortMap will parse a label:number pair and return it in | ||
// DriverNetwork.PortMap from Start(). | ||
DriverPortMap string `mapstructure:"driver_port_map"` | ||
} | ||
|
||
// MockDriver is a driver which is used for testing purposes | ||
|
@@ -114,6 +126,23 @@ func (m *MockDriver) Start(ctx *ExecContext, task *structs.Task) (*StartResponse | |
return nil, structs.NewRecoverableError(errors.New(driverConfig.StartErr), driverConfig.StartErrRecoverable) | ||
} | ||
|
||
// Create the driver network | ||
net := &cstructs.DriverNetwork{ | ||
IP: driverConfig.DriverIP, | ||
AutoAdvertise: driverConfig.DriverAdvertise, | ||
} | ||
if raw := driverConfig.DriverPortMap; len(raw) > 0 { | ||
parts := strings.Split(raw, ":") | ||
if len(parts) != 2 { | ||
return nil, fmt.Errorf("malformed port map: %q", raw) | ||
} | ||
port, err := strconv.Atoi(parts[1]) | ||
if err != nil { | ||
return nil, fmt.Errorf("malformed port map: %q -- error: %v", raw, err) | ||
} | ||
net.PortMap = map[string]int{parts[0]: port} | ||
} | ||
|
||
h := mockDriverHandle{ | ||
taskName: task.Name, | ||
runFor: driverConfig.RunFor, | ||
|
@@ -133,7 +162,8 @@ func (m *MockDriver) Start(ctx *ExecContext, task *structs.Task) (*StartResponse | |
} | ||
m.logger.Printf("[DEBUG] driver.mock: starting task %q", task.Name) | ||
go h.run() | ||
return &StartResponse{Handle: &h}, nil | ||
|
||
return &StartResponse{Handle: &h, Network: net}, nil | ||
} | ||
|
||
// Cleanup deletes all keys except for Config.Options["cleanup_fail_on"] for | ||
|
@@ -265,10 +295,20 @@ func (h *mockDriverHandle) Kill() error { | |
select { | ||
case <-h.doneCh: | ||
case <-time.After(h.killAfter): | ||
close(h.doneCh) | ||
select { | ||
case <-h.doneCh: | ||
// already closed | ||
default: | ||
close(h.doneCh) | ||
} | ||
case <-time.After(h.killTimeout): | ||
h.logger.Printf("[DEBUG] driver.mock: terminating task %q", h.taskName) | ||
close(h.doneCh) | ||
select { | ||
case <-h.doneCh: | ||
// already closed | ||
default: | ||
close(h.doneCh) | ||
} | ||
} | ||
return nil | ||
} | ||
|
@@ -286,7 +326,12 @@ func (h *mockDriverHandle) run() { | |
for { | ||
select { | ||
case <-timer.C: | ||
close(h.doneCh) | ||
select { | ||
case <-h.doneCh: | ||
// already closed | ||
default: | ||
close(h.doneCh) | ||
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. I ran into a double close panic on the mock driver when testing, so I guarded all of these closes. Not sure why we had never hit it before... |
||
} | ||
case <-h.doneCh: | ||
h.logger.Printf("[DEBUG] driver.mock: finished running task %q", h.taskName) | ||
h.waitCh <- dstructs.NewWaitResult(h.exitCode, h.exitSignal, h.exitErr) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
mock_driver
now supports DriverNetwork! I should have added this when I added DriverNetwork originally...