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

kubevirt / containerized-data-importer / #4794

14 Jul 2024 06:12PM UTC coverage: 58.983% (+0.01%) from 58.972%
#4794

push

travis-ci

web-flow
update to k8s 1.30 libs and controller-runtime 0.18.4 (#3336)

* make deps-update

Signed-off-by: Michael Henriksen <mhenriks@redhat.com>

* ReourceRequirements -> VolumeResourceRequirements

Signed-off-by: Michael Henriksen <mhenriks@redhat.com>

* fix calls to controller.Watch()

controller-runtime changed the API!

Signed-off-by: Michael Henriksen <mhenriks@redhat.com>

* Fix errors with actual openshift/library-go lib

Signed-off-by: Michael Henriksen <mhenriks@redhat.com>

* make all works now and everything compiles

Signed-off-by: Michael Henriksen <mhenriks@redhat.com>

* fix "make update-codegen" because generate_groups.sh deprecated

Signed-off-by: Michael Henriksen <mhenriks@redhat.com>

* run "make generate"

Signed-off-by: Michael Henriksen <mhenriks@redhat.com>

* fix transfer unittest because of change to controller-runtime

Signed-off-by: Michael Henriksen <mhenriks@redhat.com>

---------

Signed-off-by: Michael Henriksen <mhenriks@redhat.com>

6 of 238 new or added lines in 24 files covered. (2.52%)

10 existing lines in 4 files now uncovered.

16454 of 27896 relevant lines covered (58.98%)

0.65 hits per line

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

58.24
/pkg/operator/controller/route.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 controller
18

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

23
        "github.com/go-logr/logr"
24
        routev1 "github.com/openshift/api/route/v1"
25

26
        corev1 "k8s.io/api/core/v1"
27
        "k8s.io/apimachinery/pkg/api/errors"
28
        "k8s.io/apimachinery/pkg/api/meta"
29
        metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
30
        "k8s.io/apimachinery/pkg/runtime"
31

32
        "sigs.k8s.io/controller-runtime/pkg/client"
33
        "sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
34
        "sigs.k8s.io/controller-runtime/pkg/source"
35

36
        cc "kubevirt.io/containerized-data-importer/pkg/controller/common"
37
        "kubevirt.io/containerized-data-importer/pkg/util"
38
)
39

40
const (
41
        uploadProxyServiceName = "cdi-uploadproxy"
42
        uploadProxyRouteName   = uploadProxyServiceName
43
        uploadProxyCABundle    = "cdi-uploadproxy-signer-bundle"
44
)
45

46
func ensureUploadProxyRouteExists(ctx context.Context, logger logr.Logger, c client.Client, scheme *runtime.Scheme, owner metav1.Object) error {
1✔
47
        namespace := owner.GetNamespace()
1✔
48
        if namespace == "" {
1✔
49
                return fmt.Errorf("cluster scoped owner not supported")
×
50
        }
×
51

52
        cm := &corev1.ConfigMap{}
1✔
53
        key := client.ObjectKey{Namespace: namespace, Name: uploadProxyCABundle}
1✔
54
        if err := c.Get(ctx, key, cm); err != nil {
1✔
55
                if errors.IsNotFound(err) {
×
56
                        logger.V(3).Info("upload proxy ca cert doesn't exist yet")
×
57
                        return nil
×
58
                }
×
59
                return err
×
60
        }
61

62
        cert, exists := cm.Data["ca-bundle.crt"]
1✔
63
        if !exists {
1✔
64
                return fmt.Errorf("unexpected ConfigMap format, 'ca-bundle.crt' key missing")
×
65
        }
×
66

67
        cr, err := cc.GetActiveCDI(ctx, c)
1✔
68
        if err != nil {
1✔
69
                return err
×
70
        }
×
71
        if cr == nil {
1✔
72
                return fmt.Errorf("no active CDI")
×
73
        }
×
74
        installerLabels := util.GetRecommendedInstallerLabelsFromCr(cr)
1✔
75

1✔
76
        desiredRoute := &routev1.Route{
1✔
77
                ObjectMeta: metav1.ObjectMeta{
1✔
78
                        Name:      uploadProxyRouteName,
1✔
79
                        Namespace: namespace,
1✔
80
                        Labels: map[string]string{
1✔
81
                                "cdi.kubevirt.io": "",
1✔
82
                        },
1✔
83
                        Annotations: map[string]string{
1✔
84
                                // long timeout here to make sure client connection doesn't die during qcow->raw conversion
1✔
85
                                "haproxy.router.openshift.io/timeout": "60m",
1✔
86
                        },
1✔
87
                },
1✔
88
                Spec: routev1.RouteSpec{
1✔
89
                        To: routev1.RouteTargetReference{
1✔
90
                                Kind: "Service",
1✔
91
                                Name: uploadProxyServiceName,
1✔
92
                        },
1✔
93
                        TLS: &routev1.TLSConfig{
1✔
94
                                Termination:                   routev1.TLSTerminationReencrypt,
1✔
95
                                InsecureEdgeTerminationPolicy: routev1.InsecureEdgeTerminationPolicyRedirect,
1✔
96
                                DestinationCACertificate:      cert,
1✔
97
                        },
1✔
98
                },
1✔
99
        }
1✔
100
        util.SetRecommendedLabels(desiredRoute, installerLabels, "cdi-operator")
1✔
101

1✔
102
        currentRoute := &routev1.Route{}
1✔
103
        key = client.ObjectKey{Namespace: namespace, Name: uploadProxyRouteName}
1✔
104
        err = c.Get(ctx, key, currentRoute)
1✔
105
        if err == nil {
2✔
106
                if currentRoute.Spec.To.Kind != desiredRoute.Spec.To.Kind ||
1✔
107
                        currentRoute.Spec.To.Name != desiredRoute.Spec.To.Name ||
1✔
108
                        currentRoute.Spec.TLS == nil ||
1✔
109
                        currentRoute.Spec.TLS.Termination != desiredRoute.Spec.TLS.Termination ||
1✔
110
                        currentRoute.Spec.TLS.DestinationCACertificate != desiredRoute.Spec.TLS.DestinationCACertificate {
1✔
111
                        currentRoute.Spec = desiredRoute.Spec
×
112
                        return c.Update(ctx, currentRoute)
×
113
                }
×
114

115
                return nil
1✔
116
        }
117

118
        if meta.IsNoMatchError(err) {
1✔
119
                // not in openshift
×
120
                logger.V(3).Info("No match error for Route, must not be in openshift")
×
121
                return nil
×
122
        }
×
123

124
        if !errors.IsNotFound(err) {
1✔
125
                return err
×
126
        }
×
127

128
        if err = controllerutil.SetControllerReference(owner, desiredRoute, scheme); err != nil {
1✔
129
                return err
×
130
        }
×
131

132
        return c.Create(ctx, desiredRoute)
1✔
133
}
134

135
func (r *ReconcileCDI) watchRoutes() error {
×
136
        err := r.uncachedClient.List(context.TODO(), &routev1.RouteList{}, &client.ListOptions{
×
137
                Namespace: util.GetNamespace(),
×
138
                Limit:     1,
×
139
        })
×
140
        if err == nil {
×
NEW
141
                var route client.Object = &routev1.Route{}
×
NEW
142
                return r.controller.Watch(source.Kind(r.getCache(), route, enqueueCDI(r.client)))
×
143
        }
×
144
        if meta.IsNoMatchError(err) {
×
145
                log.Info("Not watching Routes")
×
146
                return nil
×
147
        }
×
148

149
        return err
×
150
}
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