(store storage.Store, conf *config.Config)
| 101 | } |
| 102 | |
| 103 | func defaultNetworkBackend(store storage.Store, conf *config.Config) (backend types.NetworkBackend, err error) { |
| 104 | // read defaultNetworkBackend file |
| 105 | file := filepath.Join(store.GraphRoot(), defaultNetworkBackendFileName) |
| 106 | b, err := ioutil.ReadFile(file) |
| 107 | if err == nil { |
| 108 | val := string(b) |
| 109 | if val == string(types.Netavark) { |
| 110 | return types.Netavark, nil |
| 111 | } |
| 112 | if val == string(types.CNI) { |
| 113 | return types.CNI, nil |
| 114 | } |
| 115 | return "", fmt.Errorf("unknown network backend value %q in %q", val, file) |
| 116 | } |
| 117 | // fail for all errors except ENOENT |
| 118 | if !errors.Is(err, os.ErrNotExist) { |
| 119 | return "", fmt.Errorf("could not read network backend value: %w", err) |
| 120 | } |
| 121 | |
| 122 | // cache the network backend to make sure always the same one will be used |
| 123 | defer func() { |
| 124 | // only write when there is no error |
| 125 | if err == nil { |
| 126 | // nolint:gocritic |
| 127 | if err := ioutils.AtomicWriteFile(file, []byte(backend), 0644); err != nil { |
| 128 | logrus.Errorf("could not write network backend to file: %v", err) |
| 129 | } |
| 130 | } |
| 131 | }() |
| 132 | |
| 133 | _, err = conf.FindHelperBinary("netavark", false) |
| 134 | if err != nil { |
| 135 | // if we cannot find netavark use CNI |
| 136 | return types.CNI, nil |
| 137 | } |
| 138 | |
| 139 | // now check if there are already containers, images and CNI networks (new install?) |
| 140 | cons, err := store.Containers() |
| 141 | if err != nil { |
| 142 | return "", err |
| 143 | } |
| 144 | if len(cons) == 0 { |
| 145 | imgs, err := store.Images() |
| 146 | if err != nil { |
| 147 | return "", err |
| 148 | } |
| 149 | if len(imgs) == 0 { |
| 150 | cniInterface, err := getCniInterface(conf) |
| 151 | if err == nil { |
| 152 | nets, err := cniInterface.NetworkList() |
| 153 | // there is always a default network so check <= 1 |
| 154 | if err == nil && len(nets) <= 1 { |
| 155 | // we have a fresh system so use netavark |
| 156 | return types.Netavark, nil |
| 157 | } |
| 158 | } |
| 159 | } |
| 160 | } |
no test coverage detected
searching dependent graphs…