|
6 | 6 |
|
7 | 7 | "github.com/google/go-cmp/cmp" |
8 | 8 | metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" |
9 | | - "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" |
10 | 9 | "k8s.io/utils/ptr" |
11 | 10 |
|
12 | 11 | fleetv1beta1 "github.com/kubefleet-dev/kubefleet/apis/placement/v1beta1" |
@@ -1190,221 +1189,3 @@ func TestIsDiffedResourcePlacementEqual(t *testing.T) { |
1190 | 1189 | }) |
1191 | 1190 | } |
1192 | 1191 | } |
1193 | | - |
1194 | | -func TestShouldPropagateObj(t *testing.T) { |
1195 | | - tests := []struct { |
1196 | | - name string |
1197 | | - obj map[string]interface{} |
1198 | | - ownerReferences []metav1.OwnerReference |
1199 | | - enableWorkload bool |
1200 | | - want bool |
1201 | | - }{ |
1202 | | - { |
1203 | | - name: "standalone replicaset without ownerReferences should propagate", |
1204 | | - obj: map[string]interface{}{ |
1205 | | - "apiVersion": "apps/v1", |
1206 | | - "kind": "ReplicaSet", |
1207 | | - "metadata": map[string]interface{}{ |
1208 | | - "name": "standalone-rs", |
1209 | | - "namespace": "default", |
1210 | | - }, |
1211 | | - }, |
1212 | | - 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, |
1228 | | - want: true, |
1229 | | - }, |
1230 | | - { |
1231 | | - name: "standalone pod without ownerReferences should propagate", |
1232 | | - obj: map[string]interface{}{ |
1233 | | - "apiVersion": "v1", |
1234 | | - "kind": "Pod", |
1235 | | - "metadata": map[string]interface{}{ |
1236 | | - "name": "standalone-pod", |
1237 | | - "namespace": "default", |
1238 | | - }, |
1239 | | - }, |
1240 | | - ownerReferences: nil, |
1241 | | - enableWorkload: true, |
1242 | | - want: true, |
1243 | | - }, |
1244 | | - { |
1245 | | - name: "replicaset with deployment owner should NOT propagate", |
1246 | | - obj: map[string]interface{}{ |
1247 | | - "apiVersion": "apps/v1", |
1248 | | - "kind": "ReplicaSet", |
1249 | | - "metadata": map[string]interface{}{ |
1250 | | - "name": "test-deploy-abc123", |
1251 | | - "namespace": "default", |
1252 | | - }, |
1253 | | - }, |
1254 | | - ownerReferences: []metav1.OwnerReference{ |
1255 | | - { |
1256 | | - APIVersion: "apps/v1", |
1257 | | - Kind: "Deployment", |
1258 | | - Name: "test-deploy", |
1259 | | - UID: "12345", |
1260 | | - }, |
1261 | | - }, |
1262 | | - enableWorkload: true, |
1263 | | - want: false, |
1264 | | - }, |
1265 | | - { |
1266 | | - name: "pod owned by replicaset - passes ShouldPropagateObj but filtered by resource config", |
1267 | | - obj: map[string]interface{}{ |
1268 | | - "apiVersion": "v1", |
1269 | | - "kind": "Pod", |
1270 | | - "metadata": map[string]interface{}{ |
1271 | | - "name": "test-deploy-abc123-xyz", |
1272 | | - "namespace": "default", |
1273 | | - }, |
1274 | | - }, |
1275 | | - ownerReferences: []metav1.OwnerReference{ |
1276 | | - { |
1277 | | - APIVersion: "apps/v1", |
1278 | | - Kind: "ReplicaSet", |
1279 | | - Name: "test-deploy-abc123", |
1280 | | - UID: "67890", |
1281 | | - }, |
1282 | | - }, |
1283 | | - enableWorkload: false, |
1284 | | - want: true, // ShouldPropagateObj doesn't filter Pods - they're filtered by NewResourceConfig |
1285 | | - }, |
1286 | | - { |
1287 | | - name: "controllerrevision owned by daemonset should NOT propagate", |
1288 | | - obj: map[string]interface{}{ |
1289 | | - "apiVersion": "apps/v1", |
1290 | | - "kind": "ControllerRevision", |
1291 | | - "metadata": map[string]interface{}{ |
1292 | | - "name": "test-ds-7b9848797f", |
1293 | | - "namespace": "default", |
1294 | | - }, |
1295 | | - }, |
1296 | | - ownerReferences: []metav1.OwnerReference{ |
1297 | | - { |
1298 | | - APIVersion: "apps/v1", |
1299 | | - Kind: "DaemonSet", |
1300 | | - Name: "test-ds", |
1301 | | - UID: "abcdef", |
1302 | | - }, |
1303 | | - }, |
1304 | | - enableWorkload: false, |
1305 | | - want: false, |
1306 | | - }, |
1307 | | - { |
1308 | | - name: "controllerrevision owned by statefulset should NOT propagate", |
1309 | | - obj: map[string]interface{}{ |
1310 | | - "apiVersion": "apps/v1", |
1311 | | - "kind": "ControllerRevision", |
1312 | | - "metadata": map[string]interface{}{ |
1313 | | - "name": "test-ss-7878b4b446", |
1314 | | - "namespace": "default", |
1315 | | - }, |
1316 | | - }, |
1317 | | - ownerReferences: []metav1.OwnerReference{ |
1318 | | - { |
1319 | | - APIVersion: "apps/v1", |
1320 | | - Kind: "StatefulSet", |
1321 | | - Name: "test-ss", |
1322 | | - UID: "fedcba", |
1323 | | - }, |
1324 | | - }, |
1325 | | - enableWorkload: false, |
1326 | | - want: false, |
1327 | | - }, |
1328 | | - { |
1329 | | - name: "standalone controllerrevision without owner should propagate", |
1330 | | - obj: map[string]interface{}{ |
1331 | | - "apiVersion": "apps/v1", |
1332 | | - "kind": "ControllerRevision", |
1333 | | - "metadata": map[string]interface{}{ |
1334 | | - "name": "custom-revision", |
1335 | | - "namespace": "default", |
1336 | | - }, |
1337 | | - }, |
1338 | | - 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, |
1354 | | - want: true, |
1355 | | - }, |
1356 | | - { |
1357 | | - name: "PVC should NOT propagate when workload is enabled", |
1358 | | - obj: map[string]interface{}{ |
1359 | | - "apiVersion": "v1", |
1360 | | - "kind": "PersistentVolumeClaim", |
1361 | | - "metadata": map[string]interface{}{ |
1362 | | - "name": "test-pvc", |
1363 | | - "namespace": "default", |
1364 | | - }, |
1365 | | - }, |
1366 | | - ownerReferences: nil, |
1367 | | - enableWorkload: true, |
1368 | | - want: false, |
1369 | | - }, |
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 | | - }, |
1391 | | - } |
1392 | | - |
1393 | | - for _, tt := range tests { |
1394 | | - t.Run(tt.name, func(t *testing.T) { |
1395 | | - uObj := &unstructured.Unstructured{Object: tt.obj} |
1396 | | - if tt.ownerReferences != nil { |
1397 | | - uObj.SetOwnerReferences(tt.ownerReferences) |
1398 | | - } |
1399 | | - |
1400 | | - got, err := ShouldPropagateObj(nil, uObj, tt.enableWorkload) |
1401 | | - if err != nil { |
1402 | | - t.Errorf("ShouldPropagateObj() error = %v", err) |
1403 | | - return |
1404 | | - } |
1405 | | - if got != tt.want { |
1406 | | - t.Errorf("ShouldPropagateObj() = %v, want %v", got, tt.want) |
1407 | | - } |
1408 | | - }) |
1409 | | - } |
1410 | | -} |
0 commit comments