Skip to content

Commit 519aa82

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

File tree

1 file changed

+92
-0
lines changed

1 file changed

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

0 commit comments

Comments
 (0)