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

k8snetworkplumbingwg / dra-driver-sriov / 25417071754

06 May 2026 04:49AM UTC coverage: 53.353% (+2.2%) from 51.116%
25417071754

Pull #92

github

web-flow
Merge 7add24493 into 3bc336ca0
Pull Request #92: Add downward API Metadata support

130 of 183 new or added lines in 9 files covered. (71.04%)

75 existing lines in 7 files now uncovered.

1973 of 3698 relevant lines covered (53.35%)

3.78 hits per line

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

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

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

7
        resourceapi "k8s.io/api/resource/v1"
8
        "k8s.io/apimachinery/pkg/runtime"
9
        k8stypes "k8s.io/apimachinery/pkg/types"
10
        "k8s.io/dynamic-resource-allocation/kubeletplugin"
11
        drapbv1 "k8s.io/kubelet/pkg/apis/dra/v1beta1"
12
        "k8s.io/kubernetes/pkg/kubelet/checkpointmanager/checksum"
13
        cdiapi "tags.cncf.io/container-device-interface/pkg/cdi"
14

15
        configapi "github.com/k8snetworkplumbingwg/dra-driver-sriov/pkg/api/virtualfunction/v1alpha1"
16
        "github.com/k8snetworkplumbingwg/dra-driver-sriov/pkg/consts"
17
)
18

19
// AllocatableDevices is a map of device pci address to dra device objects
20
type AllocatableDevices map[string]resourceapi.Device
21

22
// PreparedDevices is a slice of prepared devices
23
type PreparedDevices []*PreparedDevice
24

25
// PreparedDevicesByClaimID is a map of claim ID to prepared devices
26
type PreparedDevicesByClaimID map[k8stypes.UID]PreparedDevices
27

28
// PreparedClaimsByPodUID is a map of pod uid to map of claim ID to prepared devices
29
type PreparedClaimsByPodUID map[k8stypes.UID]PreparedDevicesByClaimID
30

31
type NetworkDataChanStruct struct {
32
        PreparedDevice    *PreparedDevice
33
        NetworkDeviceData *resourceapi.NetworkDeviceData
34
        CNIConfig         map[string]interface{}
35
        CNIResult         map[string]interface{}
36
}
37
type NetworkDataChanStructList []*NetworkDataChanStruct
38

39
// AddDeviceIDToNetConf adds the deviceID (PCI address) to the netconf
40
func AddDeviceIDToNetConf(originalConfig, deviceID string) (string, error) {
6✔
41
        // Unmarshal the existing configuration into a raw map
6✔
42
        var rawConfig map[string]interface{}
6✔
43
        if err := json.Unmarshal([]byte(originalConfig), &rawConfig); err != nil {
7✔
44
                return "", fmt.Errorf("failed to unmarshal existing config: %w", err)
1✔
45
        }
1✔
46

47
        // Set the deviceID (PCI address)
48
        rawConfig["deviceID"] = deviceID
5✔
49

5✔
50
        // Marshal the modified configuration back to a JSON string
5✔
51
        modifiedConfig, err := json.Marshal(rawConfig)
5✔
52
        if err != nil {
5✔
53
                return "", fmt.Errorf("failed to marshal modified config: %w", err)
×
UNCOV
54
        }
×
55

56
        return string(modifiedConfig), nil
5✔
57
}
58

59
type OpaqueDeviceConfig struct {
60
        Requests []string
61
        Config   runtime.Object
62
}
63

64
type PreparedDevice struct {
65
        Device              drapbv1.Device
66
        ClaimNamespacedName kubeletplugin.NamespacedObject
67
        ContainerEdits      *cdiapi.ContainerEdits
68
        Config              *configapi.VfConfig
69
        IfName              string
70
        PciAddress          string
71
        MultusDeviceID      string
72
        MultusResourceName  string
73
        DeviceAttributes    map[resourceapi.QualifiedName]resourceapi.DeviceAttribute
74
        NetworkDeviceData   *resourceapi.NetworkDeviceData
75
        PodUID              string
76
        NetAttachDefConfig  string
77
        OriginalDriver      string // Store original driver for restoration during unprepare
78
}
79

