@@ -1191,11 +1191,12 @@ func TestIsDiffedResourcePlacementEqual(t *testing.T) {
11911191 }
11921192}
11931193
1194- func TestShouldPropagateObj_PodAndReplicaSet (t * testing.T ) {
1194+ func TestShouldPropagateObj (t * testing.T ) {
11951195 tests := []struct {
11961196 name string
11971197 obj map [string ]interface {}
11981198 ownerReferences []metav1.OwnerReference
1199+ enableWorkload bool
11991200 want bool
12001201 }{
12011202 {
@@ -1209,6 +1210,21 @@ func TestShouldPropagateObj_PodAndReplicaSet(t *testing.T) {
12091210 },
12101211 },
12111212 ownerReferences : nil ,
1213+ enableWorkload : true ,
1214+ want : true ,
1215+ },
1216+ {
1217+ name : "standalone replicaset without ownerReferences should propagate if workload is disabled" ,
1218+ obj : map [string ]interface {}{
1219+ "apiVersion" : "apps/v1" ,
1220+ "kind" : "ReplicaSet" ,
1221+ "metadata" : map [string ]interface {}{
1222+ "name" : "standalone-rs" ,
1223+ "namespace" : "default" ,
1224+ },
1225+ },
1226+ ownerReferences : nil ,
1227+ enableWorkload : false ,
12121228 want : true ,
12131229 },
12141230 {
@@ -1222,6 +1238,7 @@ func TestShouldPropagateObj_PodAndReplicaSet(t *testing.T) {
12221238 },
12231239 },
12241240 ownerReferences : nil ,
1241+ enableWorkload : true ,
12251242 want : true ,
12261243 },
12271244 {
@@ -1242,7 +1259,8 @@ func TestShouldPropagateObj_PodAndReplicaSet(t *testing.T) {
12421259 UID : "12345" ,
12431260 },
12441261 },
1245- want : false ,
1262+ enableWorkload : true ,
1263+ want : false ,
12461264 },
12471265 {
12481266 name : "pod owned by replicaset - passes ShouldPropagateObj but filtered by resource config" ,
@@ -1262,7 +1280,8 @@ func TestShouldPropagateObj_PodAndReplicaSet(t *testing.T) {
12621280 UID : "67890" ,
12631281 },
12641282 },
1265- want : true , // ShouldPropagateObj doesn't filter Pods - they're filtered by NewResourceConfig
1283+ enableWorkload : false ,
1284+ want : true , // ShouldPropagateObj doesn't filter Pods - they're filtered by NewResourceConfig
12661285 },
12671286 {
12681287 name : "controllerrevision owned by daemonset should NOT propagate" ,
@@ -1282,7 +1301,8 @@ func TestShouldPropagateObj_PodAndReplicaSet(t *testing.T) {
12821301 UID : "abcdef" ,
12831302 },
12841303 },
1285- want : false ,
1304+ enableWorkload : false ,
1305+ want : false ,
12861306 },
12871307 {
12881308 name : "controllerrevision owned by statefulset should NOT propagate" ,
@@ -1302,7 +1322,8 @@ func TestShouldPropagateObj_PodAndReplicaSet(t *testing.T) {
13021322 UID : "fedcba" ,
13031323 },
13041324 },
1305- want : false ,
1325+ enableWorkload : false ,
1326+ want : false ,
13061327 },
13071328 {
13081329 name : "standalone controllerrevision without owner should propagate" ,
@@ -1315,10 +1336,25 @@ func TestShouldPropagateObj_PodAndReplicaSet(t *testing.T) {
13151336 },
13161337 },
13171338 ownerReferences : nil ,
1339+ enableWorkload : false ,
1340+ want : true ,
1341+ },
1342+ {
1343+ name : "PVC should propagate when workload is disabled" ,
1344+ obj : map [string ]interface {}{
1345+ "apiVersion" : "v1" ,
1346+ "kind" : "PersistentVolumeClaim" ,
1347+ "metadata" : map [string ]interface {}{
1348+ "name" : "test-pvc" ,
1349+ "namespace" : "default" ,
1350+ },
1351+ },
1352+ ownerReferences : nil ,
1353+ enableWorkload : false ,
13181354 want : true ,
13191355 },
13201356 {
1321- name : "PersistentVolumeClaim should NOT propagate" ,
1357+ name : "PVC should NOT propagate when workload is enabled " ,
13221358 obj : map [string ]interface {}{
13231359 "apiVersion" : "v1" ,
13241360 "kind" : "PersistentVolumeClaim" ,
@@ -1328,8 +1364,30 @@ func TestShouldPropagateObj_PodAndReplicaSet(t *testing.T) {
13281364 },
13291365 },
13301366 ownerReferences : nil ,
1367+ enableWorkload : true ,
13311368 want : false ,
13321369 },
1370+ {
1371+ name : "PVC with ownerReferences should NOT propagate when workload is enabled" ,
1372+ obj : map [string ]interface {}{
1373+ "apiVersion" : "v1" ,
1374+ "kind" : "PersistentVolumeClaim" ,
1375+ "metadata" : map [string ]interface {}{
1376+ "name" : "data-statefulset-0" ,
1377+ "namespace" : "default" ,
1378+ },
1379+ },
1380+ ownerReferences : []metav1.OwnerReference {
1381+ {
1382+ APIVersion : "apps/v1" ,
1383+ Kind : "StatefulSet" ,
1384+ Name : "statefulset" ,
1385+ UID : "sts-uid" ,
1386+ },
1387+ },
1388+ enableWorkload : true ,
1389+ want : false ,
1390+ },
13331391 }
13341392
13351393 for _ , tt := range tests {
@@ -1339,7 +1397,7 @@ func TestShouldPropagateObj_PodAndReplicaSet(t *testing.T) {
13391397 uObj .SetOwnerReferences (tt .ownerReferences )
13401398 }
13411399
1342- got , err := ShouldPropagateObj (nil , uObj )
1400+ got , err := ShouldPropagateObj (nil , uObj , tt . enableWorkload )
13431401 if err != nil {
13441402 t .Errorf ("ShouldPropagateObj() error = %v" , err )
13451403 return
0 commit comments