libnet: create DNS records on sbJoin (if not agent node)
| ... | ... |
@@ -348,10 +348,8 @@ func (sb *Sandbox) populateNetworkResources(ctx context.Context, ep *Endpoint) ( |
| 348 | 348 |
|
| 349 | 349 |
// Populate DNS records. |
| 350 | 350 |
n := ep.getNetwork() |
| 351 |
- if !n.getController().isAgent() {
|
|
| 352 |
- if !n.getController().isSwarmNode() || n.Scope() != scope.Swarm || !n.driverIsMultihost() {
|
|
| 353 |
- n.updateSvcRecord(context.WithoutCancel(ctx), ep, true) |
|
| 354 |
- } |
|
| 351 |
+ if !n.getController().isSwarmNode() || n.Scope() != scope.Swarm || !n.driverIsMultihost() {
|
|
| 352 |
+ n.updateSvcRecord(context.WithoutCancel(ctx), ep, true) |
|
| 355 | 353 |
} |
| 356 | 354 |
|
| 357 | 355 |
if err := ep.addDriverInfoToCluster(); err != nil {
|
| ... | ... |
@@ -1092,7 +1092,7 @@ func TestDisableIPv6OnInterface(t *testing.T) {
|
| 1092 | 1092 |
// There should not be an IPv6 DNS or /etc/hosts entry. |
| 1093 | 1093 |
runRes := container.RunAttach(ctx, t, c, |
| 1094 | 1094 |
container.WithNetworkMode(tc.netName), |
| 1095 |
- container.WithCmd("ping", "-6", ctrName),
|
|
| 1095 |
+ container.WithCmd("ping", "-6", "-c1", ctrName),
|
|
| 1096 | 1096 |
) |
| 1097 | 1097 |
assert.Check(t, is.Equal(runRes.ExitCode, 1)) |
| 1098 | 1098 |
assert.Check(t, is.Contains(runRes.Stderr.String(), "bad address")) |
| ... | ... |
@@ -2032,3 +2032,29 @@ func TestLegacyLinksEnvVars(t *testing.T) {
|
| 2032 | 2032 |
}) |
| 2033 | 2033 |
} |
| 2034 | 2034 |
} |
| 2035 |
+ |
|
| 2036 |
+// TestDNSNamesForNonSwarmScopedNetworks checks that container names can be resolved for non-swarm-scoped networks once |
|
| 2037 |
+// a node has joined a Swarm cluster. |
|
| 2038 |
+// |
|
| 2039 |
+// Regression test for https://github.com/moby/moby/issues/51491. |
|
| 2040 |
+func TestDNSNamesForNonSwarmScopedNetworks(t *testing.T) {
|
|
| 2041 |
+ ctx := setupTest(t) |
|
| 2042 |
+ |
|
| 2043 |
+ d := daemon.New(t) |
|
| 2044 |
+ d.StartAndSwarmInit(ctx, t) |
|
| 2045 |
+ defer d.Stop(t) |
|
| 2046 |
+ |
|
| 2047 |
+ c := d.NewClientT(t) |
|
| 2048 |
+ defer c.Close() |
|
| 2049 |
+ |
|
| 2050 |
+ const bridgeName = "dnsnames-with-swarm" |
|
| 2051 |
+ network.CreateNoError(ctx, t, c, bridgeName) |
|
| 2052 |
+ defer network.RemoveNoError(ctx, t, c, bridgeName) |
|
| 2053 |
+ |
|
| 2054 |
+ res := container.RunAttach(ctx, t, c, |
|
| 2055 |
+ container.WithName("test"),
|
|
| 2056 |
+ container.WithCmd("nslookup", "-type=a", "test."),
|
|
| 2057 |
+ container.WithNetworkMode(bridgeName), |
|
| 2058 |
+ container.WithAutoRemove) |
|
| 2059 |
+ assert.Equal(t, res.ExitCode, 0, "exit code: %d, expected 0; stdout:\n%s", res.ExitCode, res.Stdout) |
|
| 2060 |
+} |