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

kubevirt / hyperconverged-cluster-operator / 23585370577

26 Mar 2026 08:46AM UTC coverage: 79.978% (-0.02%) from 80.0%
23585370577

Pull #4129

github

web-flow
Merge 6b836f02d into a4cf4d8ae
Pull Request #4129: Fix a flaky test

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

1 existing line in 1 file now uncovered.

10026 of 12536 relevant lines covered (79.98%)

2.01 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 {
5✔
26
        return &ConditionalHandler{
5✔
27
                operand:       operand,
5✔
28
                shouldDeploy:  shouldDeploy,
5✔
29
                getCRWithName: getCRWithName,
5✔
30
        }
5✔
31
}
5✔
32

33
func (ch *ConditionalHandler) Ensure(req *common.HcoRequest) *EnsureResult {
5✔
34
        if ch.shouldDeploy(req.Instance) {
8✔
35
                return ch.operand.Ensure(req)
3✔
36
        }
3✔
37
        return ch.ensureDeleted(req)
5✔
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 {
5✔
45
        cr := ch.getCRWithName(req.Instance)
5✔
46
        res := NewEnsureResult(req.Instance)
5✔
47
        res.SetName(cr.GetName())
5✔
48

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

63
                if deleted {
6✔
64
                        res.SetDeleted()
3✔
65
                }
3✔
66
        }
67

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

73
        ref, err := objectreferencesv1.FindObjectReference(req.Instance.Status.RelatedObjects, *objectRef)
5✔
74
        if err != nil {
5✔
NEW
75
                return res.Error(err)
×
NEW
76
        }
×
77
        if ref != nil {
5✔
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)
5✔
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