Skip to content

Commit 1aafb6f

Browse files
committed
Fix faulty json.Marshal behavior for embeds types.NetConf
Signed-off-by: Tomofumi Hayashi <[email protected]>
1 parent cebd7df commit 1aafb6f

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

pkg/types/types.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ func (n *IPNet) UnmarshalJSON(data []byte) error {
5656
return nil
5757
}
5858

59-
// NetConf describes a network.
60-
type NetConf struct {
59+
// NetConfType describes a network.
60+
type NetConfType struct {
6161
CNIVersion string `json:"cniVersion,omitempty"`
6262

6363
Name string `json:"name,omitempty"`
@@ -73,6 +73,9 @@ type NetConf struct {
7373
ValidAttachments []GCAttachment `json:"cni.dev/valid-attachments,omitempty"`
7474
}
7575

76+
// NetConf is defined as different type as custom MarshalJSON() and issue #1096
77+
type NetConf NetConfType
78+
7679
// GCAttachment is the parameters to a GC call -- namely,
7780
// the container ID and ifname pair that represents a
7881
// still-valid attachment.
@@ -83,10 +86,10 @@ type GCAttachment struct {
8386

8487
// Note: DNS should be omit if DNS is empty but default Marshal function
8588
// will output empty structure hence need to write a Marshal function
86-
func (n *NetConf) MarshalJSON() ([]byte, error) {
87-
// use type alias to escape recursion for json.Marshal() to MarshalJSON()
89+
func (n *NetConfType) MarshalJSON() ([]byte, error) {
8890
type fixObjType = NetConf
8991

92+
// use type alias to escape recursion for json.Marshal() to MarshalJSON()
9093
bytes, err := json.Marshal(fixObjType(*n)) //nolint:all
9194
if err != nil {
9295
return nil, err

0 commit comments

Comments
 (0)