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

kubevirt / hyperconverged-cluster-operator / 23590193690

26 Mar 2026 10:45AM UTC coverage: 80.034% (+0.03%) from 80.0%
23590193690

Pull #4129

github

web-flow
Merge bc9898669 into f28e0ae02
Pull Request #4129: Fix a flaky tests

6 of 13 new or added lines in 1 file covered. (46.15%)

80 existing lines in 6 files now uncovered.

10390 of 12982 relevant lines covered (80.03%)

2.05 hits per line

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

77.36
/controllers/operands/conditionalHandler.go
1
package operands
2

3
import (
4
        objectreferencesv1 "github.com/openshift/custom-resource-status/objectreferences/v1"
5
        apierrors "k8s.io/apimachinery/pkg/api/errors"
6
        "k8s.io/client-go/tools/reference"
7
        "sigs.k8s.io/controller-runtime/pkg/client"
8

9
        "github.com/kubevirt/hyperconverged-cluster-operator/api/v1beta1"
10
        "github.com/kubevirt/hyperconverged-cluster-operator/controllers/common"
11
        hcoutil "github.com/kubevirt/hyperconverged-cluster-operator/pkg/util"
12
)
13

14
type ConditionFunc func(hc *v1beta1.HyperConverged) bool
15
type GetCRWithNameFunc func(hc *v1beta1.HyperConverged) client.Object
16

17
// ConditionalHandler is an operand handler that only deploy the operand CR if a given shouldDeploy function returns true.
18
// If not, it makes sure the CR is deleted.
19
type ConditionalHandler struct {
20
        operand       *GenericOperand
21
        shouldDeploy  ConditionFunc
22
        getCRWithName GetCRWithNameFunc
23
}
24

25
func NewConditionalHandler(operand *GenericOperand, shouldDeploy ConditionFunc, getCRWithName GetCRWithNameFunc) *ConditionalHandler {
6✔
26
        return &ConditionalHandler{
6✔
27
                operand:       operand,
6✔
28
                shouldDeploy:  shouldDeploy,
6✔
29
                getCRWithName: getCRWithName,
6✔
30
        }
6✔
31
}
6✔
32

33
func (ch *ConditionalHandler) Ensure(req *common.HcoRequest) *EnsureResult {
6✔
34
        if ch.shouldDeploy(req.Instance) {
10✔
35
                return ch.operand.Ensure(req)
4✔
36
        }
4✔
37
        return ch.ensureDeleted(req)
6✔
38
}
39

40
func (ch *ConditionalHandler) Reset() {
1✔
41
        ch.operand.Reset()
1✔
42
}
1✔
43

44
func (ch *ConditionalHandler) ensureDeleted(req *common.HcoRequest) *EnsureResult {
6✔
45
        cr := ch.getCRWithName(req.Instance)
6✔
46
        res := NewEnsureResult(req.Instance)
6✔
47
        res.SetName(cr.GetName())
6✔
48

6✔
49
        // hcoutil.EnsureDeleted does check that the CR exists before removing it. But it also writes a log message each
6✔
50
        // time it happens, i.e. for every reconcile loop. Assuming the client cache is up-to-date, we can safely get it here
6✔
51
        // with no meaningful performance cost.
6✔
52
        err := ch.operand.Get(req.Ctx, client.ObjectKeyFromObject(cr), cr)
6✔
53
        if err != nil {
12✔
54
                if !apierrors.IsNotFound(err) {
6✔
55
                        return res.Error(err)
×
56
                }
×
57
        } else {
4✔
58
                deleted, err := hcoutil.EnsureDeleted(req.Ctx, ch.operand.Client, cr, req.Instance.Name, req.Logger, false, false, true)
4✔
59
                if err != nil {
4✔
60
                        return res.Error(err)
×
61
                }
×
62

63
                if deleted {
8✔
64
                        res.SetDeleted()
4✔
65
                }
4✔
66
        }
67

68
        objectRef, err := reference.GetReference(ch.operand.Scheme, cr)
6✔
69
        if err != nil {
6✔
NEW
70
                return res.Error(err)
×
NEW
71
        }
×
72

73
        ref, err := objectreferencesv1.FindObjectReference(req.Instance.Status.RelatedObjects, *objectRef)
6✔
74
        if err != nil {
6✔
NEW
75
                return res.Error(err)
×
NEW
76
        }
×
77
        if ref != nil {
6✔
NEW
78
                if err = objectreferencesv1.RemoveObjectReference(&req.Instance.Status.RelatedObjects, *objectRef); err != nil {
×
NEW
79
                        return res.Error(err)
×
UNCOV
80
                }
×
81

NEW
82
                req.StatusDirty = true
×
83
        }
84

85
        return res.SetUpgradeDone(req.ComponentUpgradeInProgress)
6✔
86
}
87

88
func (ch *ConditionalHandler) GetFullCr(hc *v1beta1.HyperConverged) (client.Object, error) {
2✔
89
        return ch.operand.GetFullCr(hc)
2✔
90
}
2✔
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