Skip to content

Commit 903b1b2

Browse files
kart2bcgeofffranks
authored andcommitted
Reapply "remove deprecated cni loader method to read conf files"
This reverts commit 43eb98a.
1 parent 9926cc3 commit 903b1b2

File tree

3 files changed

+11
-52
lines changed

3 files changed

+11
-52
lines changed

src/code.cloudfoundry.org/garden-external-networker/cni/cni_loader.go

Lines changed: 6 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ import (
55
"os"
66
"path/filepath"
77
"strings"
8+
"time"
89

910
"io"
10-
"time"
1111

1212
"github.com/containernetworking/cni/libcni"
1313
)
@@ -24,10 +24,7 @@ func (l *CNILoader) GetCNIConfig() *libcni.CNIConfig {
2424

2525
func (l *CNILoader) GetNetworkConfig() (*libcni.NetworkConfigList, error) {
2626

27-
var (
28-
confFilePaths []string
29-
confListFilePaths []string
30-
)
27+
var confListFilePaths []string
3128

3229
err := filepath.Walk(l.ConfigDir, func(path string, info os.FileInfo, err error) error {
3330
if err != nil {
@@ -38,17 +35,15 @@ func (l *CNILoader) GetNetworkConfig() (*libcni.NetworkConfigList, error) {
3835
return nil
3936
}
4037

41-
if strings.HasSuffix(path, ".conf") {
42-
confFilePaths = append(confFilePaths, path)
43-
} else if strings.HasSuffix(path, ".conflist") {
38+
if strings.HasSuffix(path, ".conflist") {
4439
confListFilePaths = append(confListFilePaths, path)
4540
}
4641

4742
return nil
4843
})
4944

5045
if err != nil {
51-
return nil, fmt.Errorf("error loading config: %s", err)
46+
return nil, fmt.Errorf("error walking config directory: %s", err)
5247
}
5348

5449
var toReturn *libcni.NetworkConfigList
@@ -60,28 +55,11 @@ func (l *CNILoader) GetNetworkConfig() (*libcni.NetworkConfigList, error) {
6055
return confList, fmt.Errorf("unable to load config from %s: %s", path, err)
6156
}
6257

63-
toReturn = confList
64-
} else if len(confFilePaths) > 0 {
65-
path := confFilePaths[0]
66-
//lint:ignore SA1019 - we will address this, but would like to keep units passing
67-
conf, err := libcni.ConfFromFile(path)
68-
if err != nil {
69-
return nil, fmt.Errorf("unable to load config from %s: %s", path, err)
70-
}
71-
72-
//lint:ignore SA1019 - we will address this, but would like to keep units passing
73-
confList, err := libcni.ConfListFromConf(conf)
74-
if err != nil {
75-
// untested, unable to cause failure case.
76-
return nil, fmt.Errorf("unable to upconvert from conf to conf list %s: %s", path, err)
77-
}
78-
7958
toReturn = confList
8059
}
8160

82-
if (len(confListFilePaths) + len(confFilePaths)) > 1 {
83-
fmt.Fprintf(l.Logger, `%s - Only one CNI config file or conflist (chain) will be executed.
84-
If a conf and conflist file are both present, then the conflist will be executed.
61+
if len(confListFilePaths) > 1 {
62+
fmt.Fprintf(l.Logger, `%s - Only one CNI conflist (chain) will be executed.
8563
If multiple CNI config files are present, behavior is undefined.`, time.Now().Format(time.RFC3339))
8664
}
8765

src/code.cloudfoundry.org/garden-external-networker/cni/cni_loader_test.go

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ var _ = Describe("GetNetworkConfig", func() {
5050

5151
It("returns a meaningful error", func() {
5252
_, err := cniLoader.GetNetworkConfig()
53-
Expect(err).To(MatchError(HavePrefix("error loading config:")))
53+
Expect(err).To(MatchError(HavePrefix("error walking config directory:")))
5454
})
5555
})
5656

@@ -62,21 +62,6 @@ var _ = Describe("GetNetworkConfig", func() {
6262
})
6363
})
6464

65-
Context("when a valid config file exists", func() {
66-
BeforeEach(func() {
67-
err = os.WriteFile(filepath.Join(dir, "foo.conf"), []byte(`{ "name": "mynet", "type": "bridge" }`), 0600)
68-
Expect(err).NotTo(HaveOccurred())
69-
})
70-
71-
It("loads a single network config", func() {
72-
netListCfg, err := cniLoader.GetNetworkConfig()
73-
Expect(err).NotTo(HaveOccurred())
74-
Expect(netListCfg.Name).To(Equal("mynet"))
75-
Expect(netListCfg.Plugins).To(HaveLen(1))
76-
Expect(*netListCfg.Plugins[0].Network).To(Equal(*expectedBridgeNetwork))
77-
})
78-
})
79-
8065
Context("when a valid config list files exists", func() {
8166
BeforeEach(func() {
8267
err = os.WriteFile(filepath.Join(dir, "foo.conflist"), []byte(`{
@@ -101,11 +86,6 @@ var _ = Describe("GetNetworkConfig", func() {
10186

10287
Context("when multiple valid config and config list files exists", func() {
10388
BeforeEach(func() {
104-
err = os.WriteFile(filepath.Join(dir, "aaa.conf"), []byte(`{ "name": "mynet", "type": "bridge" }`), 0600)
105-
Expect(err).NotTo(HaveOccurred())
106-
107-
err = os.WriteFile(filepath.Join(dir, "zzz.conf"), []byte(`{ "name": "barnet", "type": "dummy" }`), 0600)
108-
Expect(err).NotTo(HaveOccurred())
10989

11090
err = os.WriteFile(filepath.Join(dir, "ccc.conflist"), []byte(`{ "name": "nopelist", "plugins": [{ "name": "badnet", "type": "bridge" }] }`), 0600)
11191
Expect(err).NotTo(HaveOccurred())
@@ -125,7 +105,7 @@ var _ = Describe("GetNetworkConfig", func() {
125105
It("logs warning for the skipped files", func() {
126106
_, err := cniLoader.GetNetworkConfig()
127107
Expect(err).NotTo(HaveOccurred())
128-
Expect(logger.String()).To(ContainSubstring("Only one CNI config file or conflist (chain) will be executed"))
108+
Expect(logger.String()).To(ContainSubstring("Only one CNI conflist (chain) will be executed"))
129109
})
130110
})
131111
})

src/code.cloudfoundry.org/garden-external-networker/integration/integration_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,10 @@ func writeConfig(index int, outDir string) error {
9292
{
9393
"cniVersion": "0.4.0",
9494
"name": "some-net-%d",
95-
"type": "plugin-%d"
95+
"type": "plugin-%d",
96+
"plugins": [{"type": "plugin-0"}]
9697
}`, index, index)
97-
outpath := filepath.Join(outDir, fmt.Sprintf("%d-plugin-%d.conf", 10*index, index))
98+
outpath := filepath.Join(outDir, fmt.Sprintf("%d-plugin-%d.conflist", 10*index, index))
9899
return os.WriteFile(outpath, []byte(config), 0600)
99100
}
100101

0 commit comments

Comments
 (0)