mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Miscellaneous fixes
- Fix npe in sbJoin error path
- Fail again endpoint Join in case of failure
in programming the external connectivity
- In bridge, look for parent and child container configs
in the generic data
- iptables.Exists() might be called before any other call to
iptables.raw(). We need to call checkInit() then.
Introduced by 1638fbdf27
Signed-off-by: Alessandro Boch <aboch@docker.com>
This commit is contained in:
parent
d60c3bed51
commit
8cf7270d06
5 changed files with 38 additions and 31 deletions
|
@ -1362,28 +1362,24 @@ func parseContainerOptions(cOptions map[string]interface{}) (*containerConfigura
|
|||
if cOptions == nil {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
cc := &containerConfiguration{}
|
||||
|
||||
if opt, ok := cOptions[ParentEndpoints]; ok {
|
||||
if pe, ok := opt.([]string); ok {
|
||||
cc.ParentEndpoints = pe
|
||||
} else {
|
||||
return nil, types.BadRequestErrorf("Invalid parent endpoints data in sandbox configuration: %v", opt)
|
||||
genericData := cOptions[netlabel.GenericData]
|
||||
if genericData == nil {
|
||||
return nil, nil
|
||||
}
|
||||
switch opt := genericData.(type) {
|
||||
case options.Generic:
|
||||
opaqueConfig, err := options.GenerateFromModel(opt, &containerConfiguration{})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if opt, ok := cOptions[ChildEndpoints]; ok {
|
||||
if ce, ok := opt.([]string); ok {
|
||||
cc.ChildEndpoints = ce
|
||||
} else {
|
||||
return nil, types.BadRequestErrorf("Invalid child endpoints data in sandbox configuration: %v", opt)
|
||||
return opaqueConfig.(*containerConfiguration), nil
|
||||
case *containerConfiguration:
|
||||
return opt, nil
|
||||
default:
|
||||
return nil, nil
|
||||
}
|
||||
}
|
||||
|
||||
return cc, nil
|
||||
}
|
||||
|
||||
func parseConnectivityOptions(cOptions map[string]interface{}) (*connectivityConfiguration, error) {
|
||||
if cOptions == nil {
|
||||
return nil, nil
|
||||
|
|
|
@ -10,6 +10,7 @@ import (
|
|||
"github.com/docker/libnetwork/ipamutils"
|
||||
"github.com/docker/libnetwork/iptables"
|
||||
"github.com/docker/libnetwork/netlabel"
|
||||
"github.com/docker/libnetwork/options"
|
||||
"github.com/docker/libnetwork/testutils"
|
||||
"github.com/docker/libnetwork/types"
|
||||
)
|
||||
|
@ -599,7 +600,9 @@ func TestLinkContainers(t *testing.T) {
|
|||
}
|
||||
|
||||
sbOptions = make(map[string]interface{})
|
||||
sbOptions[ChildEndpoints] = []string{"ep1"}
|
||||
sbOptions[netlabel.GenericData] = options.Generic{
|
||||
"ChildEndpoints": []string{"ep1"},
|
||||
}
|
||||
|
||||
err = d.Join("net1", "ep2", "", te2, sbOptions)
|
||||
if err != nil {
|
||||
|
@ -655,7 +658,9 @@ func TestLinkContainers(t *testing.T) {
|
|||
|
||||
// Error condition test with an invalid endpoint-id "ep4"
|
||||
sbOptions = make(map[string]interface{})
|
||||
sbOptions[ChildEndpoints] = []string{"ep1", "ep4"}
|
||||
sbOptions[netlabel.GenericData] = options.Generic{
|
||||
"ChildEndpoints": []string{"ep1", "ep4"},
|
||||
}
|
||||
|
||||
err = d.Join("net1", "ep2", "", te2, sbOptions)
|
||||
if err != nil {
|
||||
|
|
|
@ -15,10 +15,4 @@ const (
|
|||
|
||||
// DefaultBridge label
|
||||
DefaultBridge = "com.docker.network.bridge.default_bridge"
|
||||
|
||||
// ChildEndpoints for links
|
||||
ChildEndpoints = "com.docker.network.bridge.child_endpoints"
|
||||
|
||||
// ParentEndpoints for links
|
||||
ParentEndpoints = "com.docker.network.bridge.parent_endpoints"
|
||||
)
|
||||
|
|
|
@ -455,16 +455,26 @@ func (ep *endpoint) sbJoin(sb *sandbox, options ...EndpointOption) error {
|
|||
if moveExtConn {
|
||||
if extEp != nil {
|
||||
log.Debugf("Revoking external connectivity on endpoint %s (%s)", extEp.Name(), extEp.ID())
|
||||
if err := d.RevokeExternalConnectivity(extEp.network.ID(), extEp.ID()); err != nil {
|
||||
log.Warnf("driver failed revoking external connectivity on endpoint %s (%s): %v",
|
||||
if err = d.RevokeExternalConnectivity(extEp.network.ID(), extEp.ID()); err != nil {
|
||||
return types.InternalErrorf(
|
||||
"driver failed revoking external connectivity on endpoint %s (%s): %v",
|
||||
extEp.Name(), extEp.ID(), err)
|
||||
}
|
||||
defer func() {
|
||||
if err != nil {
|
||||
if e := d.ProgramExternalConnectivity(extEp.network.ID(), extEp.ID(), sb.Labels()); e != nil {
|
||||
log.Warnf("Failed to roll-back external connectivity on endpoint %s (%s): %v",
|
||||
extEp.Name(), extEp.ID(), e)
|
||||
}
|
||||
}
|
||||
}()
|
||||
}
|
||||
if !n.internal {
|
||||
log.Debugf("Programming external connectivity on endpoint %s (%s)", ep.Name(), ep.ID())
|
||||
if err := d.ProgramExternalConnectivity(n.ID(), ep.ID(), sb.Labels()); err != nil {
|
||||
log.Warnf("driver failed programming external connectivity on endpoint %s (%s): %v",
|
||||
extEp.Name(), extEp.ID(), err)
|
||||
if err = d.ProgramExternalConnectivity(n.ID(), ep.ID(), sb.Labels()); err != nil {
|
||||
return types.InternalErrorf(
|
||||
"driver failed programming external connectivity on endpoint %s (%s): %v",
|
||||
ep.Name(), ep.ID(), err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -582,7 +592,7 @@ func (ep *endpoint) sbLeave(sb *sandbox, force bool, options ...EndpointOption)
|
|||
if moveExtConn {
|
||||
log.Debugf("Revoking external connectivity on endpoint %s (%s)", ep.Name(), ep.ID())
|
||||
if err := d.RevokeExternalConnectivity(n.id, ep.id); err != nil {
|
||||
log.Warnf("driver failed removing external connectivity on endpoint %s (%s): %v",
|
||||
log.Warnf("driver failed revoking external connectivity on endpoint %s (%s): %v",
|
||||
ep.Name(), ep.ID(), err)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -306,6 +306,8 @@ func Exists(table Table, chain string, rule ...string) bool {
|
|||
table = Filter
|
||||
}
|
||||
|
||||
initCheck()
|
||||
|
||||
if supportsCOpt {
|
||||
// if exit status is 0 then return true, the rule exists
|
||||
_, err := Raw(append([]string{"-t", string(table), "-C", chain}, rule...)...)
|
||||
|
|
Loading…
Add table
Reference in a new issue