• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

k8snetworkplumbingwg / ib-sriov-cni / 16623005676

30 Jul 2025 11:23AM UTC coverage: 23.009% (+0.8%) from 22.172%
16623005676

push

github

web-flow
Merge pull request #123 from Mellanox/json-fix-upstream

fix: add MarshalJSON method for custom NetConf

15 of 25 new or added lines in 1 file covered. (60.0%)

260 of 1130 relevant lines covered (23.01%)

0.79 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

60.0
/pkg/types/types.go
1
package types
2

3
import (
4
        "encoding/json"
5
        "fmt"
6
        "net"
7

8
        "github.com/containernetworking/cni/pkg/types"
9
        "github.com/containernetworking/plugins/pkg/ns"
10
        "github.com/vishvananda/netlink"
11

12
        rdmatypes "github.com/k8snetworkplumbingwg/rdma-cni/pkg/types"
13
)
14

15
// NetConf extends types.PluginConf for ib-sriov-cni
16
type NetConf struct {
17
        types.PluginConf
18
        IbSriovNetConf
19
}
20

21
type IbSriovNetConf struct {
22
        Master              string
23
        DeviceID            string `json:"deviceID"` // PCI address of a VF in valid sysfs format
24
        VFID                int
25
        HostIFNames         string // VF netdevice name(s)
26
        HostIFGUID          string // VF netdevice GUID
27
        ContIFNames         string // VF names after in the container; used during deletion
28
        GUID                string `json:"-"` // Taken from either CNI_ARGS "guid" attribute or from RuntimeConfig
29
        PKey                string `json:"pkey"`
30
        LinkState           string `json:"link_state,omitempty"` // auto|enable|disable
31
        RdmaIso             bool   `json:"rdmaIsolation,omitempty"`
32
        IBKubernetesEnabled bool   `json:"ibKubernetesEnabled,omitempty"`
33
        RdmaNetState        rdmatypes.RdmaNetState
34
        RuntimeConfig       RuntimeConf `json:"runtimeConfig,omitempty"`
35
        Args                struct {
36
                CNI map[string]string `json:"cni"`
37
        } `json:"args"`
38
}
39

40
func (n NetConf) MarshalJSON() ([]byte, error) {
4✔
41
        pluginConfBytes, err := json.Marshal(&n.PluginConf)
4✔
42
        if err != nil {
4✔
NEW
43
                return nil, fmt.Errorf("error serializing delegate netConf: %v", err)
×
NEW
44
        }
×
45

46
        ibSriovNetConfBytes, err := json.Marshal(&n.IbSriovNetConf)
4✔
47
        if err != nil {
4✔
NEW
48
                return nil, fmt.Errorf("error serializing delegate sriovNetConf: %v", err)
×
NEW
49
        }
×
50

51
        netConfMap := make(map[string]interface{})
4✔
52
        if err := json.Unmarshal(pluginConfBytes, &netConfMap); err != nil {
4✔
NEW
53
                return nil, err
×
NEW
54
        }
×
55

56
        ibSriovNetConfMap := make(map[string]interface{})
4✔
57
        if err := json.Unmarshal(ibSriovNetConfBytes, &ibSriovNetConfMap); err != nil {
4✔
NEW
58
                return nil, err
×
NEW
59
        }
×
60

61
        for k, v := range netConfMap {
21✔
62
                ibSriovNetConfMap[k] = v
17✔
63
        }
17✔
64

65
        ibSriovNetConfBytes, err = json.Marshal(ibSriovNetConfMap)
4✔
66
        if err != nil {
4✔
NEW
67
                return nil, err
×
NEW
68
        }
×
69

70
        return ibSriovNetConfBytes, nil
4✔
71
}
72

73
// RuntimeConf represents the plugin's runtime configurations
74
type RuntimeConf struct {
75
        InfinibandGUID string `json:"infinibandGUID"`
76
}
77

78
// Manager provides interface invoke sriov nic related operations
79
type Manager interface {
80
        SetupVF(conf *NetConf, podifName string, cid string, netns ns.NetNS) error
81
        ReleaseVF(conf *NetConf, podifName string, cid string, netns ns.NetNS) error
82
        ResetVFConfig(conf *NetConf) error
83
        ApplyVFConfig(conf *NetConf) error
84
}
85

86
// mocked netlink interface
87
// required for unit tests
88

89
// NetlinkManager is an interface to mock nelink library
90
type NetlinkManager interface {
91
        LinkByName(string) (netlink.Link, error)
92
        LinkSetUp(netlink.Link) error
93
        LinkSetDown(netlink.Link) error
94
        LinkSetNsFd(netlink.Link, int) error
95
        LinkSetName(netlink.Link, string) error
96
        LinkSetVfState(netlink.Link, int, uint32) error
97
        LinkSetVfPortGUID(netlink.Link, int, net.HardwareAddr) error
98
        LinkSetVfNodeGUID(netlink.Link, int, net.HardwareAddr) error
99
        LinkDelAltName(netlink.Link, string) error
100
}
101

102
// PciUtils is interface to help in SR-IOV functions
103
type PciUtils interface {
104
        GetSriovNumVfs(ifName string) (int, error)
105
        GetVFLinkNamesFromVFID(pfName string, vfID int) ([]string, error)
106
        GetPciAddress(ifName string, vf int) (string, error)
107
        RebindVf(pfName, vfPciAddress string) error
108
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc