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

kubevirt / hyperconverged-cluster-operator / 25868969024

14 May 2026 03:30PM UTC coverage: 80.481%. Remained the same
25868969024

push

github

web-flow
Bump kubevirtci to 2605140116-9cdaaa3f (#4253)

**Release note**:
```release-note
None
```

Signed-off-by: kubevirt-bot <kubevirtbot@redhat.com>

10436 of 12967 relevant lines covered (80.48%)

2.06 hits per line

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

90.13
/pkg/webhooks/validator/validator.go
1
package validator
2

3
import (
4
        "context"
5
        "errors"
6
        "fmt"
7
        "net/http"
8
        "reflect"
9
        "strings"
10
        "time"
11

12
        "github.com/go-logr/logr"
13
        openshiftconfigv1 "github.com/openshift/api/config/v1"
14
        "github.com/samber/lo"
15
        xsync "golang.org/x/sync/errgroup"
16
        admissionv1 "k8s.io/api/admission/v1"
17
        corev1 "k8s.io/api/core/v1"
18
        apierrors "k8s.io/apimachinery/pkg/api/errors"
19
        metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
20
        "k8s.io/component-helpers/scheduling/corev1/nodeaffinity"
21
        "k8s.io/utils/ptr"
22
        "sigs.k8s.io/controller-runtime/pkg/client"
23
        "sigs.k8s.io/controller-runtime/pkg/webhook/admission"
24

25
        networkaddonsv1 "github.com/kubevirt/cluster-network-addons-operator/pkg/apis/networkaddonsoperator/v1"
26
        kubevirtcorev1 "kubevirt.io/api/core/v1"
27
        cdiv1beta1 "kubevirt.io/containerized-data-importer-api/pkg/apis/core/v1beta1"
28
        sspv1beta3 "kubevirt.io/ssp-operator/api/v1beta3"
29

30
        hcov1 "github.com/kubevirt/hyperconverged-cluster-operator/api/v1"
31
        hcov1fg "github.com/kubevirt/hyperconverged-cluster-operator/api/v1/featuregates"
32
        hcov1beta1 "github.com/kubevirt/hyperconverged-cluster-operator/api/v1beta1"
33
        "github.com/kubevirt/hyperconverged-cluster-operator/controllers/handlers"
34
        "github.com/kubevirt/hyperconverged-cluster-operator/pkg/featuregatedetails"
35
        "github.com/kubevirt/hyperconverged-cluster-operator/pkg/featuregates"
36
        "github.com/kubevirt/hyperconverged-cluster-operator/pkg/tlssecprofile"
37
        hcoutil "github.com/kubevirt/hyperconverged-cluster-operator/pkg/util"
38
)
39

40
const (
41
        updateDryRunTimeOut = time.Second * 3
42

43
        validatorV1Name = "hyperConverged v1 validator"
44
)
45

46
type ValidationWarning struct {
47
        warnings []string
48
}
49

50
func newValidationWarning(warnings []string) *ValidationWarning {
1✔
51
        return &ValidationWarning{
1✔
52
                warnings: warnings,
1✔
53
        }
1✔
54
}
1✔
55

56
func (v *ValidationWarning) Error() string {
×
57
        return ""
×
58
}
×
59

60
func (v *ValidationWarning) Warnings() []string {
1✔
61
        return v.warnings
1✔
62
}
1✔
63

64
type WebhookHandler struct {
65
        logger      logr.Logger
66
        cli         client.Client
67
        namespace   string
68
        isOpenshift bool
69
        decoder     admission.Decoder
70
}
71

72
func NewWebhookHandler(logger logr.Logger, cli client.Client, decoder admission.Decoder, namespace string, isOpenshift bool) *WebhookHandler {
2✔
73
        return &WebhookHandler{
2✔
74
                logger:      logger.WithName(validatorV1Name),
2✔
75
                cli:         cli,
2✔
76
                namespace:   namespace,
2✔
77
                isOpenshift: isOpenshift,
2✔
78
                decoder:     decoder,
2✔
79
        }
2✔
80
}
2✔
81

82
func (wh *WebhookHandler) Handle(ctx context.Context, req admission.Request) admission.Response {
1✔
83
        ctx = admission.NewContextWithRequest(ctx, req)
1✔
84
        logger, err := logr.FromContext(ctx)
1✔
85
        if err != nil {
2✔
86
                logger = wh.logger
1✔
87
        } else {
1✔
88
                logger = logger.WithName(validatorV1Name)
×
89
        }
×
90

91
        // Get the object in the request
92
        obj := &hcov1.HyperConverged{}
1✔
93

1✔
94
        dryRun := req.DryRun != nil && *req.DryRun
1✔
95

1✔
96
        switch req.Operation {
1✔
97
        case admissionv1.Create:
1✔
98
                if err = wh.decoder.Decode(req, obj); err != nil {
2✔
99
                        return admission.Errored(http.StatusBadRequest, err)
1✔
100
                }
1✔
101

102
                return wh.validateCreate(logger, dryRun, obj)
1✔
103

104
        case admissionv1.Update:
1✔
105
                if err = wh.decoder.DecodeRaw(req.Object, obj); err != nil {
2✔
106
                        return admission.Errored(http.StatusBadRequest, err)
1✔
107
                }
1✔
108

109
                oldObj := &hcov1.HyperConverged{}
1✔
110
                if err = wh.decoder.DecodeRaw(req.OldObject, oldObj); err != nil {
2✔
111
                        return admission.Errored(http.StatusBadRequest, err)
1✔
112
                }
1✔
113

114
                return wh.validateUpdate(ctx, logger, dryRun, obj, oldObj)
1✔
115

116
        case admissionv1.Delete:
1✔
117
                if err = wh.decoder.DecodeRaw(req.OldObject, obj); err != nil {
2✔
118
                        return admission.Errored(http.StatusBadRequest, err)
1✔
119
                }
1✔
120

121
                return wh.validateDelete(ctx, logger, dryRun, obj)
1✔
122

123
        default:
1✔
124
                return admission.Errored(http.StatusBadRequest, fmt.Errorf("unknown operation request %q", req.Operation))
1✔
125
        }
126
}
127

128
func (wh *WebhookHandler) validateCreate(logger logr.Logger, dryrun bool, hc *hcov1.HyperConverged) admission.Response {
1✔
129
        logger.Info("Validating create", "name", hc.Name, "namespace:", hc.Namespace)
1✔
130

1✔
131
        if err := wh.validateCreateHyperConverged(hc); err != nil {
2✔
132
                return errToResponse(err)
1✔
133
        }
1✔
134

135
        err := wh.validateCreateComponents(hc)
1✔
136
        if err != nil {
2✔
137
                return errToResponse(err)
1✔
138
        }
1✔
139

140
        if !dryrun {
2✔
141
                tlssecprofile.SetHyperConvergedTLSSecurityProfile(hc.Spec.Security.TLSSecurityProfile)
1✔
142
        }
1✔
143

144
        return admission.Allowed("")
1✔
145
}
146

147
func (wh *WebhookHandler) validateUpdate(ctx context.Context, logger logr.Logger, dryrun bool, requested *hcov1.HyperConverged, exists *hcov1.HyperConverged) admission.Response {
1✔
148
        logger.Info("Validating update", "name", requested.Name)
1✔
149

1✔
150
        // If no change is detected in the spec nor the annotations - nothing to validate
1✔
151
        if reflect.DeepEqual(exists.Spec, requested.Spec) &&
1✔
152
                reflect.DeepEqual(exists.Annotations, requested.Annotations) {
2✔
153
                return admission.Allowed("")
1✔
154
        }
1✔
155

156
        if err := wh.validateUpdateHyperConverged(requested, exists); err != nil {
1✔
157
                return errToResponse(err)
×
158
        }
×
159

160
        if err := checkOperands(ctx, wh.cli, logger, requested, wh.isOpenshift); err != nil {
2✔
161
                return errToResponse(err)
1✔
162
        }
1✔
163

164
        if !dryrun {
2✔
165
                tlssecprofile.SetHyperConvergedTLSSecurityProfile(requested.Spec.Security.TLSSecurityProfile)
1✔
166
        }
1✔
167

168
        return admission.Allowed("")
1✔
169
}
170

171
func (wh *WebhookHandler) validateDelete(ctx context.Context, logger logr.Logger, dryrun bool, hc *hcov1.HyperConverged) admission.Response {
1✔
172
        logger.Info("Validating delete", "name", hc.Name, "namespace", hc.Namespace)
1✔
173

1✔
174
        var err error
1✔
175
        for _, obj := range []client.Object{
1✔
176
                handlers.NewKubeVirtWithNameOnly(),
1✔
177
                handlers.NewCDIWithNameOnly(),
1✔
178
        } {
2✔
179
                _, err = hcoutil.EnsureDeleted(ctx, wh.cli, obj, hc.Name, logger, true, false, true)
1✔
180
                if err != nil {
2✔
181
                        logger.Error(err, "Delete validation failed", "GVK", obj.GetObjectKind().GroupVersionKind())
1✔
182
                        break
1✔
183
                }
184
        }
185

186
        if err == nil && !dryrun {
2✔
187
                tlssecprofile.SetHyperConvergedTLSSecurityProfile(nil)
1✔
188
        }
1✔
189

190
        return errToResponse(err)
1✔
191
}
192

193
func (wh *WebhookHandler) validateHyperConverged(hc *hcov1.HyperConverged) error {
1✔
194
        if err := wh.validateCertConfig(hc); err != nil {
1✔
195
                return err
×
196
        }
×
197

198
        if err := wh.validateDataImportCronTemplates(hc); err != nil {
2✔
199
                return err
1✔
200
        }
1✔
201

202
        if err := wh.validateTLSSecurityProfiles(hc); err != nil {
2✔
203
                return err
1✔
204
        }
1✔
205

206
        if err := wh.validateTuningPolicy(hc); err != nil {
2✔
207
                return err
1✔
208
        }
1✔
209

210
        if err := wh.validateAffinity(hc); err != nil {
2✔
211
                return err
1✔
212
        }
1✔
213

214
        return nil
1✔
215
}
216

217
func (wh *WebhookHandler) validateCreateHyperConverged(hc *hcov1.HyperConverged) error {
1✔
218
        if err := wh.validateHyperConverged(hc); err != nil {
2✔
219
                return err
1✔
220
        }
1✔
221

222
        if err := wh.validateFeatureGatesOnCreate(hc); err != nil {
1✔
223
                return err
×
224
        }
×
225

226
        return nil
1✔
227
}
228

229
func (wh *WebhookHandler) validateUpdateHyperConverged(hc, oldHC *hcov1.HyperConverged) error {
1✔
230
        if err := wh.validateHyperConverged(hc); err != nil {
1✔
231
                return err
×
232
        }
×
233

234
        if err := wh.validateFeatureGatesOnUpdate(hc, oldHC); err != nil {
1✔
235
                return err
×
236
        }
×
237

238
        return nil
1✔
239
}
240

241
func (wh *WebhookHandler) validateCreateComponents(hc *hcov1.HyperConverged) error {
1✔
242
        if _, err := handlers.NewKubeVirt(hc); err != nil {
2✔
243
                return err
1✔
244
        }
1✔
245

246
        if _, err := handlers.NewCDI(hc); err != nil {
2✔
247
                return err
1✔
248
        }
1✔
249

250
        if _, err := handlers.NewNetworkAddons(hc); err != nil {
2✔
251
                return err
1✔
252
        }
1✔
253

254
        if _, _, err := handlers.NewSSP(hc, true); err != nil {
2✔
255
                return err
1✔
256
        }
1✔
257

258
        return nil
1✔
259
}
260

261
func (wh *WebhookHandler) validateCertConfig(hc *hcov1.HyperConverged) error {
1✔
262
        minimalDuration := metav1.Duration{Duration: 10 * time.Minute}
1✔
263

1✔
264
        ccValues := make(map[string]time.Duration)
1✔
265
        ccValues["spec.certConfig.ca.duration"] = hc.Spec.Security.CertConfig.CA.Duration.Duration
1✔
266
        ccValues["spec.certConfig.ca.renewBefore"] = hc.Spec.Security.CertConfig.CA.RenewBefore.Duration
1✔
267
        ccValues["spec.certConfig.server.duration"] = hc.Spec.Security.CertConfig.Server.Duration.Duration
1✔
268
        ccValues["spec.certConfig.server.renewBefore"] = hc.Spec.Security.CertConfig.Server.RenewBefore.Duration
1✔
269

1✔
270
        for key, value := range ccValues {
2✔
271
                if value < minimalDuration.Duration {
1✔
272
                        return fmt.Errorf("%v: value is too small", key)
×
273
                }
×
274
        }
275

276
        if hc.Spec.Security.CertConfig.CA.Duration.Duration < hc.Spec.Security.CertConfig.CA.RenewBefore.Duration {
1✔
277
                return errors.New("spec.certConfig.ca: duration is smaller than renewBefore")
×
278
        }
×
279

280
        if hc.Spec.Security.CertConfig.Server.Duration.Duration < hc.Spec.Security.CertConfig.Server.RenewBefore.Duration {
1✔
281
                return errors.New("spec.certConfig.server: duration is smaller than renewBefore")
×
282
        }
×
283

284
        if hc.Spec.Security.CertConfig.CA.Duration.Duration < hc.Spec.Security.CertConfig.Server.Duration.Duration {
1✔
285
                return errors.New("spec.certConfig: ca.duration is smaller than server.duration")
×
286
        }
×
287

288
        return nil
1✔
289
}
290

291
func (wh *WebhookHandler) validateDataImportCronTemplates(hc *hcov1.HyperConverged) error {
1✔
292

1✔
293
        for _, dict := range hc.Spec.WorkloadSources.DataImportCronTemplates {
2✔
294
                val, ok := dict.Annotations[hcoutil.DataImportCronEnabledAnnotation]
1✔
295
                val = strings.ToLower(val)
1✔
296
                if ok && val != "false" && val != "true" {
2✔
297
                        return fmt.Errorf(`the %s annotation of a dataImportCronTemplate must be either "true" or "false"`, hcoutil.DataImportCronEnabledAnnotation)
1✔
298
                }
1✔
299

300
                enabled := !ok || val == "true"
1✔
301

1✔
302
                if enabled && dict.Spec == nil {
2✔
303
                        return fmt.Errorf("dataImportCronTemplate spec is empty for an enabled DataImportCronTemplate")
1✔
304
                }
1✔
305
        }
306

307
        return nil
1✔
308
}
309

310
func (wh *WebhookHandler) validateTLSSecurityProfiles(hc *hcov1.HyperConverged) error {
1✔
311
        tlsSP := hc.Spec.Security.TLSSecurityProfile
1✔
312

1✔
313
        if tlsSP == nil {
2✔
314
                return nil
1✔
315
        }
1✔
316

317
        if tlsSP.Custom == nil {
2✔
318
                if tlsSP.Type == openshiftconfigv1.TLSProfileCustomType {
2✔
319
                        return fmt.Errorf("missing required field spec.tlsSecurityProfile.custom when type is Custom")
1✔
320
                }
1✔
321
                return nil
1✔
322
        }
323

324
        if !isValidTLSProtocolVersion(tlsSP.Custom.MinTLSVersion) {
2✔
325
                return fmt.Errorf("invalid value for spec.tlsSecurityProfile.custom.minTLSVersion: %q", tlsSP.Custom.MinTLSVersion)
1✔
326
        }
1✔
327

328
        if tlsSP.Custom.MinTLSVersion < openshiftconfigv1.VersionTLS13 && !hasRequiredHTTP2Ciphers(tlsSP.Custom.Ciphers) {
2✔
329
                return fmt.Errorf("http2: TLSConfig.CipherSuites is missing an HTTP/2-required AES_128_GCM_SHA256 cipher (need at least one of ECDHE-RSA-AES128-GCM-SHA256 or ECDHE-ECDSA-AES128-GCM-SHA256)")
1✔
330
        } else if tlsSP.Custom.MinTLSVersion == openshiftconfigv1.VersionTLS13 && len(tlsSP.Custom.Ciphers) > 0 {
3✔
331
                return fmt.Errorf("custom ciphers cannot be selected when minTLSVersion is VersionTLS13")
1✔
332
        }
1✔
333

334
        return nil
1✔
335
}
336

337
func (wh *WebhookHandler) validateTuningPolicy(hc *hcov1.HyperConverged) error {
1✔
338
        if hc.Spec.Virtualization.TuningPolicy == hcov1beta1.HyperConvergedHighBurstProfile { //nolint SA1019
2✔
339
                return newValidationWarning([]string{"spec.virtualization.tuningPolicy: the highBurst profile is not supported and ignored"})
1✔
340
        }
1✔
341
        return nil
1✔
342
}
343

344
func (wh *WebhookHandler) validateFeatureGatesOnCreate(hc *hcov1.HyperConverged) error {
1✔
345
        fgMap := v1FGsToMap(hc.Spec.FeatureGates)
1✔
346

1✔
347
        warnings := wh.validateDeprecatedFeatureGates(fgMap, nil)
1✔
348

1✔
349
        if len(warnings) > 0 {
1✔
350
                return newValidationWarning(warnings)
×
351
        }
×
352

353
        return nil
1✔
354
}
355

356
func (wh *WebhookHandler) validateFeatureGatesOnUpdate(requested, exists *hcov1.HyperConverged) error {
1✔
357
        reqFGMap := v1FGsToMap(requested.Spec.FeatureGates)
1✔
358
        oldFGMap := v1FGsToMap(exists.Spec.FeatureGates)
1✔
359

1✔
360
        warnings := wh.validateDeprecatedFeatureGates(reqFGMap, oldFGMap)
1✔
361

1✔
362
        if len(warnings) > 0 {
1✔
363
                return newValidationWarning(warnings)
×
364
        }
×
365

366
        return nil
1✔
367
}
368

369
func (wh *WebhookHandler) validateAffinity(hc *hcov1.HyperConverged) error {
1✔
370
        if hc.Spec.Deployment.NodePlacements == nil {
2✔
371
                return nil
1✔
372
        }
1✔
373

374
        nodePlacements := hc.Spec.Deployment.NodePlacements
1✔
375

1✔
376
        if nodePlacements.Workload != nil {
2✔
377
                if err := validateAffinity(nodePlacements.Workload.Affinity); err != nil {
2✔
378
                        return fmt.Errorf("invalid workloads node placement affinity: %v", err.Error())
1✔
379
                }
1✔
380
        }
381

382
        if nodePlacements.Infra != nil {
2✔
383
                if err := validateAffinity(nodePlacements.Infra.Affinity); err != nil {
2✔
384
                        return fmt.Errorf("invalid infra node placement affinity: %v", err.Error())
1✔
385
                }
1✔
386
        }
387

388
        return nil
1✔
389
}
390

391
const (
392
        fgv1Unknown            = "the %s featureGate is unknown and ignored."
393
        fgv1DeprecationWarning = "the %s featureGate deprecated and will be removed in a future release."
394
)
395

396
func (wh *WebhookHandler) validateDeprecatedFeatureGates(fgMap, oldFgMap map[string]bool) []string {
1✔
397
        var warnings []string
1✔
398

1✔
399
        for fgName, enabled := range fgMap {
1✔
400
                phase, exists := featuregatedetails.GetFeatureGatePhase(fgName)
×
401
                if !exists {
×
402
                        warnings = append(warnings, fmt.Sprintf(fgv1Unknown, fgName))
×
403
                        continue
×
404
                }
405

406
                if phase != featuregates.PhaseDeprecated {
×
407
                        continue
×
408
                }
409

410
                if oldEnabled, oldExists := oldFgMap[fgName]; !oldExists || enabled != oldEnabled {
×
411
                        warnings = append(warnings, fmt.Sprintf(fgv1DeprecationWarning, fgName))
×
412
                }
×
413
        }
414

415
        return warnings
1✔
416
}
417

418
func hasRequiredHTTP2Ciphers(ciphers []string) bool {
1✔
419
        var requiredHTTP2Ciphers = []string{
1✔
420
                "ECDHE-RSA-AES128-GCM-SHA256",
1✔
421
                "ECDHE-ECDSA-AES128-GCM-SHA256",
1✔
422
        }
1✔
423

1✔
424
        // lo.Some returns true if at least 1 element of a subset is contained into a collection
1✔
425
        return lo.Some[string](requiredHTTP2Ciphers, ciphers)
1✔
426
}
1✔
427

428
// validationResponseFromStatus returns a response for admitting a request with provided Status object.
429
func validationResponseFromStatus(allowed bool, status metav1.Status) admission.Response {
1✔
430
        resp := admission.Response{
1✔
431
                AdmissionResponse: admissionv1.AdmissionResponse{
1✔
432
                        Allowed: allowed,
1✔
433
                        Result:  &status,
1✔
434
                },
1✔
435
        }
1✔
436
        return resp
1✔
437
}
1✔
438

439
func isValidTLSProtocolVersion(pv openshiftconfigv1.TLSProtocolVersion) bool {
1✔
440
        switch pv {
1✔
441
        case
442
                openshiftconfigv1.VersionTLS10,
443
                openshiftconfigv1.VersionTLS11,
444
                openshiftconfigv1.VersionTLS12,
445
                openshiftconfigv1.VersionTLS13:
1✔
446
                return true
1✔
447
        }
448
        return false
1✔
449
}
450

451
func validateAffinity(affinity *corev1.Affinity) error {
1✔
452
        if affinity == nil || affinity.NodeAffinity == nil || affinity.NodeAffinity.RequiredDuringSchedulingIgnoredDuringExecution == nil {
2✔
453
                return nil
1✔
454
        }
1✔
455

456
        _, err := nodeaffinity.NewNodeSelector(affinity.NodeAffinity.RequiredDuringSchedulingIgnoredDuringExecution)
1✔
457

1✔
458
        return err
1✔
459
}
460

461
func errToResponse(err error) admission.Response {
1✔
462
        if err == nil {
2✔
463
                // Return allowed if everything succeeded.
1✔
464
                return admission.Allowed("")
1✔
465
        }
1✔
466

467
        var apiStatus apierrors.APIStatus
1✔
468
        if errors.As(err, &apiStatus) {
2✔
469
                return validationResponseFromStatus(false, apiStatus.Status())
1✔
470
        }
1✔
471

472
        var vw *ValidationWarning
1✔
473
        if errors.As(err, &vw) {
2✔
474
                return admission.Allowed("").WithWarnings(vw.Warnings()...)
1✔
475
        }
1✔
476

477
        return admission.Denied(err.Error())
1✔
478
}
479

480
func v1FGsToMap(fgs hcov1fg.HyperConvergedFeatureGates) map[string]bool {
1✔
481
        m := map[string]bool{}
1✔
482
        for _, fg := range fgs {
1✔
483
                m[fg.Name] = ptr.Deref(fg.State, hcov1fg.Enabled) == hcov1fg.Enabled
×
484
        }
×
485

486
        return m
1✔
487
}
488

489
func checkOperands(ctx context.Context, cli client.Client, logger logr.Logger, requested *hcov1.HyperConverged, isOpenshift bool) error {
1✔
490
        resources, err := getOperands(ctx, cli, isOpenshift)
1✔
491
        if err != nil {
2✔
492
                return err
1✔
493
        }
1✔
494

495
        toCtx, cancel := context.WithTimeout(ctx, updateDryRunTimeOut)
1✔
496
        defer cancel()
1✔
497

1✔
498
        eg, egCtx := xsync.WithContext(toCtx)
1✔
499
        opts := &client.UpdateOptions{DryRun: []string{metav1.DryRunAll}}
1✔
500

1✔
501
        for _, obj := range resources {
2✔
502
                func(o client.Object) {
2✔
503
                        eg.Go(func() error {
2✔
504
                                return updateOperatorCr(egCtx, cli, logger, requested, o, opts)
1✔
505
                        })
1✔
506
                }(obj)
507
        }
508

509
        return eg.Wait()
1✔
510
}
511

512
func getOperands(ctx context.Context, cli client.Client, isOpenshift bool) ([]client.Object, error) {
1✔
513
        kv := handlers.NewKubeVirtWithNameOnly()
1✔
514
        err := cli.Get(ctx, client.ObjectKeyFromObject(kv), kv)
1✔
515
        if err != nil {
2✔
516
                return nil, err
1✔
517
        }
1✔
518

519
        cdi := handlers.NewCDIWithNameOnly()
1✔
520
        err = cli.Get(ctx, client.ObjectKeyFromObject(cdi), cdi)
1✔
521
        if err != nil {
2✔
522
                return nil, err
1✔
523
        }
1✔
524

525
        cna := handlers.NewNetworkAddonsWithNameOnly()
1✔
526
        err = cli.Get(ctx, client.ObjectKeyFromObject(cna), cna)
1✔
527
        if err != nil {
2✔
528
                return nil, err
1✔
529
        }
1✔
530

531
        resources := make([]client.Object, 0, 4)
1✔
532
        resources = append(resources, kv, cdi, cna)
1✔
533

1✔
534
        if isOpenshift {
2✔
535
                ssp := handlers.NewSSPWithNameOnly()
1✔
536
                err = cli.Get(ctx, client.ObjectKeyFromObject(ssp), ssp)
1✔
537
                if err != nil {
2✔
538
                        return nil, err
1✔
539
                }
1✔
540

541
                resources = append(resources, ssp)
1✔
542
        }
543

544
        return resources, nil
1✔
545
}
546

547
func updateOperatorCr(ctx context.Context, cli client.Client, logger logr.Logger, hc *hcov1.HyperConverged, exists client.Object, opts *client.UpdateOptions) error {
1✔
548
        switch existing := exists.(type) {
1✔
549
        case *kubevirtcorev1.KubeVirt:
1✔
550
                required, err := handlers.NewKubeVirt(hc)
1✔
551
                if err != nil {
2✔
552
                        return err
1✔
553
                }
1✔
554
                required.Spec.DeepCopyInto(&existing.Spec)
1✔
555

556
        case *cdiv1beta1.CDI:
1✔
557
                required, err := handlers.NewCDI(hc)
1✔
558
                if err != nil {
2✔
559
                        return err
1✔
560
                }
1✔
561
                required.Spec.DeepCopyInto(&existing.Spec)
1✔
562

563
        case *networkaddonsv1.NetworkAddonsConfig:
1✔
564
                required, err := handlers.NewNetworkAddons(hc)
1✔
565
                if err != nil {
2✔
566
                        return err
1✔
567
                }
1✔
568
                required.Spec.DeepCopyInto(&existing.Spec)
1✔
569

570
        case *sspv1beta3.SSP:
1✔
571
                required, _, err := handlers.NewSSP(hc, true)
1✔
572
                if err != nil {
2✔
573
                        return err
1✔
574
                }
1✔
575
                required.Spec.DeepCopyInto(&existing.Spec)
1✔
576
        }
577

578
        if err := cli.Update(ctx, exists, opts); err != nil {
2✔
579
                logger.Error(err, "failed to dry-run update the object", "kind", exists.GetObjectKind())
1✔
580
                return err
1✔
581
        }
1✔
582

583
        logger.Info("dry-run update the object passed", "kind", exists.GetObjectKind())
1✔
584
        return nil
1✔
585
}
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