Skip to content

Commit

Permalink
virt-operator: remove leftovers from webhook unit tests
Browse files Browse the repository at this point in the history
Since we are not restricting anymore the update of workload
or infra placement configuration while VMs are running, there is
no point in testing anything related to VM existance and KV CR update
because there is no connection between these two facts, hence there
is no coverage to do in that area.

Signed-off-by: Igor Bezukh <[email protected]>
  • Loading branch information
enp0s3 committed Sep 12, 2021
1 parent a7ef4f6 commit 87bace8
Showing 2 changed files with 17 additions and 14 deletions.
29 changes: 16 additions & 13 deletions pkg/virt-operator/webhooks/kubevirt-update-admitter.go
Original file line number Diff line number Diff line change
@@ -23,15 +23,15 @@ import (
"context"
"encoding/json"
"fmt"
"reflect"

appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
"k8s.io/utils/pointer"

admissionv1 "k8s.io/api/admission/v1"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

"k8s.io/utils/pointer"

v1 "kubevirt.io/client-go/api/v1"
"kubevirt.io/client-go/kubecli"
webhookutils "kubevirt.io/kubevirt/pkg/util/webhooks"
@@ -53,7 +53,7 @@ func NewKubeVirtUpdateAdmitter(client kubecli.KubevirtClient) *KubeVirtUpdateAdm

func (admitter *KubeVirtUpdateAdmitter) Admit(ar *admissionv1.AdmissionReview) *admissionv1.AdmissionResponse {
// Get new and old KubeVirt from admission response
newKV, _, err := getAdmissionReviewKubeVirt(ar)
newKV, currKV, err := getAdmissionReviewKubeVirt(ar)
if err != nil {
return webhookutils.ToAdmissionResponseError(err)
}
@@ -67,12 +67,18 @@ func (admitter *KubeVirtUpdateAdmitter) Admit(ar *admissionv1.AdmissionReview) *
results = append(results, validateCustomizeComponents(newKV.Spec.CustomizeComponents)...)
results = append(results, validateCertificates(newKV.Spec.CertificateRotationStrategy.SelfSigned)...)

if newKV.Spec.Infra != nil && newKV.Spec.Infra.NodePlacement != nil {
results = append(results, validateInfraPlacement(newKV.Spec.Infra.NodePlacement, admitter.Client)...)
if !reflect.DeepEqual(currKV.Spec.Infra, newKV.Spec.Infra) {
if newKV.Spec.Infra != nil && newKV.Spec.Infra.NodePlacement != nil {
results = append(results,
validateInfraPlacement(newKV.Namespace, newKV.Spec.Infra.NodePlacement, admitter.Client)...)
}
}

if newKV.Spec.Workloads != nil && newKV.Spec.Workloads.NodePlacement != nil {
results = append(results, validateWorkloadPlacement(newKV.Spec.Workloads.NodePlacement, admitter.Client)...)
if !reflect.DeepEqual(currKV.Spec.Workloads, newKV.Spec.Workloads) {
if newKV.Spec.Workloads != nil && newKV.Spec.Workloads.NodePlacement != nil {
results = append(results,
validateWorkloadPlacement(newKV.Namespace, newKV.Spec.Workloads.NodePlacement, admitter.Client)...)
}
}

return validating_webhooks.NewAdmissionResponse(results)
@@ -177,13 +183,11 @@ func validateCertificates(certConfig *v1.KubeVirtSelfSignConfiguration) []metav1
return statuses
}

//validateWorkloadPlacement
func validateWorkloadPlacement(placementConfig *v1.NodePlacement, client kubecli.KubevirtClient) []metav1.StatusCause {
func validateWorkloadPlacement(namespace string, placementConfig *v1.NodePlacement, client kubecli.KubevirtClient) []metav1.StatusCause {
statuses := []metav1.StatusCause{}

const (
dsName = "placement-validation-webhook"
namespace = "default"
mockLabel = "kubevirt.io/choose-me"
podName = "placement-verification-pod"
mockUrl = "test.only:latest"
@@ -233,12 +237,11 @@ func validateWorkloadPlacement(placementConfig *v1.NodePlacement, client kubecli
return statuses
}

func validateInfraPlacement(placementConfig *v1.NodePlacement, client kubecli.KubevirtClient) []metav1.StatusCause {
func validateInfraPlacement(namespace string, placementConfig *v1.NodePlacement, client kubecli.KubevirtClient) []metav1.StatusCause {
statuses := []metav1.StatusCause{}

const (
deploymentName = "placement-validation-webhook"
namespace = "default"
mockLabel = "kubevirt.io/choose-me"
podName = "placement-verification-pod"
mockUrl = "test.only:latest"
2 changes: 1 addition & 1 deletion tests/operator_test.go
Original file line number Diff line number Diff line change
@@ -2172,7 +2172,7 @@ spec:
patchKvWorkloads(nil, false, "")
})

It("should reject infra placement configuration with incorrect toleraion operator", func() {
It("should reject infra placement configuration with incorrect toleration operator", func() {
incorrectOperator := "foo"
incorrectWorkload := v1.ComponentConfig{
NodePlacement: &v1.NodePlacement{

0 comments on commit 87bace8

Please sign in to comment.