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

kubevirt / containerized-data-importer / #5648

30 Oct 2025 02:23PM UTC coverage: 58.818% (-0.3%) from 59.076%
#5648

Pull #3938

travis-ci

Acedus
csv-generator: add -dump-network-policies option

This commit adds the -dump-network-policies optional flag to the
csv-generator tool in order to allow dumping CDI's required network
policies in case of a restrictive environment.

Signed-off-by: Adi Aloni <aaloni@redhat.com>
Pull Request #3938: Add network policies to CDI

31 of 193 new or added lines in 7 files covered. (16.06%)

4 existing lines in 1 file now uncovered.

17270 of 29362 relevant lines covered (58.82%)

0.65 hits per line

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

60.47
/pkg/operator/resources/namespaced/factory.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 namespaced
18

19
import (
20
        "fmt"
21

22
        corev1 "k8s.io/api/core/v1"
23
        rbacv1 "k8s.io/api/rbac/v1"
24
        "k8s.io/apimachinery/pkg/runtime"
25

26
        "sigs.k8s.io/controller-runtime/pkg/client"
27

28
        sdkapi "kubevirt.io/controller-lifecycle-operator-sdk/api"
29
        utils "kubevirt.io/controller-lifecycle-operator-sdk/pkg/sdk/resources"
30
)
31

32
// FactoryArgs contains the required parameters to generate all namespaced resources
33
type FactoryArgs struct {
34
        OperatorVersion        string `required:"true" split_words:"true"`
35
        ControllerImage        string `required:"true" split_words:"true"`
36
        DeployClusterResources string `required:"true" split_words:"true"`
37
        ImporterImage          string `required:"true" split_words:"true"`
38
        ClonerImage            string `required:"true" split_words:"true"`
39
        OvirtPopulatorImage    string `required:"true" split_words:"true"`
40
        APIServerImage         string `required:"true" envconfig:"apiserver_image"`
41
        UploadProxyImage       string `required:"true" split_words:"true"`
42
        UploadServerImage      string `required:"true" split_words:"true"`
43
        Verbosity              string `required:"true"`
44
        PullPolicy             string `required:"true" split_words:"true"`
45
        ImagePullSecrets       []corev1.LocalObjectReference
46
        PriorityClassName      string
47
        Namespace              string
48
        InfraNodePlacement     *sdkapi.NodePlacement
49
        ControllerReplicas     int32
50
        APIServerReplicas      int32
51
        UploadProxyReplicas    int32
52
}
53

54
type factoryFunc func(*FactoryArgs) []client.Object
55

56
type namespaceHaver interface {
57
        SetNamespace(string)
58
        GetNamespace() string
59
}
60

61
var factoryFunctions = map[string]factoryFunc{
62
        "apiserver":   createAPIServerResources,
63
        "controller":  createControllerResources,
64
        "uploadproxy": createUploadProxyResources,
65
        "cronjob":     createCronJobResources,
66
}
67

68
var additionalFactoryFunctions = map[string]factoryFunc{
69
        "networkpolicies": createNetworkPolicies,
70
}
71

72
// CreateAllResources creates all namespaced resources
73
func CreateAllResources(args *FactoryArgs) ([]client.Object, error) {
1✔
74
        var resources []client.Object
1✔
75
        for group := range factoryFunctions {
2✔
76
                rs, err := CreateResourceGroup(group, args)
1✔
77
                if err != nil {
1✔
78
                        return nil, err
×
79
                }
×
80
                resources = append(resources, rs...)
1✔
81
        }
82
        return resources, nil
1✔
83
}
84

85
// CreateResourceGroup creates namespaced resources for a specific group/component
86
func CreateResourceGroup(group string, args *FactoryArgs) ([]client.Object, error) {
1✔
87
        f, ok := getFactoryFunc(group)
1✔
88
        if !ok {
1✔
89
                return nil, fmt.Errorf("group %s does not exist", group)
×
90
        }
×
91
        resources := f(args)
1✔
92
        for _, resource := range resources {
2✔
93
                utils.ValidateGVKs([]runtime.Object{resource})
1✔
94
                assignNamspaceIfMissing(resource, args.Namespace)
1✔
95
        }
1✔
96
        return resources, nil
1✔
97
}
98

99
func assignNamspaceIfMissing(resource client.Object, namespace string) {
1✔
100
        obj, ok := resource.(namespaceHaver)
1✔
101
        if !ok {
1✔
102
                return
×
103
        }
×
104

105
        if obj.GetNamespace() == "" {
2✔
106
                obj.SetNamespace(namespace)
1✔
107
        }
1✔
108
}
109

110
// GetRolePolicyRules returns all namespaced PolicyRules
111
func GetRolePolicyRules() []rbacv1.PolicyRule {
×
112
        result := getAPIServerNamespacedRules()
×
113
        result = append(result, getControllerNamespacedRules()...)
×
114
        result = append(result, getUploadProxyNamespacedRules()...)
×
115
        result = append(result, GetPrometheusNamespacedRules()...)
×
116
        return result
×
117
}
×
118

119
func getFactoryFunc(group string) (factoryFunc, bool) {
1✔
120
        if f, ok := factoryFunctions[group]; ok {
2✔
121
                return f, true
1✔
122
        }
1✔
NEW
123
        if f, ok := additionalFactoryFunctions[group]; ok {
×
NEW
124
                return f, true
×
NEW
125
        }
×
NEW
126
        return nil, false
×
127
}
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

© 2025 Coveralls, Inc