Merge pull request #1294 from Luap99/mkdir-netdir

libnetwork/cni: mkdir network config dir
This commit is contained in:
OpenShift Merge Robot 2023-01-17 10:37:56 -05:00 committed by GitHub
commit 312c80f14a
3 changed files with 13 additions and 2 deletions

View File

@ -327,6 +327,9 @@ func (n *cniNetwork) createCNIConfigListFromNetwork(network *types.Network, writ
}
cniPathName := ""
if writeToDisk {
if err := os.MkdirAll(n.cniConfigDir, 0o755); err != nil {
return nil, "", err
}
cniPathName = filepath.Join(n.cniConfigDir, network.Name+".conflist")
err = os.WriteFile(cniPathName, b, 0o644)
if err != nil {

View File

@ -128,6 +128,10 @@ var _ = Describe("Config", func() {
})
It("create two networks", func() {
// remove the dir here since we do not expect it to exists in the real context as well
// the backend will create it for us
os.RemoveAll(cniConfDir)
network := types.Network{}
network1, err := libpodNet.NetworkCreate(network, nil)
Expect(err).To(BeNil())

View File

@ -141,11 +141,15 @@ func (n *cniNetwork) DefaultNetworkName() string {
func (n *cniNetwork) loadNetworks() error {
// check the mod time of the config dir
var modTime time.Time
f, err := os.Stat(n.cniConfigDir)
if err != nil {
// ignore error if the file does not exists
if err != nil && !errors.Is(err, os.ErrNotExist) {
return err
}
modTime := f.ModTime()
if err == nil {
modTime = f.ModTime()
}
// skip loading networks if they are already loaded and
// if the config dir was not modified since the last call