80
func (p *PreparedDevice) ToKubeletPluginDevice(networkData *resourceapi.NetworkDeviceData) kubeletplugin.Device {
3✔
81
        if networkData == nil {
5✔
82
                networkData = p.NetworkDeviceData
2✔
83
        }
2✔
84
        return kubeletplugin.Device{
3✔
85
                Requests:     p.Device.GetRequestNames(),
3✔
86
                PoolName:     p.Device.GetPoolName(),
3✔
87
                DeviceName:   p.Device.GetDeviceName(),
3✔
88
                CDIDeviceIDs: p.Device.GetCdiDeviceIds(),
3✔
89
                Metadata: &kubeletplugin.DeviceMetadata{
3✔
90
                        Attributes:  p.MetadataAttributes(),
3✔
91
                        NetworkData: networkData,
3✔
92
                },
3✔
93
        }
3✔
94
}
95

NEW
96
func (p *PreparedDevice) SetNetworkDeviceData(networkData *resourceapi.NetworkDeviceData) {
×
NEW
97
        if networkData == nil {
×
NEW
98
                p.NetworkDeviceData = nil
×
NEW
99
                return
×
NEW
100
        }
×
NEW
101
        p.NetworkDeviceData = networkData.DeepCopy()
×
102
}
103

104
func (p *PreparedDevice) MetadataAttributes() map[string]resourceapi.DeviceAttribute {
3✔
105
        attrs := make(map[string]resourceapi.DeviceAttribute, len(p.DeviceAttributes)+1)
3✔
106
        for key, value := range p.DeviceAttributes {
4✔
107
                attrs[string(key)] = value
1✔
108
        }
1✔
109
        if p.IfName != "" {
4✔
110
                ifName := p.IfName
1✔
111
                attrs[consts.AttributeInterfaceName] = resourceapi.DeviceAttribute{
1✔
112
                        StringValue: &ifName,
1✔
113
                }
1✔
114
        }
1✔
115
        return attrs
3✔
116
}
117

118
type Checkpoint struct {
119
        Checksum checksum.Checksum `json:"checksum"`
120
        V1       *CheckpointV1     `json:"v1,omitempty"`
121
}
122

123
type CheckpointV1 struct {
124
        PreparedClaimsByPodUID PreparedClaimsByPodUID `json:"preparedClaimsByPodUID,omitempty"`
125
}
126

127
func NewCheckpoint() *Checkpoint {
7✔
128
        pc := &Checkpoint{
7✔
129
                Checksum: 0,
7✔
130
                V1: &CheckpointV1{
7✔
131
                        PreparedClaimsByPodUID: make(PreparedClaimsByPodUID),
7✔
132
                },
7✔
133
        }
7✔
134
        return pc
7✔
135
}
7✔
136

137
func (cp *Checkpoint) MarshalCheckpoint() ([]byte, error) {
4✔
138
        cp.Checksum = 0
4✔
139
        out, err := json.Marshal(*cp)
4✔
140
        if err != nil {
4✔
UNCOV
141
                return nil, err
×
UNCOV
142
        }
×
143
        cp.Checksum = checksum.New(out)
4✔
144
        return json.Marshal(*cp)
4✔
145
}
146

147
func (cp *Checkpoint) UnmarshalCheckpoint(data []byte) error {
5✔
148
        return json.Unmarshal(data, cp)
5✔
149
}
5✔
150

151
func (cp *Checkpoint) VerifyChecksum() error {
3✔
152
        ck := cp.Checksum
3✔
153
        cp.Checksum = 0
3✔
154
        defer func() {
6✔
155
                cp.Checksum = ck
3✔
156
        }()
3✔
157
        out, err := json.Marshal(*cp)
3✔
158
        if err != nil {
3✔
UNCOV
159
                return err
×
UNCOV
160
        }
×
161
        return ck.Verify(out)
3✔
162
}
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

© 2026 Coveralls, Inc