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

kubevirt / kubevirt / 53e09dbe-7149-4eef-b52c-e1d16135149a

24 Feb 2026 10:58AM UTC coverage: 71.243% (+0.07%) from 71.17%
53e09dbe-7149-4eef-b52c-e1d16135149a

push

prow

web-flow
Merge pull request #16662 from mhenriks/containerpath-volumes

VEP 165: Containerpath Volumes

411 of 454 new or added lines in 14 files covered. (90.53%)

9 existing lines in 3 files now uncovered.

74412 of 104448 relevant lines covered (71.24%)

587.5 hits per line

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

0.0
/pkg/virt-api/webhooks/mutating-webhook/mutating-webhook.go
1
/*
2
 * This file is part of the KubeVirt project
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
 * Copyright The KubeVirt Authors.
17
 *
18
 */
19

20
package mutating_webhook
21

22
import (
23
        "encoding/json"
24
        "net/http"
25

26
        admissionv1 "k8s.io/api/admission/v1"
27
        metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
28
        "k8s.io/apimachinery/pkg/runtime"
29

30
        "kubevirt.io/client-go/kubecli"
31
        "kubevirt.io/client-go/log"
32

33
        webhookutils "kubevirt.io/kubevirt/pkg/util/webhooks"
34
        "kubevirt.io/kubevirt/pkg/virt-api/webhooks"
35
        "kubevirt.io/kubevirt/pkg/virt-api/webhooks/mutating-webhook/mutators"
36
        virtconfig "kubevirt.io/kubevirt/pkg/virt-config"
37
)
38

39
type mutator interface {
40
        Mutate(*admissionv1.AdmissionReview) *admissionv1.AdmissionResponse
41
}
42

43
func serve(resp http.ResponseWriter, req *http.Request, m mutator) {
×
44
        review, err := webhookutils.GetAdmissionReview(req)
×
45
        if err != nil {
×
46
                resp.WriteHeader(http.StatusBadRequest)
×
47
                return
×
48
        }
×
49

50
        response := admissionv1.AdmissionReview{
×
51
                TypeMeta: metav1.TypeMeta{
×
52
                        APIVersion: admissionv1.SchemeGroupVersion.String(),
×
53
                        Kind:       "AdmissionReview",
×
54
                },
×
55
        }
×
56
        reviewResponse := m.Mutate(review)
×
57
        if reviewResponse != nil {
×
58
                response.Response = reviewResponse
×
59
                response.Response.UID = review.Request.UID
×
60
        }
×
61
        // reset the Object and OldObject, they are not needed in a response.
62
        review.Request.Object = runtime.RawExtension{}
×
63
        review.Request.OldObject = runtime.RawExtension{}
×
64

×
65
        responseBytes, err := json.Marshal(response)
×
66
        if err != nil {
×
67
                log.Log.Reason(err).Errorf("failed json encode webhook response")
×
68
                resp.WriteHeader(http.StatusBadRequest)
×
69
                return
×
70
        }
×
71
        if _, err := resp.Write(responseBytes); err != nil {
×
72
                log.Log.Reason(err).Errorf("failed to write webhook response")
×
73
                resp.WriteHeader(http.StatusBadRequest)
×
74
                return
×
75
        }
×
76
}
77

78
func ServeVMs(resp http.ResponseWriter, req *http.Request, clusterConfig *virtconfig.ClusterConfig, virtCli kubecli.KubevirtClient) {
×
79
        serve(resp, req, mutators.NewVMsMutator(clusterConfig, virtCli))
×
80
}
×
81

82
func ServeVMIs(resp http.ResponseWriter, req *http.Request, clusterConfig *virtconfig.ClusterConfig, informers *webhooks.Informers, kubeVirtServiceAccounts map[string]struct{}) {
×
83
        serve(resp, req, &mutators.VMIsMutator{ClusterConfig: clusterConfig, VMIPresetInformer: informers.VMIPresetInformer, KubeVirtServiceAccounts: kubeVirtServiceAccounts})
×
84
}
×
85

86
func ServeMigrationCreate(resp http.ResponseWriter, req *http.Request) {
×
87
        serve(resp, req, &mutators.MigrationCreateMutator{})
×
88
}
×
89

90
func ServeClones(resp http.ResponseWriter, req *http.Request) {
×
91
        serve(resp, req, mutators.NewCloneCreateMutator())
×
92
}
×
93

NEW
94
func ServeVirtLauncherPods(resp http.ResponseWriter, req *http.Request, clusterConfig *virtconfig.ClusterConfig, virtCli kubecli.KubevirtClient) {
×
NEW
95
        serve(resp, req, mutators.NewVirtLauncherPodMutator(clusterConfig, virtCli))
×
NEW
96
}
×
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