@@ -7,6 +7,9 @@ package controller
77import (
88 "context"
99 "errors"
10+ "fmt"
11+ "github.com/gardener/machine-controller-manager/pkg/util/annotations"
12+ "github.com/gardener/machine-controller-manager/pkg/util/provider/machineutils"
1013 "time"
1114
1215 machinev1 "github.com/gardener/machine-controller-manager/pkg/apis/machine/v1alpha1"
@@ -1400,8 +1403,9 @@ var _ = Describe("machineDeployment", func() {
14001403 Labels : map [string ]string {
14011404 "test-label" : "test-label" ,
14021405 },
1403- UID : "1234567" ,
1404- Generation : 5 ,
1406+ Annotations : make (map [string ]string ),
1407+ UID : "1234567" ,
1408+ Generation : 5 ,
14051409 },
14061410 TypeMeta : metav1.TypeMeta {
14071411 Kind : "MachineDeployment" ,
@@ -1506,7 +1510,8 @@ var _ = Describe("machineDeployment", func() {
15061510 "test-label" : "test-label" ,
15071511 machinev1 .NodeLabelKey : "Node1-test" ,
15081512 },
1509- UID : "1234567" ,
1513+ Annotations : map [string ]string {},
1514+ UID : "1234567" ,
15101515 OwnerReferences : []metav1.OwnerReference {
15111516 {
15121517 Kind : "MachineSet" ,
@@ -1552,7 +1557,7 @@ var _ = Describe("machineDeployment", func() {
15521557
15531558 DescribeTable ("This should" ,
15541559 func (preset func (testMachineDeployment * machinev1.MachineDeployment , testMachineSet * machinev1.MachineSet ),
1555- postCheck func (testMachineDeployment * machinev1.MachineDeployment , testMachineSet []machinev1.MachineSet , testNode * corev1.Node ) error ) {
1560+ postCheck func (testMachineDeployment * machinev1.MachineDeployment , testMachineSet []machinev1.MachineSet , testMachines []machinev1. Machine , testNode * corev1.Node ) error ) {
15561561
15571562 stop := make (chan struct {})
15581563 preset (testMachineDeployment , testMachineSet )
@@ -1575,13 +1580,15 @@ var _ = Describe("machineDeployment", func() {
15751580 waitForCacheSync (stop , c )
15761581 actualMachineDeployment , _ := c .controlMachineClient .MachineDeployments (testNamespace ).Get (context .Background (), testMachineDeployment .Name , metav1.GetOptions {})
15771582 actualMachineSets , _ := c .controlMachineClient .MachineSets (testNamespace ).List (context .Background (), metav1.ListOptions {})
1583+ waitForCacheSync (stop , c )
1584+ actualMachines , _ := c .controlMachineClient .Machines (testNamespace ).List (context .Background (), metav1.ListOptions {})
15781585 testNode , _ := c .targetCoreClient .CoreV1 ().Nodes ().Get (context .Background (), testNode .Name , metav1.GetOptions {})
15791586
1580- Expect (postCheck (actualMachineDeployment , actualMachineSets .Items , testNode )).To (BeNil ())
1587+ Expect (postCheck (actualMachineDeployment , actualMachineSets .Items , actualMachines . Items , testNode )).To (BeNil ())
15811588 },
15821589 Entry ("reconcile the machineDeployment and return nil" ,
15831590 func (_ * machinev1.MachineDeployment , _ * machinev1.MachineSet ) {},
1584- func (_ * machinev1.MachineDeployment , _ []machinev1.MachineSet , _ * corev1.Node ) error {
1591+ func (_ * machinev1.MachineDeployment , _ []machinev1.MachineSet , _ []machinev1. Machine , _ * corev1.Node ) error {
15851592 return nil
15861593 },
15871594 ),
@@ -1592,7 +1599,7 @@ var _ = Describe("machineDeployment", func() {
15921599 testMachineSet .Spec = machinev1.MachineSetSpec {}
15931600 testMachineSet .Status = machinev1.MachineSetStatus {}
15941601 },
1595- func (_ * machinev1.MachineDeployment , testMachineSets []machinev1.MachineSet , _ * corev1.Node ) error {
1602+ func (_ * machinev1.MachineDeployment , testMachineSets []machinev1.MachineSet , _ []machinev1. Machine , _ * corev1.Node ) error {
15961603 if len (testMachineSets ) != 1 {
15971604 return errors .New ("it should have created one machine set" )
15981605 }
@@ -1603,18 +1610,19 @@ var _ = Describe("machineDeployment", func() {
16031610 func (testMachineDeployment * machinev1.MachineDeployment , _ * machinev1.MachineSet ) {
16041611 testMachineDeployment .Spec .Selector = & metav1.LabelSelector {}
16051612 },
1606- func (_ * machinev1.MachineDeployment , testMachineSets []machinev1.MachineSet , _ * corev1.Node ) error {
1613+ func (_ * machinev1.MachineDeployment , testMachineSets []machinev1.MachineSet , _ []machinev1. Machine , _ * corev1.Node ) error {
16071614 if len (testMachineSets ) > 1 {
16081615 return errors .New ("it should not have created one machine set" )
16091616 }
1617+
16101618 return nil
16111619 },
16121620 ),
16131621 Entry ("should remove the finalizer from deployment when deleted and no machineSets are available." ,
16141622 func (testMachineDeployment * machinev1.MachineDeployment , _ * machinev1.MachineSet ) {
16151623 testMachineDeployment .DeletionTimestamp = & metav1.Time {Time : time .Now ()}
16161624 },
1617- func (testMachineDeployment * machinev1.MachineDeployment , _ []machinev1.MachineSet , _ * corev1.Node ) error {
1625+ func (testMachineDeployment * machinev1.MachineDeployment , _ []machinev1.MachineSet , _ []machinev1. Machine , _ * corev1.Node ) error {
16181626 if len (testMachineDeployment .Finalizers ) > 0 {
16191627 return errors .New ("it should have removed the finalizers" )
16201628 }
@@ -1631,7 +1639,7 @@ var _ = Describe("machineDeployment", func() {
16311639 testMachineSet .Spec = machinev1.MachineSetSpec {}
16321640 testMachineSet .Status = machinev1.MachineSetStatus {}
16331641 },
1634- func (_ * machinev1.MachineDeployment , testMachineSets []machinev1.MachineSet , _ * corev1.Node ) error {
1642+ func (_ * machinev1.MachineDeployment , testMachineSets []machinev1.MachineSet , _ []machinev1. Machine , _ * corev1.Node ) error {
16351643 if len (testMachineSets ) != 0 {
16361644 return errors .New ("it shouldn't have created machine set" )
16371645 }
@@ -1648,7 +1656,7 @@ var _ = Describe("machineDeployment", func() {
16481656 testMachineSet .Spec = machinev1.MachineSetSpec {}
16491657 testMachineSet .Status = machinev1.MachineSetStatus {}
16501658 },
1651- func (_ * machinev1.MachineDeployment , testMachineSets []machinev1.MachineSet , _ * corev1.Node ) error {
1659+ func (_ * machinev1.MachineDeployment , testMachineSets []machinev1.MachineSet , _ []machinev1. Machine , _ * corev1.Node ) error {
16521660 if len (testMachineSets ) < 1 {
16531661 return errors .New ("it should have created one machine set" )
16541662 }
@@ -1662,7 +1670,7 @@ var _ = Describe("machineDeployment", func() {
16621670 }
16631671 testMachineDeployment .Spec .Template .Spec .Class .Name = "MachineClass-test-new"
16641672 },
1665- func (_ * machinev1.MachineDeployment , testMachineSets []machinev1.MachineSet , _ * corev1.Node ) error {
1673+ func (_ * machinev1.MachineDeployment , testMachineSets []machinev1.MachineSet , _ []machinev1. Machine , _ * corev1.Node ) error {
16661674 // Old machine set should exist and should be scaled-down to zero.
16671675 if len (testMachineSets ) == 0 || testMachineSets [0 ].Spec .Replicas != 0 {
16681676 return errors .New ("it should have scaled-down old machineSet to zero" )
@@ -1691,7 +1699,7 @@ var _ = Describe("machineDeployment", func() {
16911699 }
16921700 testMachine = & machinev1.Machine {}
16931701 },
1694- func (testMachineDeployment * machinev1.MachineDeployment , testMachineSets []machinev1.MachineSet , _ * corev1.Node ) error {
1702+ func (testMachineDeployment * machinev1.MachineDeployment , testMachineSets []machinev1.MachineSet , _ []machinev1. Machine , _ * corev1.Node ) error {
16951703 if len (testMachineSets ) != 2 || testMachineSets [0 ].Spec .Replicas != testMachineDeployment .Spec .Replicas {
16961704 return errors .New ("it should have fully scaled-up the new machineSet" )
16971705 }
@@ -1704,7 +1712,7 @@ var _ = Describe("machineDeployment", func() {
17041712 // This should trigger rolling-update.
17051713 testMachineDeployment .Spec .Template .Spec .Class .Name = "MachineClass-test-new"
17061714 },
1707- func (_ * machinev1.MachineDeployment , testMachineSets []machinev1.MachineSet , _ * corev1.Node ) error {
1715+ func (_ * machinev1.MachineDeployment , testMachineSets []machinev1.MachineSet , _ []machinev1. Machine , _ * corev1.Node ) error {
17081716 if len (testMachineSets ) != 2 {
17091717 return errors .New ("it should have created a new machine set" )
17101718 }
@@ -1716,7 +1724,7 @@ var _ = Describe("machineDeployment", func() {
17161724 // This should trigger rolling-update.
17171725 testMachineDeployment .Spec .Template .Spec .Class .Name = "MachineClass-test-new"
17181726 },
1719- func (testMachineDeployment * machinev1.MachineDeployment , testMachineSets []machinev1.MachineSet , _ * corev1.Node ) error {
1727+ func (testMachineDeployment * machinev1.MachineDeployment , testMachineSets []machinev1.MachineSet , _ []machinev1. Machine , _ * corev1.Node ) error {
17201728 /*TODO: when we create a new RS then we assign it the replica count and
17211729 then we again see if the replica count can be increased in the same reconciliation loop
17221730 So in our case we first assign it replica count of 1(note a new machine is not created)
@@ -1748,7 +1756,7 @@ var _ = Describe("machineDeployment", func() {
17481756 }
17491757
17501758 },
1751- func (testMachineDeployment * machinev1.MachineDeployment , _ []machinev1.MachineSet , _ * corev1.Node ) error {
1759+ func (testMachineDeployment * machinev1.MachineDeployment , _ []machinev1.MachineSet , _ []machinev1. Machine , _ * corev1.Node ) error {
17521760 // RollbackTo should be removed after rollback.
17531761 if testMachineDeployment .Spec .RollbackTo != nil {
17541762 return errors .New ("RollbackTo field should have been removed from machine-deployment" )
@@ -1768,7 +1776,7 @@ var _ = Describe("machineDeployment", func() {
17681776 testMachineDeployment .Spec .Template .Spec .Class .Name = "MachineClass-test-new"
17691777 testMachineDeployment .Spec .Paused = true
17701778 },
1771- func (_ * machinev1.MachineDeployment , testMachineSets []machinev1.MachineSet , _ * corev1.Node ) error {
1779+ func (_ * machinev1.MachineDeployment , testMachineSets []machinev1.MachineSet , _ []machinev1. Machine , _ * corev1.Node ) error {
17721780
17731781 if len (testMachineSets ) != 1 {
17741782 return errors .New ("there should be only one old machine-set" )
@@ -1781,6 +1789,17 @@ var _ = Describe("machineDeployment", func() {
17811789 return nil
17821790 },
17831791 ),
1792+ Entry ("should set MachinePriority=1 for the machines named in TriggerDeletionByMCM annotation in the MachineDeployment" ,
1793+ func (testMachineDeployment * machinev1.MachineDeployment , _ * machinev1.MachineSet ) {
1794+ testMachineDeployment .Annotations [machineutils .TriggerDeletionByMCM ] = annotations .CreateMachinesTriggeredForDeletionAnnotValue ([]string {testMachine .Name })
1795+ },
1796+ func (_ * machinev1.MachineDeployment , _ []machinev1.MachineSet , machines []machinev1.Machine , _ * corev1.Node ) error {
1797+ if machines [0 ].Annotations [machineutils .MachinePriority ] != "1" {
1798+ return fmt .Errorf ("testMachine should have its %q annotation set to 1" , machineutils .MachinePriority )
1799+ }
1800+ return nil
1801+ },
1802+ ),
17841803 )
17851804 })
17861805
0 commit comments