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

kubevirt / hyperconverged-cluster-operator / 14240046899

03 Apr 2025 09:48AM UTC coverage: 72.296%. First build
14240046899

Pull #3379

github

nunnatsa
Fix a bug when setting a CPU quentity without a type

When setting, for example, the
`spec.resourceRequirements.storageWorkloads.limit` field to `"1.5"`, the
client set the value in CDI to `"1500m"`. Then HCO will always find this
value as not matches to the required value of `"1.5"`, and will
constantly try to update CDI.

This PR fixes this issue by turning the required objects to json and back
to objects. The json marshaling peforms the same change in the object.
Now when HCO will compare the required value with the existing one, both
will be at the newer format, with the quntity type, and HCO will
understand that no change was done, and it will not try to update the CR
again.

Also. This PR adds a mutex protection to the cache in the operand
handlers.

Signed-off-by: Nahshon Unna-Tsameret <nunnatsa@redhat.com>
Pull Request #3379: Fix a bug when setting a CPU quantity without a type

53 of 62 new or added lines in 7 files covered. (85.48%)

6524 of 9024 relevant lines covered (72.3%)

0.8 hits per line

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

66.67
/pkg/reformatobj/reformatobj.go
1
package reformatobj
2

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

8
// ReformatObj reformats client objects to solve the quantity bug.
9
// The bug is happening when setting a quantity field without quantity
10
// type.
11
// for example
12
//
13
//        limit:
14
//          cpu: "1.5"
15
//
16
// In this case, the client actually set a formatted value to the resource
17
// in K8s cluster, while HCO keep use the original un-typed quantity value.
18
// That causes an endless loop of updates, because HCO compares the values
19
// and finds out they are different.
20
func ReformatObj[T any](obj *T) (*T, error) {
1✔
21
        bts, err := json.Marshal(obj)
1✔
22

1✔
23
        if err != nil {
1✔
NEW
24
                return nil, fmt.Errorf("failed to marshal %T: %w", obj, err)
×
NEW
25
        }
×
26

27
        var obj2 T
1✔
28
        err = json.Unmarshal(bts, &obj2)
1✔
29
        if err != nil {
1✔
NEW
30
                return nil, fmt.Errorf("failed to unmarshal %T: %w", obj, err)
×
NEW
31
        }
×
32

33
        return &obj2, nil
1✔
34
}
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