Skip to content

Commit 0ed257d

Browse files
author
Ryan Zhang
committed
test
1 parent 05fa25e commit 0ed257d

File tree

1 file changed

+128
-1
lines changed

1 file changed

+128
-1
lines changed

test/e2e/placement_selecting_resources_test.go

Lines changed: 128 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import (
2929

3030
var (
3131
// we are propagating large secrets from hub to member clusters the timeout needs to be large.
32-
largeEventuallyDuration = time.Minute * 5
32+
largeEventuallyDuration = time.Second * 15
3333
)
3434

3535
// Note that this container will run in parallel with other containers.
@@ -1185,6 +1185,133 @@ var _ = Describe("validating CRP when selected resources cross the 1MB limit", O
11851185
})
11861186
})
11871187

1188+
// This test verifies that resources are selected and ordered correctly according to the sortResources logic
1189+
var _ = FDescribe("creating CRP and checking selected resources order", Ordered, func() {
1190+
crpName := fmt.Sprintf("test-resource-order-%d", GinkgoParallelProcess())
1191+
nsName := fmt.Sprintf("test-ns-order-%d", GinkgoParallelProcess())
1192+
var configMap *corev1.ConfigMap
1193+
var secret *corev1.Secret
1194+
var pvc *corev1.PersistentVolumeClaim
1195+
var role *rbacv1.Role
1196+
BeforeAll(func() {
1197+
By("creating test resources in specific order for ordering verification")
1198+
// Create a namespace for our test resources
1199+
ns := &corev1.Namespace{
1200+
ObjectMeta: metav1.ObjectMeta{
1201+
Name: nsName,
1202+
Labels: map[string]string{
1203+
"test-label": "selected",
1204+
},
1205+
},
1206+
}
1207+
Expect(hubClient.Create(ctx, ns)).To(Succeed(), "Failed to create test namespace")
1208+
1209+
// Create ConfigMap
1210+
configMap = &corev1.ConfigMap{
1211+
ObjectMeta: metav1.ObjectMeta{
1212+
Name: fmt.Sprintf("test-configmap-%d", GinkgoParallelProcess()),
1213+
Namespace: nsName,
1214+
},
1215+
Data: map[string]string{
1216+
"key1": "value1",
1217+
},
1218+
}
1219+
Expect(hubClient.Create(ctx, configMap)).To(Succeed(), "Failed to create ConfigMap")
1220+
1221+
// Create Secret
1222+
secret = &corev1.Secret{
1223+
ObjectMeta: metav1.ObjectMeta{
1224+
Name: fmt.Sprintf("test-secret-%d", GinkgoParallelProcess()),
1225+
Namespace: nsName,
1226+
},
1227+
StringData: map[string]string{
1228+
"username": "test-user",
1229+
"password": "test-password",
1230+
},
1231+
Type: corev1.SecretTypeOpaque,
1232+
}
1233+
Expect(hubClient.Create(ctx, secret)).To(Succeed(), "Failed to create Secret")
1234+
1235+
// Create PersistentVolumeClaim
1236+
pvc = &corev1.PersistentVolumeClaim{
1237+
ObjectMeta: metav1.ObjectMeta{
1238+
Name: fmt.Sprintf("test-pvc-%d", GinkgoParallelProcess()),
1239+
Namespace: nsName,
1240+
},
1241+
Spec: corev1.PersistentVolumeClaimSpec{
1242+
AccessModes: []corev1.PersistentVolumeAccessMode{corev1.ReadWriteOnce},
1243+
StorageClassName: ptr.To("standard"),
1244+
},
1245+
}
1246+
Expect(hubClient.Create(ctx, pvc)).To(Succeed(), "Failed to create PVC")
1247+
1248+
// Create Role
1249+
role = &rbacv1.Role{
1250+
ObjectMeta: metav1.ObjectMeta{
1251+
Name: fmt.Sprintf("test-role-%d", GinkgoParallelProcess()),
1252+
Namespace: nsName,
1253+
},
1254+
Rules: []rbacv1.PolicyRule{
1255+
{
1256+
APIGroups: []string{""},
1257+
Resources: []string{"configmaps"},
1258+
Verbs: []string{"get", "list"},
1259+
},
1260+
},
1261+
}
1262+
Expect(hubClient.Create(ctx, role)).To(Succeed(), "Failed to create Role")
1263+
1264+
// Create the CRP
1265+
crp := &placementv1beta1.ClusterResourcePlacement{
1266+
ObjectMeta: metav1.ObjectMeta{
1267+
Name: crpName,
1268+
Finalizers: []string{customDeletionBlockerFinalizer},
1269+
},
1270+
Spec: placementv1beta1.ClusterResourcePlacementSpec{
1271+
ResourceSelectors: []placementv1beta1.ClusterResourceSelector{
1272+
{
1273+
Group: "",
1274+
Kind: "Namespace",
1275+
Version: "v1",
1276+
Name: nsName,
1277+
},
1278+
},
1279+
},
1280+
}
1281+
By(fmt.Sprintf("creating placement %s", crpName))
1282+
Expect(hubClient.Create(ctx, crp)).To(Succeed(), "Failed to create CRP %s", crpName)
1283+
})
1284+
1285+
AfterAll(func() {
1286+
By(fmt.Sprintf("garbage collect all things related to placement %s", crpName))
1287+
ensureCRPAndRelatedResourcesDeleted(crpName, allMemberClusters)
1288+
1289+
// Delete the namespace which will cascade delete all resources
1290+
ns := &corev1.Namespace{
1291+
ObjectMeta: metav1.ObjectMeta{
1292+
Name: nsName,
1293+
},
1294+
}
1295+
Expect(client.IgnoreNotFound(hubClient.Delete(ctx, ns))).To(Succeed(), "Failed to delete test namespace")
1296+
})
1297+
1298+
It("should update CRP status with the correct resources and target clusters", func() {
1299+
// Define the expected resources in order
1300+
expectedResources := []placementv1beta1.ResourceIdentifier{
1301+
{Kind: "Namespace", Name: nsName, Version: "v1"},
1302+
{Kind: "ConfigMap", Name: configMap.Name, Namespace: nsName, Version: "v1"},
1303+
{Kind: "Secret", Name: secret.Name, Namespace: nsName, Version: "v1"},
1304+
{Kind: "PersistentVolumeClaim", Name: pvc.Name, Namespace: nsName, Version: "v1"},
1305+
{Kind: "Role", Name: role.Name, Namespace: nsName, Version: "v1"},
1306+
}
1307+
1308+
// Use the common crpStatusUpdatedActual function to verify the status
1309+
crpStatusUpdatedActual := crpStatusUpdatedActual(expectedResources, allMemberClusterNames, nil, "1")
1310+
Eventually(crpStatusUpdatedActual, eventuallyDuration, eventuallyInterval).Should(Succeed(),
1311+
"Failed to update CRP %s status as expected", crpName)
1312+
})
1313+
})
1314+
11881315
func createResourcesForMultipleResourceSnapshots() {
11891316
createWorkResources()
11901317

0 commit comments

Comments
 (0)