Add e2e test for the ReviseReplica hook
Signed-off-by: Xinzhao Xu <z2d@jifangcheng.com>
This commit is contained in:
parent
14487548dd
commit
7207dad298
|
@ -74,6 +74,24 @@ func RemoveWorkload(client dynamic.Interface, namespace, name string) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// WaitWorkloadPresentOnClusterFitWith wait workload present on member clusters sync with fit func.
|
||||||
|
func WaitWorkloadPresentOnClusterFitWith(cluster, namespace, name string, fit func(workload *workloadv1alpha1.Workload) bool) {
|
||||||
|
clusterClient := GetClusterDynamicClient(cluster)
|
||||||
|
gomega.Expect(clusterClient).ShouldNot(gomega.BeNil())
|
||||||
|
|
||||||
|
klog.Infof("Waiting for Workload(%s/%s) synced on cluster(%s)", namespace, name, cluster)
|
||||||
|
gomega.Eventually(func() bool {
|
||||||
|
workload, err := clusterClient.Resource(workloadGVR).Namespace(namespace).Get(context.TODO(), name, metav1.GetOptions{})
|
||||||
|
if err != nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
typedObj := &workloadv1alpha1.Workload{}
|
||||||
|
err = runtime.DefaultUnstructuredConverter.FromUnstructured(workload.UnstructuredContent(), typedObj)
|
||||||
|
gomega.Expect(err).ShouldNot(gomega.HaveOccurred())
|
||||||
|
return fit(typedObj)
|
||||||
|
}, pollTimeout, pollInterval).Should(gomega.Equal(true))
|
||||||
|
}
|
||||||
|
|
||||||
// WaitWorkloadDisappearOnCluster wait workload disappear on cluster until timeout.
|
// WaitWorkloadDisappearOnCluster wait workload disappear on cluster until timeout.
|
||||||
func WaitWorkloadDisappearOnCluster(cluster, namespace, name string) {
|
func WaitWorkloadDisappearOnCluster(cluster, namespace, name string) {
|
||||||
clusterClient := GetClusterDynamicClient(cluster)
|
clusterClient := GetClusterDynamicClient(cluster)
|
||||||
|
|
|
@ -10,7 +10,9 @@ import (
|
||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
"k8s.io/apimachinery/pkg/util/rand"
|
"k8s.io/apimachinery/pkg/util/rand"
|
||||||
"k8s.io/klog/v2"
|
"k8s.io/klog/v2"
|
||||||
|
"k8s.io/utils/pointer"
|
||||||
|
|
||||||
|
workloadv1alpha1 "github.com/karmada-io/karmada/examples/customresourceinterpreter/apis/workload/v1alpha1"
|
||||||
policyv1alpha1 "github.com/karmada-io/karmada/pkg/apis/policy/v1alpha1"
|
policyv1alpha1 "github.com/karmada-io/karmada/pkg/apis/policy/v1alpha1"
|
||||||
"github.com/karmada-io/karmada/pkg/util/names"
|
"github.com/karmada-io/karmada/pkg/util/names"
|
||||||
"github.com/karmada-io/karmada/test/e2e/framework"
|
"github.com/karmada-io/karmada/test/e2e/framework"
|
||||||
|
@ -121,4 +123,59 @@ var _ = ginkgo.Describe("Resource interpreter webhook testing", func() {
|
||||||
framework.RemovePropagationPolicy(karmadaClient, policy.Namespace, policy.Name)
|
framework.RemovePropagationPolicy(karmadaClient, policy.Namespace, policy.Name)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
ginkgo.Context("InterpreterOperation ReviseReplica testing", func() {
|
||||||
|
policyNamespace := testNamespace
|
||||||
|
policyName := workloadNamePrefix + rand.String(RandomStrLength)
|
||||||
|
workloadNamespace := testNamespace
|
||||||
|
workloadName := policyName
|
||||||
|
workload := testhelper.NewWorkload(workloadNamespace, workloadName)
|
||||||
|
|
||||||
|
ginkgo.It("ReviseReplica testing", func() {
|
||||||
|
sumWeight := 0
|
||||||
|
staticWeightLists := make([]policyv1alpha1.StaticClusterWeight, 0)
|
||||||
|
for index, clusterName := range framework.ClusterNames() {
|
||||||
|
staticWeightList := policyv1alpha1.StaticClusterWeight{
|
||||||
|
TargetCluster: policyv1alpha1.ClusterAffinity{
|
||||||
|
ClusterNames: []string{clusterName},
|
||||||
|
},
|
||||||
|
Weight: int64(index + 1),
|
||||||
|
}
|
||||||
|
sumWeight += index + 1
|
||||||
|
staticWeightLists = append(staticWeightLists, staticWeightList)
|
||||||
|
}
|
||||||
|
workload.Spec.Replicas = pointer.Int32Ptr(int32(sumWeight))
|
||||||
|
policy := testhelper.NewPropagationPolicy(policyNamespace, policyName, []policyv1alpha1.ResourceSelector{
|
||||||
|
{
|
||||||
|
APIVersion: workload.APIVersion,
|
||||||
|
Kind: workload.Kind,
|
||||||
|
Name: workload.Name,
|
||||||
|
},
|
||||||
|
}, policyv1alpha1.Placement{
|
||||||
|
ClusterAffinity: &policyv1alpha1.ClusterAffinity{
|
||||||
|
ClusterNames: framework.ClusterNames(),
|
||||||
|
},
|
||||||
|
ReplicaScheduling: &policyv1alpha1.ReplicaSchedulingStrategy{
|
||||||
|
ReplicaDivisionPreference: policyv1alpha1.ReplicaDivisionPreferenceWeighted,
|
||||||
|
ReplicaSchedulingType: policyv1alpha1.ReplicaSchedulingTypeDivided,
|
||||||
|
WeightPreference: &policyv1alpha1.ClusterPreferences{
|
||||||
|
StaticWeightList: staticWeightLists,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
framework.CreateWorkload(dynamicClient, workload)
|
||||||
|
framework.CreatePropagationPolicy(karmadaClient, policy)
|
||||||
|
|
||||||
|
for index, clusterName := range framework.ClusterNames() {
|
||||||
|
framework.WaitWorkloadPresentOnClusterFitWith(clusterName, workload.Namespace, workload.Name, func(workload *workloadv1alpha1.Workload) bool {
|
||||||
|
return *workload.Spec.Replicas == int32(index+1)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
framework.RemoveWorkload(dynamicClient, workload.Namespace, workload.Name)
|
||||||
|
framework.WaitWorkloadDisappearOnClusters(framework.ClusterNames(), workload.Namespace, workload.Name)
|
||||||
|
framework.RemovePropagationPolicy(karmadaClient, policy.Namespace, policy.Name)
|
||||||
|
})
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in New Issue