@@ -1378,154 +1378,154 @@ var _ = Describe("Deployment controller", func() {
13781378 })
13791379
13801380 When ("cleaning up removed target clusters" , func () {
1381- var (
1382- ctx context.Context
1383- r * Reconciler
1384- c client.WithWatch
1385- d v1beta1.Deployment
1386- dc1 v1beta1.DeploymentCluster
1387- dc2 v1beta1.DeploymentCluster
1388- dc3 v1beta1.DeploymentCluster
1389- )
1381+ var (
1382+ ctx context.Context
1383+ r * Reconciler
1384+ c client.WithWatch
1385+ d v1beta1.Deployment
1386+ dc1 v1beta1.DeploymentCluster
1387+ dc2 v1beta1.DeploymentCluster
1388+ dc3 v1beta1.DeploymentCluster
1389+ )
13901390
1391- BeforeEach (func () {
1392- ctx = context .Background ()
1393-
1394- d = v1beta1.Deployment {
1395- ObjectMeta : metav1.ObjectMeta {
1396- Name : "test-deployment" ,
1397- Namespace : "default" ,
1398- UID : "test-uid-12345" ,
1399- },
1400- Spec : v1beta1.DeploymentSpec {
1401- DeploymentType : v1beta1 .Targeted ,
1402- Applications : []v1beta1.Application {
1403- {
1404- Name : "app1" ,
1405- Version : "1.0.0" ,
1406- Namespace : "default" ,
1407- Targets : []map [string ]string {
1408- {string (v1beta1 .ClusterName ): "cluster-1" },
1409- {string (v1beta1 .ClusterName ): "cluster-2" },
1410- },
1411- },
1412- },
1413- },
1414- }
1391+ BeforeEach (func () {
1392+ ctx = context .Background ()
14151393
1416- dc1 = v1beta1.DeploymentCluster {
1417- ObjectMeta : metav1.ObjectMeta {
1418- Name : "test-deployment-cluster-1" ,
1419- Namespace : "default" ,
1420- Labels : map [string ]string {
1421- string (v1beta1 .BundleName ): "test-deployment" ,
1422- string (v1beta1 .DeploymentID ): "test-uid-12345" ,
1423- },
1424- OwnerReferences : []metav1.OwnerReference {
1425- {APIVersion : "app.edge-orchestrator.intel.com/v1beta1" , Kind : "Deployment" , Name : "test-deployment" , UID : "test-uid-12345" },
1426- },
1427- },
1428- Spec : v1beta1.DeploymentClusterSpec {ClusterID : "cluster-1" },
1429- }
1394+ d = v1beta1.Deployment {
1395+ ObjectMeta : metav1.ObjectMeta {
1396+ Name : "test-deployment" ,
1397+ Namespace : "default" ,
1398+ UID : "test-uid-12345" ,
1399+ },
1400+ Spec : v1beta1.DeploymentSpec {
1401+ DeploymentType : v1beta1 .Targeted ,
1402+ Applications : []v1beta1.Application {
1403+ {
1404+ Name : "app1" ,
1405+ Version : "1.0.0" ,
1406+ Namespace : "default" ,
1407+ Targets : []map [string ]string {
1408+ {string (v1beta1 .ClusterName ): "cluster-1" },
1409+ {string (v1beta1 .ClusterName ): "cluster-2" },
1410+ },
1411+ },
1412+ },
1413+ },
1414+ }
14301415
1431- dc2 = v1beta1.DeploymentCluster {
1432- ObjectMeta : metav1.ObjectMeta {
1433- Name : "test-deployment-cluster-2 " ,
1434- Namespace : "default" ,
1435- Labels : map [string ]string {
1436- string (v1beta1 .BundleName ): "test-deployment" ,
1437- string (v1beta1 .DeploymentID ): "test-uid-12345" ,
1438- },
1439- OwnerReferences : []metav1.OwnerReference {
1440- {APIVersion : "app.edge-orchestrator.intel.com/v1beta1" , Kind : "Deployment" , Name : "test-deployment" , UID : "test-uid-12345" },
1441- },
1442- },
1443- Spec : v1beta1.DeploymentClusterSpec {ClusterID : "cluster-2 " },
1444- }
1416+ dc1 = v1beta1.DeploymentCluster {
1417+ ObjectMeta : metav1.ObjectMeta {
1418+ Name : "test-deployment-cluster-1 " ,
1419+ Namespace : "default" ,
1420+ Labels : map [string ]string {
1421+ string (v1beta1 .BundleName ): "test-deployment" ,
1422+ string (v1beta1 .DeploymentID ): "test-uid-12345" ,
1423+ },
1424+ OwnerReferences : []metav1.OwnerReference {
1425+ {APIVersion : "app.edge-orchestrator.intel.com/v1beta1" , Kind : "Deployment" , Name : "test-deployment" , UID : "test-uid-12345" },
1426+ },
1427+ },
1428+ Spec : v1beta1.DeploymentClusterSpec {ClusterID : "cluster-1 " },
1429+ }
14451430
1446- dc3 = v1beta1.DeploymentCluster {
1447- ObjectMeta : metav1.ObjectMeta {
1448- Name : "test-deployment-cluster-3 " ,
1449- Namespace : "default" ,
1450- Labels : map [string ]string {
1451- string (v1beta1 .BundleName ): "test-deployment" ,
1452- string (v1beta1 .DeploymentID ): "test-uid-12345" ,
1453- },
1454- OwnerReferences : []metav1.OwnerReference {
1455- {APIVersion : "app.edge-orchestrator.intel.com/v1beta1" , Kind : "Deployment" , Name : "test-deployment" , UID : "test-uid-12345" },
1456- },
1457- },
1458- Spec : v1beta1.DeploymentClusterSpec {ClusterID : "cluster-3 " },
1459- }
1431+ dc2 = v1beta1.DeploymentCluster {
1432+ ObjectMeta : metav1.ObjectMeta {
1433+ Name : "test-deployment-cluster-2 " ,
1434+ Namespace : "default" ,
1435+ Labels : map [string ]string {
1436+ string (v1beta1 .BundleName ): "test-deployment" ,
1437+ string (v1beta1 .DeploymentID ): "test-uid-12345" ,
1438+ },
1439+ OwnerReferences : []metav1.OwnerReference {
1440+ {APIVersion : "app.edge-orchestrator.intel.com/v1beta1" , Kind : "Deployment" , Name : "test-deployment" , UID : "test-uid-12345" },
1441+ },
1442+ },
1443+ Spec : v1beta1.DeploymentClusterSpec {ClusterID : "cluster-2 " },
1444+ }
14601445
1461- c = fake .NewClientBuilder ().
1462- WithScheme (scheme .Scheme ).
1463- WithObjects (& d , & dc1 , & dc2 , & dc3 ).
1464- WithStatusSubresource (& v1beta1.Deployment {}).
1465- Build ()
1446+ dc3 = v1beta1.DeploymentCluster {
1447+ ObjectMeta : metav1.ObjectMeta {
1448+ Name : "test-deployment-cluster-3" ,
1449+ Namespace : "default" ,
1450+ Labels : map [string ]string {
1451+ string (v1beta1 .BundleName ): "test-deployment" ,
1452+ string (v1beta1 .DeploymentID ): "test-uid-12345" ,
1453+ },
1454+ OwnerReferences : []metav1.OwnerReference {
1455+ {APIVersion : "app.edge-orchestrator.intel.com/v1beta1" , Kind : "Deployment" , Name : "test-deployment" , UID : "test-uid-12345" },
1456+ },
1457+ },
1458+ Spec : v1beta1.DeploymentClusterSpec {ClusterID : "cluster-3" },
1459+ }
14661460
1467- r = & Reconciler {
1468- Client : c ,
1469- Scheme : scheme .Scheme ,
1470- recorder : record .NewFakeRecorder (1024 ),
1471- }
1472- })
1461+ c = fake .NewClientBuilder ().
1462+ WithScheme (scheme .Scheme ).
1463+ WithObjects (& d , & dc1 , & dc2 , & dc3 ).
1464+ WithStatusSubresource (& v1beta1.Deployment {}).
1465+ Build ()
14731466
1474- Context ("when cluster is removed from targeted deployment" , func () {
1475- It ("should delete the DeploymentCluster for removed cluster" , func () {
1476- err := r .cleanupRemovedTargetClusters (ctx , & d )
1477- Expect (err ).NotTo (HaveOccurred ())
1467+ r = & Reconciler {
1468+ Client : c ,
1469+ Scheme : scheme .Scheme ,
1470+ recorder : record .NewFakeRecorder (1024 ),
1471+ }
1472+ })
14781473
1479- err = r .Get (ctx , types.NamespacedName {Name : dc1 .Name , Namespace : dc1 .Namespace }, & dc1 )
1480- Expect (err ).NotTo (HaveOccurred ())
1474+ Context ("when cluster is removed from targeted deployment" , func () {
1475+ It ("should delete the DeploymentCluster for removed cluster" , func () {
1476+ err := r .cleanupRemovedTargetClusters (ctx , & d )
1477+ Expect (err ).NotTo (HaveOccurred ())
14811478
1482- err = r .Get (ctx , types.NamespacedName {Name : dc2 .Name , Namespace : dc2 .Namespace }, & dc2 )
1483- Expect (err ).NotTo (HaveOccurred ())
1479+ err = r .Get (ctx , types.NamespacedName {Name : dc1 .Name , Namespace : dc1 .Namespace }, & dc1 )
1480+ Expect (err ).NotTo (HaveOccurred ())
14841481
1485- err = r .Get (ctx , types.NamespacedName {Name : dc3 .Name , Namespace : dc3 .Namespace }, & dc3 )
1486- Expect (apierrors .IsNotFound (err )).To (BeTrue ())
1487- })
1488- })
1482+ err = r .Get (ctx , types.NamespacedName {Name : dc2 .Name , Namespace : dc2 .Namespace }, & dc2 )
1483+ Expect (err ).NotTo (HaveOccurred ())
14891484
1490- Context ("when deployment is auto-scaling type" , func () {
1491- It ("should not delete any DeploymentClusters" , func () {
1492- d .Spec .DeploymentType = v1beta1 .AutoScaling
1493- err := c .Update (ctx , & d )
1494- Expect (err ).NotTo (HaveOccurred ())
1485+ err = r .Get (ctx , types.NamespacedName {Name : dc3 .Name , Namespace : dc3 .Namespace }, & dc3 )
1486+ Expect (apierrors .IsNotFound (err )).To (BeTrue ())
1487+ })
1488+ })
14951489
1496- err = r .cleanupRemovedTargetClusters (ctx , & d )
1497- Expect (err ).NotTo (HaveOccurred ())
1490+ Context ("when deployment is auto-scaling type" , func () {
1491+ It ("should not delete any DeploymentClusters" , func () {
1492+ d .Spec .DeploymentType = v1beta1 .AutoScaling
1493+ err := c .Update (ctx , & d )
1494+ Expect (err ).NotTo (HaveOccurred ())
14981495
1499- err = r .Get (ctx , types. NamespacedName { Name : dc1 . Name , Namespace : dc1 . Namespace }, & dc1 )
1500- Expect (err ).NotTo (HaveOccurred ())
1496+ err = r .cleanupRemovedTargetClusters (ctx , & d )
1497+ Expect (err ).NotTo (HaveOccurred ())
15011498
1502- err = r .Get (ctx , types.NamespacedName {Name : dc2 .Name , Namespace : dc2 .Namespace }, & dc2 )
1503- Expect (err ).NotTo (HaveOccurred ())
1499+ err = r .Get (ctx , types.NamespacedName {Name : dc1 .Name , Namespace : dc1 .Namespace }, & dc1 )
1500+ Expect (err ).NotTo (HaveOccurred ())
15041501
1505- err = r .Get (ctx , types.NamespacedName {Name : dc3 .Name , Namespace : dc3 .Namespace }, & dc3 )
1506- Expect (err ).NotTo (HaveOccurred ())
1507- })
1508- })
1502+ err = r .Get (ctx , types.NamespacedName {Name : dc2 .Name , Namespace : dc2 .Namespace }, & dc2 )
1503+ Expect (err ).NotTo (HaveOccurred ())
15091504
1510- Context ("when all clusters are removed from deployment" , func () {
1511- It ("should delete all DeploymentClusters" , func () {
1512- d .Spec .Applications [0 ].Targets = []map [string ]string {}
1513- err := c .Update (ctx , & d )
1514- Expect (err ).NotTo (HaveOccurred ())
1505+ err = r .Get (ctx , types.NamespacedName {Name : dc3 .Name , Namespace : dc3 .Namespace }, & dc3 )
1506+ Expect (err ).NotTo (HaveOccurred ())
1507+ })
1508+ })
15151509
1516- err = r .cleanupRemovedTargetClusters (ctx , & d )
1517- Expect (err ).NotTo (HaveOccurred ())
1510+ Context ("when all clusters are removed from deployment" , func () {
1511+ It ("should delete all DeploymentClusters" , func () {
1512+ d .Spec .Applications [0 ].Targets = []map [string ]string {}
1513+ err := c .Update (ctx , & d )
1514+ Expect (err ).NotTo (HaveOccurred ())
15181515
1519- err = r .Get (ctx , types. NamespacedName { Name : dc1 . Name , Namespace : dc1 . Namespace }, & dc1 )
1520- Expect (apierrors . IsNotFound ( err )). To ( BeTrue ())
1516+ err = r .cleanupRemovedTargetClusters (ctx , & d )
1517+ Expect (err ). NotTo ( HaveOccurred ())
15211518
1522- err = r .Get (ctx , types.NamespacedName {Name : dc2 .Name , Namespace : dc2 .Namespace }, & dc2 )
1523- Expect (apierrors .IsNotFound (err )).To (BeTrue ())
1519+ err = r .Get (ctx , types.NamespacedName {Name : dc1 .Name , Namespace : dc1 .Namespace }, & dc1 )
1520+ Expect (apierrors .IsNotFound (err )).To (BeTrue ())
15241521
1525- err = r .Get (ctx , types.NamespacedName {Name : dc3 .Name , Namespace : dc3 .Namespace }, & dc3 )
1526- Expect (apierrors .IsNotFound (err )).To (BeTrue ())
1527- })
1528- })
1522+ err = r .Get (ctx , types.NamespacedName {Name : dc2 .Name , Namespace : dc2 .Namespace }, & dc2 )
1523+ Expect (apierrors .IsNotFound (err )).To (BeTrue ())
1524+
1525+ err = r .Get (ctx , types.NamespacedName {Name : dc3 .Name , Namespace : dc3 .Namespace }, & dc3 )
1526+ Expect (apierrors .IsNotFound (err )).To (BeTrue ())
1527+ })
1528+ })
15291529 })
15301530
15311531})
0 commit comments