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

k8snetworkplumbingwg / sriov-network-operator / 18003884172

25 Sep 2025 09:59AM UTC coverage: 61.951% (-0.09%) from 62.036%
18003884172

Pull #909

github

web-flow
Merge a62c78a96 into c49a32c97
Pull Request #909: Add hugepages func test

8683 of 14016 relevant lines covered (61.95%)

0.69 hits per line

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

62.24
/pkg/daemon/status.go
1
package daemon
2

3
import (
4
        "context"
5
        "fmt"
6

7
        "k8s.io/apimachinery/pkg/api/equality"
8
        "k8s.io/client-go/util/retry"
9
        "sigs.k8s.io/controller-runtime/pkg/client"
10
        "sigs.k8s.io/controller-runtime/pkg/log"
11

12
        sriovnetworkv1 "github.com/k8snetworkplumbingwg/sriov-network-operator/api/v1"
13
        "github.com/k8snetworkplumbingwg/sriov-network-operator/pkg/consts"
14
        "github.com/k8snetworkplumbingwg/sriov-network-operator/pkg/vars"
15
)
16

17
const (
18
        Unknown = "Unknown"
19
)
20

21
func (dn *NodeReconciler) updateSyncState(ctx context.Context, desiredNodeState *sriovnetworkv1.SriovNetworkNodeState, status, failedMessage string) error {
1✔
22
        funcLog := log.Log.WithName("updateSyncState")
1✔
23
        currentNodeState := &sriovnetworkv1.SriovNetworkNodeState{}
1✔
24
        desiredNodeState.Status.SyncStatus = status
1✔
25
        desiredNodeState.Status.LastSyncError = failedMessage
1✔
26

1✔
27
        retryErr := retry.RetryOnConflict(retry.DefaultRetry, func() error {
2✔
28
                if err := dn.client.Get(ctx, client.ObjectKey{Namespace: desiredNodeState.Namespace, Name: desiredNodeState.Name}, currentNodeState); err != nil {
1✔
29
                        funcLog.Error(err, "failed to get latest node state",
×
30
                                "SyncStatus", status,
×
31
                                "LastSyncError", failedMessage)
×
32
                        return err
×
33
                }
×
34
                // update the object meta if not the patch can fail if the object did change
35
                desiredNodeState.ObjectMeta = currentNodeState.ObjectMeta
1✔
36

1✔
37
                funcLog.V(2).Info("update nodeState status",
1✔
38
                        "CurrentSyncStatus", currentNodeState.Status.SyncStatus,
1✔
39
                        "CurrentLastSyncError", currentNodeState.Status.LastSyncError,
1✔
40
                        "NewSyncStatus", desiredNodeState.Status.SyncStatus,
1✔
41
                        "NewFailedMessage", desiredNodeState.Status.LastSyncError)
1✔
42

1✔
43
                err := dn.client.Status().Patch(ctx, desiredNodeState, client.MergeFrom(currentNodeState))
1✔
44
                if err != nil {
1✔
45
                        funcLog.Error(err, "failed to update node state status",
×
46
                                "SyncStatus", status,
×
47
                                "LastSyncError", failedMessage)
×
48
                        return err
×
49
                }
×
50
                return nil
1✔
51
        })
52

53
        if retryErr != nil {
1✔
54
                funcLog.Error(retryErr, "failed to update node state status")
×
55
                return retryErr
×
56
        }
×
57

58
        dn.recordStatusChangeEvent(ctx, currentNodeState.Status.SyncStatus, status, failedMessage)
1✔
59
        return nil
1✔
60
}
61

62
func (dn *NodeReconciler) shouldUpdateStatus(current, desiredNodeState *sriovnetworkv1.SriovNetworkNodeState) bool {
1✔
63
        // check number of interfaces are equal
1✔
64
        if len(current.Status.Interfaces) != len(desiredNodeState.Status.Interfaces) {
1✔
65
                return true
×
66
        }
×
67

68
        // check for bridges
69
        if !equality.Semantic.DeepEqual(current.Status.Bridges, desiredNodeState.Status.Bridges) {
1✔
70
                return true
×
71
        }
×
72

73
        // check for system
74
        if !equality.Semantic.DeepEqual(current.Status.System, desiredNodeState.Status.System) {
1✔
75
                return true
×
76
        }
×
77

78
        // check for interfaces
79
        // we can't use deep equal here because if we have a vf inside a pod is name will not be available for example
80
        // we use the index for both lists
81
        c := current.Status.DeepCopy().Interfaces
1✔
82
        d := desiredNodeState.Status.DeepCopy().Interfaces
1✔
83
        for idx := range d {
2✔
84
                // check if it's a new device
1✔
85
                if d[idx].PciAddress != c[idx].PciAddress {
1✔
86
                        return true
×
87
                }
×
88
                // remove all the vfs
89
                d[idx].VFs = nil
1✔
90
                c[idx].VFs = nil
1✔
91

1✔
92
                if !equality.Semantic.DeepEqual(d[idx], c[idx]) {
1✔
93
                        return true
×
94
                }
×
95
        }
96

97
        return false
1✔
98
}
99

100
func (dn *NodeReconciler) updateStatusFromHost(nodeState *sriovnetworkv1.SriovNetworkNodeState) error {
1✔
101
        log.Log.WithName("updateStatusFromHost").Info("Getting host network status")
1✔
102
        var ifaces []sriovnetworkv1.InterfaceExt
1✔
103
        var bridges sriovnetworkv1.Bridges
1✔
104
        var err error
1✔
105

1✔
106
        if vars.PlatformType == consts.VirtualOpenStack {
1✔
107
                ifaces, err = dn.platformHelpers.DiscoverSriovDevicesVirtual()
×
108
                if err != nil {
×
109
                        return err
×
110
                }
×
111
        } else {
1✔
112
                ifaces, err = dn.HostHelpers.DiscoverSriovDevices(dn.HostHelpers)
1✔
113
                if err != nil {
1✔
114
                        return err
×
115
                }
×
116
                if vars.ManageSoftwareBridges {
1✔
117
                        bridges, err = dn.HostHelpers.DiscoverBridges()
×
118
                        if err != nil {
×
119
                                return err
×
120
                        }
×
121
                }
122
        }
123

124
        nodeState.Status.Interfaces = ifaces
1✔
125
        nodeState.Status.Bridges = bridges
1✔
126
        nodeState.Status.System.RdmaMode, err = dn.HostHelpers.DiscoverRDMASubsystem()
1✔
127
        return err
1✔
128
}
129

130
func (dn *NodeReconciler) recordStatusChangeEvent(ctx context.Context, oldStatus, newStatus, lastError string) {
1✔
131
        if oldStatus != newStatus {
2✔
132
                if oldStatus == "" {
2✔
133
                        oldStatus = Unknown
1✔
134
                }
1✔
135
                if newStatus == "" {
1✔
136
                        newStatus = Unknown
×
137
                }
×
138
                eventMsg := fmt.Sprintf("Status changed from: %s to: %s", oldStatus, newStatus)
1✔
139
                if lastError != "" {
1✔
140
                        eventMsg = fmt.Sprintf("%s. Last Error: %s", eventMsg, lastError)
×
141
                }
×
142
                dn.eventRecorder.SendEvent(ctx, "SyncStatusChanged", eventMsg)
1✔
143
        }
144
}
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