Skip to content

Commit 3e436ae

Browse files
committed
test(e2e): add operator initData validation event test
Signed-off-by: manmathbh <manmathcode@gmail.com>
1 parent 3424bc7 commit 3e436ae

File tree

1 file changed

+95
-0
lines changed

1 file changed

+95
-0
lines changed
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
/*
2+
Copyright 2026 The Karmada Authors.
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+
17+
package e2e
18+
19+
import (
20+
"context"
21+
"strings"
22+
23+
"github.com/onsi/ginkgo/v2"
24+
"github.com/onsi/gomega"
25+
corev1 "k8s.io/api/core/v1"
26+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
27+
"k8s.io/apimachinery/pkg/util/rand"
28+
29+
operatorv1alpha1 "github.com/karmada-io/karmada/operator/pkg/apis/operator/v1alpha1"
30+
karmadacontroller "github.com/karmada-io/karmada/operator/pkg/controller/karmada"
31+
operatorresource "github.com/karmada-io/karmada/test/e2e/framework/resource/operator"
32+
"github.com/karmada-io/karmada/test/helper"
33+
)
34+
35+
var _ = ginkgo.Describe("Karmada validation event testing", func() {
36+
const validationErrorMessageSubstring = "invalid CRDs remote URL"
37+
38+
var karmadaName string
39+
40+
ginkgo.BeforeEach(func() {
41+
karmadaName = KarmadaInstanceNamePrefix + rand.String(RandomStrLength)
42+
})
43+
44+
ginkgo.AfterEach(func() {
45+
operatorresource.DeleteKarmadaInstance(operatorClient, testNamespace, karmadaName)
46+
})
47+
48+
ginkgo.It("should emit warning event and set Ready condition false when CRD tarball HTTP URL is invalid", func() {
49+
ginkgo.By("Step 1: create the Karmada instance with an invalid CRD tarball URL", func() {
50+
karmada := helper.NewKarmada(testNamespace, karmadaName)
51+
karmada.Spec.CRDTarball.HTTPSource.URL = "bad-url"
52+
53+
err := operatorresource.CreateKarmadaInstance(operatorClient, karmada)
54+
gomega.Expect(err).ShouldNot(gomega.HaveOccurred())
55+
})
56+
57+
ginkgo.By("Step 2: assert Ready condition becomes False with ValidationError reason", func() {
58+
gomega.Eventually(func(g gomega.Gomega) {
59+
updated, err := operatorClient.OperatorV1alpha1().Karmadas(testNamespace).Get(context.TODO(), karmadaName, metav1.GetOptions{})
60+
g.Expect(err).ShouldNot(gomega.HaveOccurred())
61+
62+
var readyCond *metav1.Condition
63+
for i := range updated.Status.Conditions {
64+
if updated.Status.Conditions[i].Type == string(operatorv1alpha1.Ready) {
65+
readyCond = &updated.Status.Conditions[i]
66+
break
67+
}
68+
}
69+
70+
g.Expect(readyCond).ShouldNot(gomega.BeNil())
71+
g.Expect(readyCond.Status).Should(gomega.Equal(metav1.ConditionFalse))
72+
g.Expect(readyCond.Reason).Should(gomega.Equal(karmadacontroller.ValidationErrorReason))
73+
g.Expect(readyCond.Message).Should(gomega.ContainSubstring(validationErrorMessageSubstring))
74+
}, pollTimeout, pollInterval).Should(gomega.Succeed())
75+
})
76+
77+
ginkgo.By("Step 3: assert Warning ValidationError event is emitted", func() {
78+
gomega.Eventually(func(g gomega.Gomega) bool {
79+
events, err := hostClient.CoreV1().Events(testNamespace).List(context.TODO(), metav1.ListOptions{})
80+
g.Expect(err).ShouldNot(gomega.HaveOccurred())
81+
82+
for _, event := range events.Items {
83+
if event.InvolvedObject.Name == karmadaName &&
84+
event.Type == corev1.EventTypeWarning &&
85+
event.Reason == karmadacontroller.ValidationErrorReason &&
86+
strings.Contains(event.Message, validationErrorMessageSubstring) {
87+
return true
88+
}
89+
}
90+
91+
return false
92+
}, pollTimeout, pollInterval).Should(gomega.BeTrue())
93+
})
94+
})
95+
})

0 commit comments

Comments
 (0)