Commit 0ca7ac325 was merged before a review comment was addressed.
Update the warning message returned by handlePortBindingsBC to handle
the case where multiple empty port bindings slices are sent to the API.
Signed-off-by: Albin Kerouanton <albinker@gmail.com>
| ... | ... |
@@ -891,7 +891,7 @@ func handleSysctlBC( |
| 891 | 891 |
// See https://github.com/moby/moby/pull/50710#discussion_r2315840899 for more |
| 892 | 892 |
// context. |
| 893 | 893 |
func handlePortBindingsBC(hostConfig *container.HostConfig, version string) string {
|
| 894 |
- var warning string |
|
| 894 |
+ var emptyPBs []string |
|
| 895 | 895 |
|
| 896 | 896 |
for portProto, bindings := range hostConfig.PortBindings {
|
| 897 | 897 |
if len(bindings) > 0 {
|
| ... | ... |
@@ -909,13 +909,17 @@ func handlePortBindingsBC(hostConfig *container.HostConfig, version string) stri |
| 909 | 909 |
} |
| 910 | 910 |
|
| 911 | 911 |
if versions.Equal(version, "1.52") {
|
| 912 |
- warning = fmt.Sprintf("Container port %s has an empty list of port-bindings. Starting with API 1.53, this will be discarded.", portProto)
|
|
| 912 |
+ emptyPBs = append(emptyPBs, string(portProto)) |
|
| 913 | 913 |
} |
| 914 | 914 |
|
| 915 | 915 |
hostConfig.PortBindings[portProto] = []nat.PortBinding{{}}
|
| 916 | 916 |
} |
| 917 | 917 |
|
| 918 |
- return warning |
|
| 918 |
+ if len(emptyPBs) > 0 {
|
|
| 919 |
+ return fmt.Sprintf("Following container port(s) have an empty list of port-bindings: %s. Starting with API 1.53, such bindings will be discarded.", strings.Join(emptyPBs, ", "))
|
|
| 920 |
+ } |
|
| 921 |
+ |
|
| 922 |
+ return "" |
|
| 919 | 923 |
} |
| 920 | 924 |
|
| 921 | 925 |
// epConfigForNetMode finds, or creates, an entry in netConfig.EndpointsConfig |
| ... | ... |
@@ -993,7 +993,7 @@ func TestEmptyPortBindingsBC(t *testing.T) {
|
| 993 | 993 |
{}, // An empty PortBinding is backfilled
|
| 994 | 994 |
}} |
| 995 | 995 |
expWarnings := []string{
|
| 996 |
- "Container port 80/tcp has an empty list of port-bindings. Starting with API 1.53, this will be discarded.", |
|
| 996 |
+ "Following container port(s) have an empty list of port-bindings: 80/tcp. Starting with API 1.53, such bindings will be discarded.", |
|
| 997 | 997 |
} |
| 998 | 998 |
|
| 999 | 999 |
mappings, warnings := createInspect(t, "1.52", []nat.PortBinding{})
|