This repository has been archived by the owner on Jun 20, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 674
make proxy attach network on docker start event #1210
Merged
Merged
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
81e8ba2
Do network attach on docker event rather than intercepting start and …
bboreham 9ae6435
Attach existing weave containers at startup
bboreham b712ba1
Extend test to cover containers restarting automatically
bboreham 1e23443
Wait for container to be attached before returning from {re}start req…
bboreham 76895c7
Use Mutex instead of RWMutex, for simplicity
bboreham 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
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 |
---|---|---|
@@ -1,47 +1,24 @@ | ||
package proxy | ||
|
||
import ( | ||
"errors" | ||
"net/http" | ||
"strings" | ||
|
||
. "github.com/weaveworks/weave/common" | ||
) | ||
|
||
type startContainerInterceptor struct{ proxy *Proxy } | ||
|
||
func (i *startContainerInterceptor) InterceptRequest(r *http.Request) error { | ||
return nil | ||
container, err := inspectContainerInPath(i.proxy.client, r.URL.Path) | ||
if err == nil && containerShouldAttach(container) { | ||
i.proxy.createWait(r, container.ID) | ||
} | ||
return err | ||
} | ||
|
||
func (i *startContainerInterceptor) InterceptResponse(r *http.Response) error { | ||
defer i.proxy.removeWait(r.Request) | ||
if r.StatusCode < 200 || r.StatusCode >= 300 { // Docker didn't do the start | ||
return nil | ||
} | ||
|
||
container, err := inspectContainerInPath(i.proxy.client, r.Request.URL.Path) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
cidrs, err := i.proxy.weaveCIDRsFromConfig(container.Config, container.HostConfig) | ||
if err != nil { | ||
Log.Infof("Leaving container %s alone because %s", container.ID, err) | ||
return nil | ||
} | ||
Log.Infof("Attaching container %s with WEAVE_CIDR \"%s\" to weave network", container.ID, strings.Join(cidrs, " ")) | ||
args := []string{"attach"} | ||
args = append(args, cidrs...) | ||
if !i.proxy.NoRewriteHosts { | ||
args = append(args, "--rewrite-hosts") | ||
} | ||
args = append(args, "--or-die", container.ID) | ||
if _, stderr, err := callWeave(args...); err != nil { | ||
Log.Warningf("Attaching container %s to weave network failed: %s", container.ID, string(stderr)) | ||
return errors.New(string(stderr)) | ||
} else if len(stderr) > 0 { | ||
Log.Warningf("Attaching container %s to weave network: %s", container.ID, string(stderr)) | ||
} | ||
|
||
i.proxy.waitForStart(r.Request) | ||
return nil | ||
} |
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
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.
This comment was marked as abuse.
Sorry, something went wrong.
This comment was marked as abuse.
Sorry, something went wrong.
This comment was marked as abuse.
Sorry, something went wrong.