Skip to content
Open
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
2 changes: 1 addition & 1 deletion hack/deploy-karmada-operator.sh
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,4 @@ kubectl --kubeconfig="${KUBECONFIG}" --context="${CONTEXT_NAME}" apply -f "${REP
kubectl --kubeconfig="${KUBECONFIG}" --context="${CONTEXT_NAME}" apply -f "${REPO_ROOT}/operator/config/deploy/karmada-operator-deployment.yaml"

# wait karmada-operator ready
kubectl --kubeconfig="${KUBECONFIG}" --context="${CONTEXT_NAME}" wait --for=condition=Ready --timeout=30s pods -l app.kubernetes.io/name=karmada-operator -n ${KARMADA_SYSTEM_NAMESPACE}
kubectl --kubeconfig="${KUBECONFIG}" --context="${CONTEXT_NAME}" rollout status deployment/karmada-operator --timeout=90s -n ${KARMADA_SYSTEM_NAMESPACE}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to make those changes?

95 changes: 95 additions & 0 deletions test/e2e/suites/operator/validating_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
/*
Copyright 2026 The Karmada Authors.

Licensed 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 e2e

import (
"context"
"strings"

"github.com/onsi/ginkgo/v2"
"github.com/onsi/gomega"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/rand"

operatorv1alpha1 "github.com/karmada-io/karmada/operator/pkg/apis/operator/v1alpha1"
karmadacontroller "github.com/karmada-io/karmada/operator/pkg/controller/karmada"
operatorresource "github.com/karmada-io/karmada/test/e2e/framework/resource/operator"
"github.com/karmada-io/karmada/test/helper"
)

var _ = ginkgo.Describe("Karmada validation event testing", func() {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The test implementation and its scope do not align with the PR title and description. The PR description states that the test verifies validation events for missing initData (such as spec.components.karmadaAPIServer or spec.hostCluster.networking.dnsDomain), but the code actually tests an update operation on spec.crdTarball.httpSource.url. Please update the PR description or the test cases to ensure consistency.

References
  1. It is acceptable to merge code with incomplete or placeholder logic for new features when it is an intentional part of the development process.

const validationErrorMessageSubstring = "invalid CRDs remote URL"
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's have a sentinel error perhaps with a concise name in

and we can reuse it here


var karmadaName string

ginkgo.BeforeEach(func() {
karmadaName = KarmadaInstanceNamePrefix + rand.String(RandomStrLength)
})

ginkgo.AfterEach(func() {
operatorresource.DeleteKarmadaInstance(operatorClient, testNamespace, karmadaName)
})

ginkgo.It("should emit warning event and set Ready condition false when CRD tarball HTTP URL is invalid", func() {
ginkgo.By("Step 1: create the Karmada instance with an invalid CRD tarball URL", func() {
karmada := helper.NewKarmada(testNamespace, karmadaName)
karmada.Spec.CRDTarball.HTTPSource.URL = "bad-url"
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit:

Suggested change
karmada.Spec.CRDTarball.HTTPSource.URL = "bad-url"
karmada.Spec.CRDTarball.HTTPSource.URL = "invalid-url"


err := operatorresource.CreateKarmadaInstance(operatorClient, karmada)
gomega.Expect(err).ShouldNot(gomega.HaveOccurred())
})

ginkgo.By("Step 2: assert Ready condition becomes False with ValidationError reason", func() {
gomega.Eventually(func(g gomega.Gomega) {
updated, err := operatorClient.OperatorV1alpha1().Karmadas(testNamespace).Get(context.TODO(), karmadaName, metav1.GetOptions{})
g.Expect(err).ShouldNot(gomega.HaveOccurred())

var readyCond *metav1.Condition
for i := range updated.Status.Conditions {
if updated.Status.Conditions[i].Type == string(operatorv1alpha1.Ready) {
readyCond = &updated.Status.Conditions[i]
break
}
}

g.Expect(readyCond).ShouldNot(gomega.BeNil())
g.Expect(readyCond.Status).Should(gomega.Equal(metav1.ConditionFalse))
g.Expect(readyCond.Reason).Should(gomega.Equal(karmadacontroller.ValidationErrorReason))
g.Expect(readyCond.Message).Should(gomega.ContainSubstring(validationErrorMessageSubstring))
}, pollTimeout, pollInterval).Should(gomega.Succeed())
})

ginkgo.By("Step 3: assert Warning ValidationError event is emitted", func() {
gomega.Eventually(func(g gomega.Gomega) bool {
events, err := hostClient.CoreV1().Events(testNamespace).List(context.TODO(), metav1.ListOptions{})
g.Expect(err).ShouldNot(gomega.HaveOccurred())

for _, event := range events.Items {
if event.InvolvedObject.Name == karmadaName &&
event.Type == corev1.EventTypeWarning &&
event.Reason == karmadacontroller.ValidationErrorReason &&
strings.Contains(event.Message, validationErrorMessageSubstring) {
return true
}
}

return false
}, pollTimeout, pollInterval).Should(gomega.BeTrue())
})
})
})
Loading