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
31 changes: 21 additions & 10 deletions test/e2e/framework/clusterpropagationpolicy.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
apierrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
"k8s.io/client-go/util/retry"

policyv1alpha1 "github.com/karmada-io/karmada/pkg/apis/policy/v1alpha1"
karmada "github.com/karmada-io/karmada/pkg/generated/clientset/versioned"
Expand Down Expand Up @@ -61,23 +62,33 @@ func PatchClusterPropagationPolicy(client karmada.Interface, name string, patch
// UpdateClusterPropagationPolicyWithSpec update PropagationSpec with karmada client.
func UpdateClusterPropagationPolicyWithSpec(client karmada.Interface, name string, policySpec policyv1alpha1.PropagationSpec) {
ginkgo.By(fmt.Sprintf("Updating ClusterPropagationPolicy(%s) spec", name), func() {
newPolicy, err := client.PolicyV1alpha1().ClusterPropagationPolicies().Get(context.TODO(), name, metav1.GetOptions{})
gomega.Expect(err).ShouldNot(gomega.HaveOccurred())
err := retry.RetryOnConflict(retry.DefaultRetry, func() error {
newPolicy, err := client.PolicyV1alpha1().ClusterPropagationPolicies().Get(context.TODO(), name, metav1.GetOptions{})
if err != nil {
return err
}

newPolicy.Spec = policySpec
_, err = client.PolicyV1alpha1().ClusterPropagationPolicies().Update(context.TODO(), newPolicy, metav1.UpdateOptions{})
gomega.Expect(err).ShouldNot(gomega.HaveOccurred())
newPolicy.Spec = policySpec
_, err = client.PolicyV1alpha1().ClusterPropagationPolicies().Update(context.TODO(), newPolicy, metav1.UpdateOptions{})
return err
})
gomega.Expect(err).NotTo(gomega.HaveOccurred())
})
}

// UpdateClusterPropagationPolicy update ClusterPropagationPolicy resourceSelectors with karmada client.
func UpdateClusterPropagationPolicy(client karmada.Interface, name string, resourceSelectors []policyv1alpha1.ResourceSelector) {
ginkgo.By(fmt.Sprintf("Updating ClusterPropagationPolicy(%s)", name), func() {
newPolicy, err := client.PolicyV1alpha1().ClusterPropagationPolicies().Get(context.TODO(), name, metav1.GetOptions{})
gomega.Expect(err).ShouldNot(gomega.HaveOccurred())
err := retry.RetryOnConflict(retry.DefaultRetry, func() error {
newPolicy, err := client.PolicyV1alpha1().ClusterPropagationPolicies().Get(context.TODO(), name, metav1.GetOptions{})
if err != nil {
return err
}

newPolicy.Spec.ResourceSelectors = resourceSelectors
_, err = client.PolicyV1alpha1().ClusterPropagationPolicies().Update(context.TODO(), newPolicy, metav1.UpdateOptions{})
gomega.Expect(err).ShouldNot(gomega.HaveOccurred())
newPolicy.Spec.ResourceSelectors = resourceSelectors
_, err = client.PolicyV1alpha1().ClusterPropagationPolicies().Update(context.TODO(), newPolicy, metav1.UpdateOptions{})
return err
})
gomega.Expect(err).NotTo(gomega.HaveOccurred())
})
}
18 changes: 12 additions & 6 deletions test/e2e/framework/cronfederatedhpa.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"github.com/onsi/ginkgo/v2"
"github.com/onsi/gomega"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/util/retry"

autoscalingv1alpha1 "github.com/karmada-io/karmada/pkg/apis/autoscaling/v1alpha1"
karmada "github.com/karmada-io/karmada/pkg/generated/clientset/versioned"
Expand All @@ -47,11 +48,16 @@ func RemoveCronFederatedHPA(client karmada.Interface, namespace, name string) {
// UpdateCronFederatedHPAWithRule update CronFederatedHPA with karmada client.
func UpdateCronFederatedHPAWithRule(client karmada.Interface, namespace, name string, rule []autoscalingv1alpha1.CronFederatedHPARule) {
ginkgo.By(fmt.Sprintf("Updating CronFederatedHPA(%s/%s)", namespace, name), func() {
newCronFederatedHPA, err := client.AutoscalingV1alpha1().CronFederatedHPAs(namespace).Get(context.TODO(), name, metav1.GetOptions{})
gomega.Expect(err).ShouldNot(gomega.HaveOccurred())

newCronFederatedHPA.Spec.Rules = rule
_, err = client.AutoscalingV1alpha1().CronFederatedHPAs(namespace).Update(context.TODO(), newCronFederatedHPA, metav1.UpdateOptions{})
gomega.Expect(err).ShouldNot(gomega.HaveOccurred())
err := retry.RetryOnConflict(retry.DefaultRetry, func() error {
newCronFederatedHPA, err := client.AutoscalingV1alpha1().CronFederatedHPAs(namespace).Get(context.TODO(), name, metav1.GetOptions{})
if err != nil {
return err
}

newCronFederatedHPA.Spec.Rules = rule
_, err = client.AutoscalingV1alpha1().CronFederatedHPAs(namespace).Update(context.TODO(), newCronFederatedHPA, metav1.UpdateOptions{})
return err
})
gomega.Expect(err).NotTo(gomega.HaveOccurred())
})
}
18 changes: 12 additions & 6 deletions test/e2e/framework/hpa.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
autoscalingv2 "k8s.io/api/autoscaling/v2"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/util/retry"
)

// CreateHPA create HPA.
Expand All @@ -46,11 +47,16 @@ func RemoveHPA(client kubernetes.Interface, namespace, name string) {
// UpdateHPAWithMinReplicas update HPA with replicas.
func UpdateHPAWithMinReplicas(client kubernetes.Interface, namespace, name string, minReplicas int32) {
ginkgo.By(fmt.Sprintf("Updating HPA(%s/%s)", namespace, name), func() {
newHPA, err := client.AutoscalingV2().HorizontalPodAutoscalers(namespace).Get(context.TODO(), name, metav1.GetOptions{})
gomega.Expect(err).ShouldNot(gomega.HaveOccurred())

newHPA.Spec.MinReplicas = &minReplicas
_, err = client.AutoscalingV2().HorizontalPodAutoscalers(namespace).Update(context.TODO(), newHPA, metav1.UpdateOptions{})
gomega.Expect(err).ShouldNot(gomega.HaveOccurred())
err := retry.RetryOnConflict(retry.DefaultRetry, func() error {
newHPA, err := client.AutoscalingV2().HorizontalPodAutoscalers(namespace).Get(context.TODO(), name, metav1.GetOptions{})
if err != nil {
return err
}

newHPA.Spec.MinReplicas = &minReplicas
_, err = client.AutoscalingV2().HorizontalPodAutoscalers(namespace).Update(context.TODO(), newHPA, metav1.UpdateOptions{})
return err
})
gomega.Expect(err).NotTo(gomega.HaveOccurred())
})
}
16 changes: 11 additions & 5 deletions test/e2e/framework/propagationpolicy.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
apierrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
"k8s.io/client-go/util/retry"
"k8s.io/klog/v2"

policyv1alpha1 "github.com/karmada-io/karmada/pkg/apis/policy/v1alpha1"
Expand Down Expand Up @@ -78,12 +79,17 @@ func PatchPropagationPolicy(client karmada.Interface, namespace, name string, pa
// UpdatePropagationPolicyWithSpec update PropagationSpec with karmada client.
func UpdatePropagationPolicyWithSpec(client karmada.Interface, namespace, name string, policySpec policyv1alpha1.PropagationSpec) {
ginkgo.By(fmt.Sprintf("Updating PropagationPolicy(%s/%s) spec", namespace, name), func() {
newPolicy, err := client.PolicyV1alpha1().PropagationPolicies(namespace).Get(context.TODO(), name, metav1.GetOptions{})
gomega.Expect(err).ShouldNot(gomega.HaveOccurred())
err := retry.RetryOnConflict(retry.DefaultRetry, func() error {
newPolicy, err := client.PolicyV1alpha1().PropagationPolicies(namespace).Get(context.TODO(), name, metav1.GetOptions{})
if err != nil {
return err
}

newPolicy.Spec = policySpec
_, err = client.PolicyV1alpha1().PropagationPolicies(newPolicy.Namespace).Update(context.TODO(), newPolicy, metav1.UpdateOptions{})
gomega.Expect(err).ShouldNot(gomega.HaveOccurred())
newPolicy.Spec = policySpec
_, err = client.PolicyV1alpha1().PropagationPolicies(newPolicy.Namespace).Update(context.TODO(), newPolicy, metav1.UpdateOptions{})
return err
})
gomega.Expect(err).NotTo(gomega.HaveOccurred())
})
}

Expand Down
16 changes: 11 additions & 5 deletions test/e2e/framework/resource/operator/karmada.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"github.com/onsi/gomega"
apierrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/util/retry"
"k8s.io/klog/v2"

operatorv1alpha1 "github.com/karmada-io/karmada/operator/pkg/apis/operator/v1alpha1"
Expand Down Expand Up @@ -67,12 +68,17 @@ func CreateKarmadaInstance(operatorClient operator.Interface, karmada *operatorv
// UpdateKarmadaInstanceWithSpec updates karmada instance with spec.
func UpdateKarmadaInstanceWithSpec(client operator.Interface, namespace, name string, karmadaSpec operatorv1alpha1.KarmadaSpec) {
ginkgo.By(fmt.Sprintf("Updating Karmada(%s/%s) spec", namespace, name), func() {
karmada, err := client.OperatorV1alpha1().Karmadas(namespace).Get(context.TODO(), name, metav1.GetOptions{})
gomega.Expect(err).ShouldNot(gomega.HaveOccurred())
err := retry.RetryOnConflict(retry.DefaultRetry, func() error {
karmada, err := client.OperatorV1alpha1().Karmadas(namespace).Get(context.TODO(), name, metav1.GetOptions{})
if err != nil {
return err
}

karmada.Spec = karmadaSpec
_, err = client.OperatorV1alpha1().Karmadas(namespace).Update(context.TODO(), karmada, metav1.UpdateOptions{})
gomega.Expect(err).ShouldNot(gomega.HaveOccurred())
karmada.Spec = karmadaSpec
_, err = client.OperatorV1alpha1().Karmadas(namespace).Update(context.TODO(), karmada, metav1.UpdateOptions{})
return err
})
gomega.Expect(err).NotTo(gomega.HaveOccurred())
})
}

Expand Down
18 changes: 14 additions & 4 deletions test/e2e/framework/resourceregistry.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"github.com/onsi/ginkgo/v2"
"github.com/onsi/gomega"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/util/retry"

searchv1alpha1 "github.com/karmada-io/karmada/pkg/apis/search/v1alpha1"
karmada "github.com/karmada-io/karmada/pkg/generated/clientset/versioned"
Expand All @@ -44,10 +45,19 @@ func RemoveResourceRegistry(client karmada.Interface, name string) {
})
}

// UpdateResourceRegistry patch ResourceRegistry with karmada client.
func UpdateResourceRegistry(client karmada.Interface, rr *searchv1alpha1.ResourceRegistry) {
// UpdateResourceRegistryWithSpec patch ResourceRegistry with karmada client.
func UpdateResourceRegistryWithSpec(client karmada.Interface, rr *searchv1alpha1.ResourceRegistry) {
ginkgo.By(fmt.Sprintf("Update ResourceRegistry(%s)", rr.Name), func() {
_, err := client.SearchV1alpha1().ResourceRegistries().Update(context.TODO(), rr, metav1.UpdateOptions{})
gomega.Expect(err).ShouldNot(gomega.HaveOccurred())
err := retry.RetryOnConflict(retry.DefaultRetry, func() error {
latestRR, err := client.SearchV1alpha1().ResourceRegistries().Get(context.TODO(), rr.Name, metav1.GetOptions{})
if err != nil {
return err
}

latestRR.Spec = rr.Spec
_, err = client.SearchV1alpha1().ResourceRegistries().Update(context.TODO(), latestRR, metav1.UpdateOptions{})
return err
})
gomega.Expect(err).NotTo(gomega.HaveOccurred())
})
}
2 changes: 1 addition & 1 deletion test/e2e/suites/base/search_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ var _ = ginkgo.Describe("[karmada-search] karmada search testing", ginkgo.Ordere
Kind: "ClusterRoleBinding",
},
}
framework.UpdateResourceRegistry(karmadaClient, rr)
framework.UpdateResourceRegistryWithSpec(karmadaClient, rr)
searchObject(pathAllClusterRoleBindings, existsClusterRoleBindingName, true)
})
})
Expand Down