diff options
author | OpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com> | 2020-12-01 21:43:27 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-12-01 21:43:27 +0100 |
commit | b7ff6f09121eee8a0444baede9f6c84cc1f12b71 (patch) | |
tree | dcedf6e0674998f3da09a51fe5e48510297ee2c4 /libpod/network/files.go | |
parent | 4b5cb7b1de3caecf0f78f264d5931066851c6a37 (diff) | |
parent | 8494bcb866f1c0978cbe35c62c1e3312a91040b4 (diff) | |
download | podman-b7ff6f09121eee8a0444baede9f6c84cc1f12b71.tar.gz podman-b7ff6f09121eee8a0444baede9f6c84cc1f12b71.tar.bz2 podman-b7ff6f09121eee8a0444baede9f6c84cc1f12b71.zip |
Merge pull request #8505 from Luap99/network-labels
podman network label support
Diffstat (limited to 'libpod/network/files.go')
-rw-r--r-- | libpod/network/files.go | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/libpod/network/files.go b/libpod/network/files.go index 7f1e3ee18..83cb1c23a 100644 --- a/libpod/network/files.go +++ b/libpod/network/files.go @@ -12,6 +12,7 @@ import ( "github.com/containers/common/pkg/config" "github.com/containers/podman/v2/libpod/define" "github.com/pkg/errors" + "github.com/sirupsen/logrus" ) // ErrNoSuchNetworkInterface indicates that no network interface exists @@ -89,6 +90,35 @@ func GetCNIPlugins(list *libcni.NetworkConfigList) string { return strings.Join(plugins, ",") } +// GetNetworkLabels returns a list of labels as a string +func GetNetworkLabels(list *libcni.NetworkConfigList) NcLabels { + cniJSON := make(map[string]interface{}) + err := json.Unmarshal(list.Bytes, &cniJSON) + if err != nil { + logrus.Errorf("failed to unmarshal network config %v %v", cniJSON["name"], err) + return nil + } + if args, ok := cniJSON["args"]; ok { + if key, ok := args.(map[string]interface{}); ok { + if labels, ok := key[PodmanLabelKey]; ok { + if labels, ok := labels.(map[string]interface{}); ok { + result := make(NcLabels, len(labels)) + for k, v := range labels { + if v, ok := v.(string); ok { + result[k] = v + } else { + logrus.Errorf("network config %v invalid label value type %T should be string", cniJSON["name"], labels) + } + } + return result + } + logrus.Errorf("network config %v invalid label type %T should be map[string]string", cniJSON["name"], labels) + } + } + } + return nil +} + // GetNetworksFromFilesystem gets all the networks from the cni configuration // files func GetNetworksFromFilesystem(config *config.Config) ([]*allocator.Net, error) { |