From b2a893c1ac094438cb794495950b409aeb5e39ee Mon Sep 17 00:00:00 2001 From: Tomofumi Hayashi Date: Thu, 26 Oct 2023 14:31:08 +0900 Subject: [PATCH] Change 100's Result DNS as pointer to remove empty DNS field This commit changes DNS as pointer to remove empty DNS field in Result. This will simplify Result format. This also changes SPEC to mention all keys are optional, other than 'cniVerison'. Signed-off-by: Tomofumi Hayashi --- SPEC.md | 1 + libcni/api_test.go | 5 ++--- libcni/conf_test.go | 2 +- pkg/types/100/types.go | 4 ++-- pkg/types/100/types_test.go | 2 +- pkg/types/types.go | 2 +- pkg/types/types_test.go | 2 +- 7 files changed, 9 insertions(+), 9 deletions(-) diff --git a/SPEC.md b/SPEC.md index 9436c892..d26c3ea9 100644 --- a/SPEC.md +++ b/SPEC.md @@ -523,6 +523,7 @@ For certain operations, plugins must output result information. The output shoul ### ADD Success Plugins must output a JSON object with the following keys upon a successful `ADD` operation: +All keys are optional other than `cniVersion`. - `cniVersion`: The same version supplied on input - the string "1.1.0" - `interfaces`: An array of all interfaces created by the attachment, including any host-level interfaces: diff --git a/libcni/api_test.go b/libcni/api_test.go index 1f552325..1c9149b3 100644 --- a/libcni/api_test.go +++ b/libcni/api_test.go @@ -311,8 +311,7 @@ var _ = Describe("Invoking plugins", func() { debug = &noop_debug.Debug{ ReportResult: `{ "cniVersion": "` + version.Current() + `", - "ips": [{"address": "10.1.2.3/24"}], - "dns": {} + "ips": [{"address": "10.1.2.3/24"}] }`, } Expect(debug.WriteDebug(debugFilePath)).To(Succeed()) @@ -1003,7 +1002,7 @@ var _ = Describe("Invoking plugins", func() { }, }, // DNS injected by last plugin - DNS: types.DNS{ + DNS: &types.DNS{ Nameservers: []string{"1.2.3.4"}, }, })) diff --git a/libcni/conf_test.go b/libcni/conf_test.go index 74fb0dc2..196f12c9 100644 --- a/libcni/conf_test.go +++ b/libcni/conf_test.go @@ -496,7 +496,7 @@ var _ = Describe("Loading configuration from disk", func() { Expect(err).NotTo(HaveOccurred()) Expect(resultConfig).To(Equal(&libcni.NetworkConfig{ - Network: &types.NetConf{Name: "some-plugin", Type: "bridge", DNS: types.DNS{Nameservers: servers, Domain: "local"}}, + Network: &types.NetConf{Name: "some-plugin", Type: "bridge", DNS: &types.DNS{Nameservers: servers, Domain: "local"}}, Bytes: expectedPluginConfig, })) }) diff --git a/pkg/types/100/types.go b/pkg/types/100/types.go index 6c138568..beb46b07 100644 --- a/pkg/types/100/types.go +++ b/pkg/types/100/types.go @@ -92,7 +92,7 @@ type Result struct { Interfaces []*Interface `json:"interfaces,omitempty"` IPs []*IPConfig `json:"ips,omitempty"` Routes []*types.Route `json:"routes,omitempty"` - DNS types.DNS `json:"dns,omitempty"` + DNS *types.DNS `json:"dns,omitempty"` } // convertFrom100 does nothing except set the version; the types are the same @@ -145,7 +145,7 @@ func convertFrom04x(from types.Result, toVersion string) (types.Result, error) { fromResult := from.(*types040.Result) toResult := &Result{ CNIVersion: toVersion, - DNS: *fromResult.DNS.Copy(), + DNS: fromResult.DNS.Copy(), Routes: []*types.Route{}, } for _, fromIntf := range fromResult.Interfaces { diff --git a/pkg/types/100/types_test.go b/pkg/types/100/types_test.go index 3bd50bd7..4078ac67 100644 --- a/pkg/types/100/types_test.go +++ b/pkg/types/100/types_test.go @@ -72,7 +72,7 @@ func testResult() *current.Result { {Dst: *routev4, GW: routegwv4}, {Dst: *routev6, GW: routegwv6}, }, - DNS: types.DNS{ + DNS: &types.DNS{ Nameservers: []string{"1.2.3.4", "1::cafe"}, Domain: "acompany.com", Search: []string{"somedomain.com", "otherdomain.net"}, diff --git a/pkg/types/types.go b/pkg/types/types.go index 780dfa13..b4f8c1bb 100644 --- a/pkg/types/types.go +++ b/pkg/types/types.go @@ -64,7 +64,7 @@ type NetConf struct { Type string `json:"type,omitempty"` Capabilities map[string]bool `json:"capabilities,omitempty"` IPAM IPAM `json:"ipam,omitempty"` - DNS DNS `json:"dns,omitempty"` + DNS *DNS `json:"dns,omitempty"` RawPrevResult map[string]interface{} `json:"prevResult,omitempty"` PrevResult Result `json:"-"` diff --git a/pkg/types/types_test.go b/pkg/types/types_test.go index 4fed4a67..3694d0e7 100644 --- a/pkg/types/types_test.go +++ b/pkg/types/types_test.go @@ -176,7 +176,7 @@ var _ = Describe("Types", func() { Gateway: net.ParseIP("abcd:1234:ffff::1"), }, }, - DNS: types.DNS{ + DNS: &types.DNS{ Nameservers: []string{"1.2.3.4", "1::cafe"}, Domain: "acompany.com", Search: []string{"somedomain.com", "otherdomain.net"},