diff --git a/internal/operands/template-validator/reconcile.go b/internal/operands/template-validator/reconcile.go index 8d4556b8e..d26445845 100644 --- a/internal/operands/template-validator/reconcile.go +++ b/internal/operands/template-validator/reconcile.go @@ -72,7 +72,9 @@ func (t *templateValidator) Reconcile(request *common.Request) ([]common.Reconci reconcileConfigMap, reconcileDeployment, reconcileValidatingWebhook, - reconcilePodDisruptionBudget, + } + if !request.IsSingleReplicaTopologyMode() { + funcs = append(funcs, reconcilePodDisruptionBudget) } funcs = append(funcs, reconcileNetworkPolicies(request)...) return common.CollectResourceStatus(request, funcs...) diff --git a/internal/operands/template-validator/reconcile_test.go b/internal/operands/template-validator/reconcile_test.go index ad3e5ecff..1fdadcf7e 100644 --- a/internal/operands/template-validator/reconcile_test.go +++ b/internal/operands/template-validator/reconcile_test.go @@ -6,8 +6,9 @@ import ( . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" - securityv1 "github.com/openshift/api/security/v1" + osconfv1 "github.com/openshift/api/config/v1" + securityv1 "github.com/openshift/api/security/v1" admission "k8s.io/api/admissionregistration/v1" apps "k8s.io/api/apps/v1" core "k8s.io/api/core/v1" @@ -95,6 +96,15 @@ var _ = Describe("Template validator operand", func() { } }) + It("should not create PodDisruptionBudget when SingleReplicaTopologyMode is used", func() { + request.TopologyMode = osconfv1.SingleReplicaTopologyMode + + _, err := operand.Reconcile(&request) + Expect(err).ToNot(HaveOccurred()) + + ExpectResourceNotExists(newPodDisruptionBudget(namespace), request) + }) + It("should not update webhook CA bundle", func() { _, err := operand.Reconcile(&request) Expect(err).ToNot(HaveOccurred()) diff --git a/tests/single_node_test.go b/tests/single_node_test.go index 608002a42..29ec71273 100644 --- a/tests/single_node_test.go +++ b/tests/single_node_test.go @@ -4,9 +4,13 @@ import ( . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" + policy "k8s.io/api/policy/v1" + "k8s.io/apimachinery/pkg/api/errors" "kubevirt.io/controller-lifecycle-operator-sdk/api" + "sigs.k8s.io/controller-runtime/pkg/client" ssp "kubevirt.io/ssp-operator/api/v1beta3" + validator "kubevirt.io/ssp-operator/internal/operands/template-validator" "kubevirt.io/ssp-operator/tests/env" ) @@ -81,4 +85,10 @@ var _ = Describe("Single Node Topology", func() { deployment := getTemplateValidatorDeployment() Expect(int(deployment.Status.Replicas)).Should(Equal(0), "In Single Mode Topology the number of replicas is at most 1") }) + + It("[test_id:TODO] PodDisruptionBudget should not be created", func() { + key := client.ObjectKey{Name: validator.DeploymentName, Namespace: strategy.GetNamespace()} + pdb := &policy.PodDisruptionBudget{} + Expect(apiClient.Get(ctx, key, pdb)).To(MatchError(errors.IsNotFound, "errors.IsNotFound")) + }) }) diff --git a/tests/validator_test.go b/tests/validator_test.go index 4290d91bb..e7d848280 100644 --- a/tests/validator_test.go +++ b/tests/validator_test.go @@ -214,9 +214,14 @@ var _ = Describe("Template validator operand", func() { Entry("[test_id:4912] deployment", &deploymentRes), Entry("[test_id:TODO] network policy kube api and dns", &networkPolicyKubeAPIAndDNSRes), Entry("[test_id:TODO] network policy webhook and metrics", &networkPolicyWebhookAndMetricsRes), - Entry("[test_id:TODO] PodDisruptionBudget", &podDisruptionBudgetRes), ) + It("[test_id:TODO] PodDisruptionBudget", decorators.Conformance, func() { + strategy.SkipUnlessHighlyAvailableTopologyMode() + err := apiClient.Get(ctx, podDisruptionBudgetRes.GetKey(), podDisruptionBudgetRes.NewResource()) + Expect(err).ToNot(HaveOccurred()) + }) + DescribeTable("should set app labels", expectAppLabels, Entry("[test_id:5824]cluster role", &clusterRoleRes), Entry("[test_id:5825]cluster role binding", &clusterRoleBindingRes), @@ -228,8 +233,12 @@ var _ = Describe("Template validator operand", func() { Entry("[test_id:5828]deployment", &deploymentRes), Entry("[test_id:TODO]network policy kube api and dns", &networkPolicyKubeAPIAndDNSRes), Entry("[test_id:TODO]network policy webhook and metrics", &networkPolicyWebhookAndMetricsRes), - Entry("[test_id:TODO] PodDisruptionBudget", &podDisruptionBudgetRes), ) + + It("[test_id:TODO] should set app labels on PodDisruptionBudget", func() { + strategy.SkipUnlessHighlyAvailableTopologyMode() + expectAppLabels(&podDisruptionBudgetRes) + }) }) Context("resource deletion", func() { @@ -244,8 +253,12 @@ var _ = Describe("Template validator operand", func() { Entry("[test_id:4924] deployment", &deploymentRes), Entry("[test_id:TODO] network policy kube api and dns", &networkPolicyKubeAPIAndDNSRes), Entry("[test_id:TODO] network policy webhook and metrics", &networkPolicyWebhookAndMetricsRes), - Entry("[test_id:TODO] PodDisruptionBudget", &podDisruptionBudgetRes), ) + + It("[test_id:TODO] PodDisruptionBudget recreate after delete", decorators.Conformance, func() { + strategy.SkipUnlessHighlyAvailableTopologyMode() + expectRecreateAfterDelete(&podDisruptionBudgetRes) + }) }) Context("resource change", func() { @@ -259,9 +272,13 @@ var _ = Describe("Template validator operand", func() { Entry("[test_id:4925] deployment", &deploymentRes), Entry("[test_id:TODO] network policy kube api and dns", &networkPolicyKubeAPIAndDNSRes), Entry("[test_id:TODO] network policy webhook and metrics", &networkPolicyWebhookAndMetricsRes), - Entry("[test_id:TODO] PodDisruptionBudget", &podDisruptionBudgetRes), ) + It("[test_id:TODO] should restore modified PodDisruptionBudget", decorators.Conformance, func() { + strategy.SkipUnlessHighlyAvailableTopologyMode() + expectRestoreAfterUpdate(&podDisruptionBudgetRes) + }) + Context("with pause", func() { BeforeEach(func() { strategy.SkipSspUpdateTestsIfNeeded() @@ -281,8 +298,12 @@ var _ = Describe("Template validator operand", func() { Entry("[test_id:5539] deployment", &deploymentRes), Entry("[test_id:TODO] network policy kube api and dns", &networkPolicyKubeAPIAndDNSRes), Entry("[test_id:TODO] network policy webhook and metrics", &networkPolicyWebhookAndMetricsRes), - Entry("[test_id:TODO] PodDisruptionBudget", &podDisruptionBudgetRes), ) + + It("[test_id:TODO] should restore modified PodDisruptionBudget with pause", decorators.Conformance, func() { + strategy.SkipUnlessHighlyAvailableTopologyMode() + expectRestoreAfterUpdateWithPause(&podDisruptionBudgetRes) + }) }) DescribeTable("should restore modified app labels", expectAppLabelsRestoreAfterUpdate, @@ -295,8 +316,12 @@ var _ = Describe("Template validator operand", func() { Entry("[test_id:6209] deployment", &deploymentRes), Entry("[test_id:TODO] network policy kube api and dns", &networkPolicyKubeAPIAndDNSRes), Entry("[test_id:TODO] network policy webhook and metrics", &networkPolicyWebhookAndMetricsRes), - Entry("[test_id:TODO] PodDisruptionBudget", &podDisruptionBudgetRes), ) + + It("[test_id:TODO] should restore modified app labels on PodDisruptionBudget", func() { + strategy.SkipUnlessHighlyAvailableTopologyMode() + expectAppLabelsRestoreAfterUpdate(&podDisruptionBudgetRes) + }) }) It("[test_id:4913] should successfully start template-validator pod", decorators.Conformance, func() {