Skip to content

Commit 5d20062

Browse files
committed
API: /info: remove BridgeNfIptables, BridgeNfIp6tables fields
The `BridgeNfIptables` and `BridgeNfIp6tables` fields in the `GET /info` response were deprecated in API v1.48, and are now omitted in API v1.49. With this patch, old API version continue to return the field: curl -s --unix-socket /var/run/docker.sock http://localhost/v1.48/info | jq .BridgeNfIp6tables false curl -s --unix-socket /var/run/docker.sock http://localhost/v1.48/info | jq .BridgeNfIptables false Omitting the field in API v1.49 and above curl -s --unix-socket /var/run/docker.sock http://localhost/v1.49/info | jq .BridgeNfIp6tables null curl -s --unix-socket /var/run/docker.sock http://localhost/v1.49/info | jq .BridgeNfIptables null Signed-off-by: Sebastiaan van Stijn <[email protected]>
1 parent 325076d commit 5d20062

5 files changed

Lines changed: 92 additions & 12 deletions

File tree

api/server/router/system/system_routes.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,13 @@ func (s *systemRouter) getInfo(ctx context.Context, w http.ResponseWriter, r *ht
122122
info.ContainerdCommit.Expected = info.ContainerdCommit.ID //nolint:staticcheck // ignore SA1019: field is deprecated, but still used on API < v1.49.
123123
info.RuncCommit.Expected = info.RuncCommit.ID //nolint:staticcheck // ignore SA1019: field is deprecated, but still used on API < v1.49.
124124
info.InitCommit.Expected = info.InitCommit.ID //nolint:staticcheck // ignore SA1019: field is deprecated, but still used on API < v1.49.
125+
126+
// These fields are omitted in > API 1.49, and always false
127+
// older API versions.
128+
info.ExtraFields = map[string]any{
129+
"BridgeNfIptables": json.RawMessage("false"),
130+
"BridgeNfIp6tables": json.RawMessage("false"),
131+
}
125132
}
126133
if versions.GreaterThanOrEqualTo(version, "1.42") {
127134
info.KernelMemory = false

api/types/system/info.go

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
1+
// FIXME(thaJeztah): remove once we are a module; the go:build directive prevents go from downgrading language version to go1.16:
2+
//go:build go1.22
3+
14
package system
25

36
import (
7+
"encoding/json"
8+
49
"github.com/docker/docker/api/types/container"
510
"github.com/docker/docker/api/types/registry"
611
"github.com/docker/docker/api/types/swarm"
@@ -29,8 +34,6 @@ type Info struct {
2934
CPUSet bool
3035
PidsLimit bool
3136
IPv4Forwarding bool
32-
BridgeNfIptables bool `json:"BridgeNfIptables"` // Deprecated: netfilter module is now loaded on-demand and no longer during daemon startup, making this field obsolete. This field is always false and will be removed in the next release.
33-
BridgeNfIP6tables bool `json:"BridgeNfIp6tables"` // Deprecated: netfilter module is now loaded on-demand and no longer during daemon startup, making this field obsolete. This field is always false and will be removed in the next release.
3437
Debug bool
3538
NFd int
3639
OomKillDisable bool
@@ -83,6 +86,26 @@ type Info struct {
8386
// messages for the user, and are not intended to be parsed / used for
8487
// other purposes, as they do not have a fixed format.
8588
Warnings []string
89+
90+
// ExtraFields is for internal use to include deprecated fields on older API versions.
91+
ExtraFields map[string]any `json:"-"`
92+
}
93+
94+
// MarshalJSON implements a custom marshaler to include legacy fields
95+
// in API responses.
96+
func (sc *Info) MarshalJSON() ([]byte, error) {
97+
type tmp Info
98+
base, err := json.Marshal((*tmp)(sc))
99+
if err != nil {
100+
return nil, err
101+
}
102+
var merged map[string]any
103+
_ = json.Unmarshal(base, &merged)
104+
105+
for k, v := range sc.ExtraFields {
106+
merged[k] = v
107+
}
108+
return json.Marshal(merged)
86109
}
87110

88111
// ContainerdInfo holds information about the containerd instance used by the daemon.

docs/api/version-history.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ keywords: "API, Docker, rcli, REST, documentation"
2929
* Deprecated: The `ContainerdCommit.Expected`, `RuncCommit.Expected`, and
3030
`InitCommit.Expected` fields in the `GET /info` endpoint were deprecated
3131
in API v1.48, and are now omitted in API v1.49.
32+
* Deprecated: The `BridgeNfIptables` and `BridgeNfIp6tables` fields in the
33+
`GET /info` response were deprecated in API v1.48, and are now omitted
34+
in API v1.49.
3235

3336
## v1.48 API changes
3437

integration/system/info_linux_test.go

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,13 @@
33
package system // import "github.com/docker/docker/integration/system"
44

55
import (
6+
"encoding/json"
7+
"io"
8+
"net/http"
69
"testing"
710

811
"github.com/docker/docker/client"
12+
"github.com/docker/docker/testutil/request"
913
"gotest.tools/v3/assert"
1014
is "gotest.tools/v3/assert/cmp"
1115
)
@@ -47,3 +51,56 @@ func TestInfoBinaryCommits(t *testing.T) {
4751
assert.Check(t, is.Equal(info.RuncCommit.Expected, info.RuncCommit.ID)) //nolint:staticcheck // ignore SA1019: field is deprecated, but still used on API < v1.49.
4852
})
4953
}
54+
55+
func TestInfoLegacyFields(t *testing.T) {
56+
ctx := setupTest(t)
57+
58+
const notPresent = "expected field to not be present"
59+
60+
tests := []struct {
61+
name string
62+
url string
63+
expectedFields map[string]any
64+
}{
65+
{
66+
name: "api v1.48 legacy bridge-nftables",
67+
url: "/v1.48/info",
68+
expectedFields: map[string]any{
69+
"BridgeNfIp6tables": false,
70+
"BridgeNfIptables": false,
71+
},
72+
},
73+
{
74+
name: "api v1.49 legacy bridge-nftables",
75+
url: "/v1.49/info",
76+
expectedFields: map[string]any{
77+
"BridgeNfIp6tables": notPresent,
78+
"BridgeNfIptables": notPresent,
79+
},
80+
},
81+
}
82+
for _, tc := range tests {
83+
t.Run(tc.name, func(t *testing.T) {
84+
res, _, err := request.Get(ctx, tc.url)
85+
assert.NilError(t, err)
86+
assert.Equal(t, res.StatusCode, http.StatusOK)
87+
body, err := io.ReadAll(res.Body)
88+
assert.NilError(t, err)
89+
90+
actual := map[string]any{}
91+
err = json.Unmarshal(body, &actual)
92+
assert.NilError(t, err, string(body))
93+
94+
for field, expectedValue := range tc.expectedFields {
95+
if expectedValue == notPresent {
96+
_, found := actual[field]
97+
assert.Assert(t, !found, "field %s should not be present", field)
98+
} else {
99+
_, found := actual[field]
100+
assert.Assert(t, found, "field %s should be present", field)
101+
assert.Check(t, is.DeepEqual(actual[field], expectedValue))
102+
}
103+
}
104+
})
105+
}
106+
}

pkg/sysinfo/sysinfo.go

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,6 @@ type SysInfo struct {
2424
// Whether IPv4 forwarding is supported or not, if this was disabled, networking will not work
2525
IPv4ForwardingDisabled bool
2626

27-
// Whether bridge-nf-call-iptables is supported or not
28-
//
29-
// Deprecated: netfilter module is now loaded on-demand and no longer during daemon startup, making this field obsolete. This field is always false and will be removed in the next release.
30-
BridgeNFCallIPTablesDisabled bool
31-
32-
// Whether bridge-nf-call-ip6tables is supported or not
33-
//
34-
// Deprecated: netfilter module is now loaded on-demand and no longer during daemon startup, making this field obsolete. This field is always false and will be removed in the next release.
35-
BridgeNFCallIP6TablesDisabled bool
36-
3727
// Whether the cgroup has the mountpoint of "devices" or not
3828
CgroupDevicesEnabled bool
3929

0 commit comments

Comments
 (0)