This is an automated email from the ASF dual-hosted git repository. astefanutti pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/camel-k.git
commit 73f5970a5722455dbfcd5d58cb871c0418e311b9 Author: Antonin Stefanutti <anto...@stefanutti.fr> AuthorDate: Wed Sep 22 14:52:40 2021 +0200 fix(e2e): Update PodDisruptionBudget test with k8s 1.21 API --- e2e/common/operator_metrics_test.go | 8 ----- e2e/common/traits/pdb_test.go | 64 +++++++++++++++++-------------------- e2e/support/test_util.go | 37 +++++++++++++++++++++ 3 files changed, 67 insertions(+), 42 deletions(-) diff --git a/e2e/common/operator_metrics_test.go b/e2e/common/operator_metrics_test.go index dc10029..b511aa4 100644 --- a/e2e/common/operator_metrics_test.go +++ b/e2e/common/operator_metrics_test.go @@ -486,14 +486,6 @@ func parsePrometheusData(data []byte) (map[string]*prometheus.MetricFamily, erro return parser.TextToMetricFamilies(bytes.NewReader(data)) } -func EqualP(expected interface{}) types.GomegaMatcher { - return PointTo(Equal(expected)) -} - -func MatchFieldsP(options Options, fields Fields) types.GomegaMatcher { - return PointTo(MatchFields(options, fields)) -} - func stringP(s string) *string { return &s } diff --git a/e2e/common/traits/pdb_test.go b/e2e/common/traits/pdb_test.go index fdb9691..807c57c 100644 --- a/e2e/common/traits/pdb_test.go +++ b/e2e/common/traits/pdb_test.go @@ -26,18 +26,18 @@ import ( "testing" . "github.com/onsi/gomega" - "github.com/onsi/gomega/gstruct" + . "github.com/onsi/gomega/gstruct" - v1 "k8s.io/api/core/v1" + corev1 "k8s.io/api/core/v1" policy "k8s.io/api/policy/v1beta1" "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/util/intstr" - "sigs.k8s.io/controller-runtime/pkg/client" + ctrl "sigs.k8s.io/controller-runtime/pkg/client" . "github.com/apache/camel-k/e2e/support" - camelv1 "github.com/apache/camel-k/pkg/apis/camel/v1" + v1 "github.com/apache/camel-k/pkg/apis/camel/v1" ) func TestPodDisruptionBudgetTrait(t *testing.T) { @@ -50,52 +50,48 @@ func TestPodDisruptionBudgetTrait(t *testing.T) { "-t", "pdb.min-available=2", ).Execute()).To(Succeed()) - Eventually(IntegrationPodPhase(ns, name), TestTimeoutLong).Should(Equal(v1.PodRunning)) - Eventually(IntegrationCondition(ns, name, camelv1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(v1.ConditionTrue)) + Eventually(IntegrationPodPhase(ns, name), TestTimeoutLong).Should(Equal(corev1.PodRunning)) + Eventually(IntegrationCondition(ns, name, v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) Eventually(IntegrationLogs(ns, name), TestTimeoutShort).Should(ContainSubstring("Magicstring!")) // Check PodDisruptionBudget Eventually(podDisruptionBudget(ns, name), TestTimeoutShort).ShouldNot(BeNil()) pdb := podDisruptionBudget(ns, name)() // Assert PDB Spec - Expect(pdb.Spec.MinAvailable).To(gstruct.PointTo(Equal(intstr.FromInt(2)))) + Expect(pdb.Spec.MinAvailable).To(PointTo(Equal(intstr.FromInt(2)))) // Assert PDB Status - Eventually(podDisruptionBudget(ns, name), TestTimeoutShort).Should(gstruct.PointTo(gstruct.MatchFields( - gstruct.IgnoreExtras, - gstruct.Fields{ - "Status": Equal(policy.PodDisruptionBudgetStatus{ - ObservedGeneration: 1, - DisruptionsAllowed: 0, - CurrentHealthy: 1, - DesiredHealthy: 2, - ExpectedPods: 1, + Eventually(podDisruptionBudget(ns, name), TestTimeoutShort). + Should(MatchFieldsP(IgnoreExtras, Fields{ + "Status": MatchFields(IgnoreExtras, Fields{ + "ObservedGeneration": BeNumerically("==", 1), + "DisruptionsAllowed": BeNumerically("==", 0), + "CurrentHealthy": BeNumerically("==", 1), + "DesiredHealthy": BeNumerically("==", 2), + "ExpectedPods": BeNumerically("==", 1), }), - }), - )) + })) // Scale Integration Expect(ScaleIntegration(ns, name, 2)).To(Succeed()) Eventually(IntegrationPods(ns, name), TestTimeoutMedium).Should(HaveLen(2)) Eventually(IntegrationStatusReplicas(ns, name), TestTimeoutShort). - Should(gstruct.PointTo(BeNumerically("==", 2))) - Eventually(IntegrationCondition(ns, name, camelv1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(v1.ConditionTrue)) + Should(PointTo(BeNumerically("==", 2))) + Eventually(IntegrationCondition(ns, name, v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) // Check PodDisruptionBudget pdb = podDisruptionBudget(ns, name)() Expect(pdb).NotTo(BeNil()) // Assert PDB Status according to the scale change - Eventually(podDisruptionBudget(ns, name), TestTimeoutShort).Should(gstruct.PointTo(gstruct.MatchFields( - gstruct.IgnoreExtras, - gstruct.Fields{ - "Status": Equal(policy.PodDisruptionBudgetStatus{ - ObservedGeneration: 1, - DisruptionsAllowed: 0, - CurrentHealthy: 2, - DesiredHealthy: 2, - ExpectedPods: 2, + Eventually(podDisruptionBudget(ns, name), TestTimeoutShort). + Should(MatchFieldsP(IgnoreExtras, Fields{ + "Status": MatchFields(IgnoreExtras, Fields{ + "ObservedGeneration": BeNumerically("==", 1), + "DisruptionsAllowed": BeNumerically("==", 0), + "CurrentHealthy": BeNumerically("==", 2), + "DesiredHealthy": BeNumerically("==", 2), + "ExpectedPods": BeNumerically("==", 2), }), - }), - )) + })) // Eviction attempt pods := IntegrationPods(ns, name)() @@ -127,8 +123,8 @@ func TestPodDisruptionBudgetTrait(t *testing.T) { Expect(ScaleIntegration(ns, name, 3)).To(Succeed()) Eventually(IntegrationPods(ns, name), TestTimeoutMedium).Should(HaveLen(3)) Eventually(IntegrationStatusReplicas(ns, name), TestTimeoutShort). - Should(gstruct.PointTo(BeNumerically("==", 3))) - Eventually(IntegrationCondition(ns, name, camelv1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(v1.ConditionTrue)) + Should(PointTo(BeNumerically("==", 3))) + Eventually(IntegrationCondition(ns, name, v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) pods = IntegrationPods(ns, name)() Expect(pods).To(HaveLen(3)) @@ -155,7 +151,7 @@ func podDisruptionBudget(ns string, name string) func() *policy.PodDisruptionBud Name: name, }, } - err := TestClient().Get(TestContext, client.ObjectKeyFromObject(&pdb), &pdb) + err := TestClient().Get(TestContext, ctrl.ObjectKeyFromObject(&pdb), &pdb) if err != nil && errors.IsNotFound(err) { return nil } else if err != nil { diff --git a/e2e/support/test_util.go b/e2e/support/test_util.go new file mode 100644 index 0000000..d627ccc --- /dev/null +++ b/e2e/support/test_util.go @@ -0,0 +1,37 @@ +// +build integration + +// To enable compilation of this file in Goland, go to "Settings -> Go -> Vendoring & Build Tags -> Custom Tags" and add "integration" + +/* +Licensed to the Apache Software Foundation (ASF) under one or more +contributor license agreements. See the NOTICE file distributed with +this work for additional information regarding copyright ownership. +The ASF licenses this file to You under the Apache License, Version 2.0 +(the "License"); you may not use this file except in compliance with +the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package support + +import ( + . "github.com/onsi/gomega" + . "github.com/onsi/gomega/gstruct" + + "github.com/onsi/gomega/types" +) + +func EqualP(expected interface{}) types.GomegaMatcher { + return PointTo(Equal(expected)) +} + +func MatchFieldsP(options Options, fields Fields) types.GomegaMatcher { + return PointTo(MatchFields(options, fields)) +}