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

kubevirt / hyperconverged-cluster-operator / 14333923257

08 Apr 2025 12:48PM UTC coverage: 71.84% (+0.09%) from 71.754%
14333923257

push

github

web-flow
Fix a bug when setting a CPU quentity without a type (#3389)

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>
Co-authored-by: Nahshon Unna-Tsameret <nunnatsa@redhat.com>

56 of 65 new or added lines in 7 files covered. (86.15%)

2 existing lines in 1 file now uncovered.

6314 of 8789 relevant lines covered (71.84%)

0.79 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