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

kubevirt / containerized-data-importer / #5732

24 Dec 2025 10:45PM UTC coverage: 49.382% (-9.3%) from 58.689%
#5732

push

travis-ci

web-flow
Build: bump to go 1.24.0 (#3993)

* build: use the new builder image

Bazel 6.5.0 and Go 1.24.9

https://github.com/kubevirt/containerized-data-importer/pull/3990

Signed-off-by: Adi Aloni <aaloni@redhat.com>

* build: update rules_go to v0.54.1 which supports go v1.24

https://github.com/bazel-contrib/rules_go/releases/tag/v0.54.1

Signed-off-by: Adi Aloni <aaloni@redhat.com>

* build: update to a compatible version of gazelle

https://github.com/bazel-contrib/bazel-gazelle/releases/tag/v0.39.1

Signed-off-by: Adi Aloni <aaloni@redhat.com>

* build: remove rules_proto, switch to buildozer

Newer versions of rules_go stop automatically registering certain
transitive dependencies, specifically rules_proto which is deprecated. buildtools which we
use to run buildozer depended on rules_proto until recently.

This commit removes all proto dependencies by moving to
buildifier-prebuilt to only download and use the binaries from the host
platform and make it independent of rules_go entirely (similar to how
kubevirt/kubevirt does it).

Signed-off-by: Adi Aloni <aaloni@redhat.com>

* build: bump go.1.24 & deps-update

Signed-off-by: Adi Aloni <aaloni@redhat.com>

* build: bump linters version & make format

Signed-off-by: Adi Aloni <aaloni@redhat.com>

---------

Signed-off-by: Adi Aloni <aaloni@redhat.com>

14587 of 29539 relevant lines covered (49.38%)

0.55 hits per line

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

0.0
/pkg/operator/api.go
1
/*
2
Copyright 2018 The CDI Authors.
3

4
Licensed under the Apache License, Version 2.0 (the "License");
5
you may not use this file except in compliance with the License.
6
You may obtain a copy of the License at
7

8
    http://www.apache.org/licenses/LICENSE-2.0
9

10
Unless required by applicable law or agreed to in writing, software
11
distributed under the License is distributed on an "AS IS" BASIS,
12
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
See the License for the specific language governing permissions and
14
limitations under the License.
15
*/
16

17
package operator
18

19
import (
20
        "context"
21
        "fmt"
22

23
        corev1 "k8s.io/api/core/v1"
24
        metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
25
        "k8s.io/apimachinery/pkg/types"
26
        "k8s.io/client-go/kubernetes"
27
        "k8s.io/klog/v2"
28

29
        "sigs.k8s.io/controller-runtime/pkg/client"
30

31
        cdiv1 "kubevirt.io/containerized-data-importer-api/pkg/apis/core/v1beta1"
32
        cc "kubevirt.io/containerized-data-importer/pkg/controller/common"
33
        "kubevirt.io/containerized-data-importer/pkg/operator/resources/cert"
34
        "kubevirt.io/containerized-data-importer/pkg/util"
35
)
36

37
const (
38
        // ConfigMapName is the name of the CDI Operator config map
39
        // used to determine which CDI instance is "active"
40
        // and maybe other stuff some day in the future
41
        ConfigMapName = "cdi-config"
42
)
43

44
// SetOwnerRuntime makes the current "active" CDI CR the owner of the object using runtime lib client
45
func SetOwnerRuntime(client client.Client, object metav1.Object) error {
×
46
        namespace := util.GetNamespace()
×
47
        configMap := &corev1.ConfigMap{}
×
48
        if err := client.Get(context.TODO(), types.NamespacedName{Name: ConfigMapName, Namespace: namespace}, configMap); err != nil {
×
49
                klog.Warningf("ConfigMap %s does not exist, so not assigning owner", ConfigMapName)
×
50
                return nil
×
51
        }
×
52
        return SetConfigAsOwner(configMap, object)
×
53
}
54

55
// SetOwner makes the current "active" CDI CR the owner of the object
56
func SetOwner(client kubernetes.Interface, object metav1.Object) error {
×
57
        namespace := util.GetNamespace()
×
58
        configMap, err := client.CoreV1().ConfigMaps(namespace).Get(context.TODO(), ConfigMapName, metav1.GetOptions{})
×
59
        if err != nil {
×
60
                klog.Warningf("ConfigMap %s does not exist, so not assigning owner", ConfigMapName)
×
61
                return nil
×
62
        }
×
63
        return SetConfigAsOwner(configMap, object)
×
64
}
65

66
// SetConfigAsOwner sets the passed in config map as owner of the object
67
func SetConfigAsOwner(configMap *corev1.ConfigMap, object metav1.Object) error {
×
68
        configMapOwner := getController(configMap.GetOwnerReferences())
×
69

×
70
        if configMapOwner == nil {
×
71
                return fmt.Errorf("configmap has no owner")
×
72
        }
×
73

74
        for _, o := range object.GetOwnerReferences() {
×
75
                if o.Controller != nil && *o.Controller {
×
76
                        if o.UID == configMapOwner.UID {
×
77
                                // already set to current obj
×
78
                                return nil
×
79
                        }
×
80

81
                        return fmt.Errorf("object %+v already owned by %+v", object, o)
×
82
                }
83
        }
84

85
        object.SetOwnerReferences(append(object.GetOwnerReferences(), *configMapOwner))
×
86

×
87
        return nil
×
88
}
89

90
// GetCertConfigWithDefaults returns the CDI cert config with default values when not set
91
func GetCertConfigWithDefaults(ctx context.Context, c client.Client) (*cdiv1.CDICertConfig, error) {
×
92
        cdi, err := cc.GetActiveCDI(ctx, c)
×
93
        if err != nil {
×
94
                return nil, err
×
95
        }
×
96

97
        certConfig := cdi.Spec.CertConfig
×
98
        if certConfig == nil {
×
99
                certConfig = &cdiv1.CDICertConfig{}
×
100
        }
×
101

102
        if certConfig.CA == nil || certConfig.CA.Duration == nil || certConfig.CA.RenewBefore == nil {
×
103
                certConfig.CA = &cdiv1.CertConfig{
×
104
                        Duration:    &metav1.Duration{Duration: cert.SignerLifetime},
×
105
                        RenewBefore: &metav1.Duration{Duration: cert.SignerLifetime - cert.SignerRefresh},
×
106
                }
×
107
        }
×
108

109
        if certConfig.Server == nil || certConfig.Server.Duration == nil || certConfig.Server.RenewBefore == nil {
×
110
                certConfig.Server = &cdiv1.CertConfig{
×
111
                        Duration:    &metav1.Duration{Duration: cert.ServerLifetime},
×
112
                        RenewBefore: &metav1.Duration{Duration: cert.ServerLifetime - cert.ServerRefresh},
×
113
                }
×
114
        }
×
115

116
        if certConfig.Client == nil || certConfig.Client.Duration == nil || certConfig.Client.RenewBefore == nil {
×
117
                certConfig.Client = &cdiv1.CertConfig{
×
118
                        Duration:    &metav1.Duration{Duration: cert.ClientLifetime},
×
119
                        RenewBefore: &metav1.Duration{Duration: cert.ClientLifetime - cert.ClientRefresh},
×
120
                }
×
121
        }
×
122

123
        return certConfig, nil
×
124
}
125

126
func getController(owners []metav1.OwnerReference) *metav1.OwnerReference {
×
127
        for _, owner := range owners {
×
128
                if owner.Controller != nil && *owner.Controller {
×
129
                        return &owner
×
130
                }
×
131
        }
132
        return nil
×
133
}
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