Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion internal/operands/template-validator/reconcile.go
Original file line number Diff line number Diff line change
Expand Up @@ -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...)
Expand Down
12 changes: 11 additions & 1 deletion internal/operands/template-validator/reconcile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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())
Expand Down
10 changes: 10 additions & 0 deletions tests/single_node_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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"))
})
})
37 changes: 31 additions & 6 deletions tests/validator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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() {
Expand All @@ -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() {
Expand All @@ -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()
Expand All @@ -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,
Expand All @@ -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() {
Expand Down