aboutsummaryrefslogtreecommitdiff
path: root/pkg/network
diff options
context:
space:
mode:
Diffstat (limited to 'pkg/network')
-rw-r--r--pkg/network/files.go11
-rw-r--r--pkg/network/network.go4
2 files changed, 7 insertions, 8 deletions
diff --git a/pkg/network/files.go b/pkg/network/files.go
index 81c0e1a28..beb3289f3 100644
--- a/pkg/network/files.go
+++ b/pkg/network/files.go
@@ -22,13 +22,13 @@ func GetCNIConfDir(config *config.Config) string {
// LoadCNIConfsFromDir loads all the CNI configurations from a dir
func LoadCNIConfsFromDir(dir string) ([]*libcni.NetworkConfigList, error) {
- var configs []*libcni.NetworkConfigList
files, err := libcni.ConfFiles(dir, []string{".conflist"})
if err != nil {
return nil, err
}
sort.Strings(files)
+ configs := make([]*libcni.NetworkConfigList, 0, len(files))
for _, confFile := range files {
conf, err := libcni.ConfListFromFile(confFile)
if err != nil {
@@ -72,7 +72,7 @@ func ReadRawCNIConfByName(config *config.Config, name string) ([]byte, error) {
// GetCNIPlugins returns a list of plugins that a given network
// has in the form of a string
func GetCNIPlugins(list *libcni.NetworkConfigList) string {
- var plugins []string
+ plugins := make([]string, 0, len(list.Plugins))
for _, plug := range list.Plugins {
plugins = append(plugins, plug.Network.Type)
}
@@ -106,12 +106,11 @@ func GetNetworksFromFilesystem(config *config.Config) ([]*allocator.Net, error)
// GetNetworkNamesFromFileSystem gets all the names from the cni network
// configuration files
func GetNetworkNamesFromFileSystem(config *config.Config) ([]string, error) {
- var networkNames []string
-
networks, err := LoadCNIConfsFromDir(GetCNIConfDir(config))
if err != nil {
return nil, err
}
+ networkNames := []string{}
for _, n := range networks {
networkNames = append(networkNames, n.Name)
}
@@ -144,12 +143,12 @@ func GetInterfaceNameFromConfig(path string) (string, error) {
// GetBridgeNamesFromFileSystem is a convenience function to get all the bridge
// names from the configured networks
func GetBridgeNamesFromFileSystem(config *config.Config) ([]string, error) {
- var bridgeNames []string
-
networks, err := LoadCNIConfsFromDir(GetCNIConfDir(config))
if err != nil {
return nil, err
}
+
+ bridgeNames := []string{}
for _, n := range networks {
var name string
// iterate network conflists
diff --git a/pkg/network/network.go b/pkg/network/network.go
index 3ff664316..997aaf8a2 100644
--- a/pkg/network/network.go
+++ b/pkg/network/network.go
@@ -30,11 +30,11 @@ func IsSupportedDriver(driver string) error {
// GetLiveNetworks returns a slice of networks representing what the system
// has defined as network interfaces
func GetLiveNetworks() ([]*net.IPNet, error) {
- var nets []*net.IPNet
addrs, err := net.InterfaceAddrs()
if err != nil {
return nil, err
}
+ nets := make([]*net.IPNet, 0, len(addrs))
for _, address := range addrs {
_, n, err := net.ParseCIDR(address.String())
if err != nil {
@@ -47,11 +47,11 @@ func GetLiveNetworks() ([]*net.IPNet, error) {
// GetLiveNetworkNames returns a list of network interfaces on the system
func GetLiveNetworkNames() ([]string, error) {
- var interfaceNames []string
liveInterfaces, err := net.Interfaces()
if err != nil {
return nil, err
}
+ interfaceNames := make([]string, 0, len(liveInterfaces))
for _, i := range liveInterfaces {
interfaceNames = append(interfaceNames, i.Name)
}