@@ -23,6 +23,7 @@ import (
23
23
"fmt"
24
24
"testing"
25
25
26
+ "github.com/aws/aws-sdk-go/aws"
26
27
"github.com/go-logr/logr"
27
28
"github.com/golang/mock/gomock"
28
29
. "github.com/onsi/gomega"
@@ -531,7 +532,7 @@ func setupCluster(clusterName string) (*scope.ClusterScope, error) {
531
532
})
532
533
}
533
534
534
- func TestASGNeedsUpdates (t * testing.T ) {
535
+ func TestDiffASG (t * testing.T ) {
535
536
type args struct {
536
537
machinePoolScope * scope.MachinePoolScope
537
538
existingASG * expinfrav1.AutoScalingGroup
@@ -695,6 +696,106 @@ func TestASGNeedsUpdates(t *testing.T) {
695
696
},
696
697
want : true ,
697
698
},
699
+ {
700
+ name : "MixedInstancesPolicy.InstancesDistribution != asg.MixedInstancesPolicy.InstancesDistribution" ,
701
+ args : args {
702
+ machinePoolScope : & scope.MachinePoolScope {
703
+ MachinePool : & expclusterv1.MachinePool {
704
+ Spec : expclusterv1.MachinePoolSpec {
705
+ Replicas : pointer .Int32 (1 ),
706
+ },
707
+ },
708
+ AWSMachinePool : & expinfrav1.AWSMachinePool {
709
+ Spec : expinfrav1.AWSMachinePoolSpec {
710
+ MaxSize : 2 ,
711
+ MinSize : 0 ,
712
+ CapacityRebalance : true ,
713
+ MixedInstancesPolicy : & expinfrav1.MixedInstancesPolicy {
714
+ InstancesDistribution : & expinfrav1.InstancesDistribution {
715
+ OnDemandAllocationStrategy : expinfrav1 .OnDemandAllocationStrategyPrioritized ,
716
+ SpotAllocationStrategy : expinfrav1 .SpotAllocationStrategyCapacityOptimized ,
717
+ OnDemandBaseCapacity : aws .Int64 (0 ),
718
+ OnDemandPercentageAboveBaseCapacity : aws .Int64 (100 ),
719
+ },
720
+ Overrides : []expinfrav1.Overrides {
721
+ {
722
+ InstanceType : "m6a.32xlarge" ,
723
+ },
724
+ },
725
+ },
726
+ },
727
+ },
728
+ Logger : * logger .NewLogger (logr .Discard ()),
729
+ },
730
+ existingASG : & expinfrav1.AutoScalingGroup {
731
+ DesiredCapacity : pointer .Int32 (1 ),
732
+ MaxSize : 2 ,
733
+ MinSize : 0 ,
734
+ CapacityRebalance : true ,
735
+ MixedInstancesPolicy : & expinfrav1.MixedInstancesPolicy {
736
+ InstancesDistribution : & expinfrav1.InstancesDistribution {
737
+ OnDemandAllocationStrategy : expinfrav1 .OnDemandAllocationStrategyPrioritized ,
738
+ SpotAllocationStrategy : expinfrav1 .SpotAllocationStrategyLowestPrice ,
739
+ OnDemandBaseCapacity : aws .Int64 (0 ),
740
+ OnDemandPercentageAboveBaseCapacity : aws .Int64 (100 ),
741
+ },
742
+ Overrides : []expinfrav1.Overrides {
743
+ {
744
+ InstanceType : "m6a.32xlarge" ,
745
+ },
746
+ },
747
+ },
748
+ },
749
+ },
750
+ want : true ,
751
+ },
752
+ {
753
+ name : "MixedInstancesPolicy.InstancesDistribution unset" ,
754
+ args : args {
755
+ machinePoolScope : & scope.MachinePoolScope {
756
+ MachinePool : & expclusterv1.MachinePool {
757
+ Spec : expclusterv1.MachinePoolSpec {
758
+ Replicas : pointer .Int32 (1 ),
759
+ },
760
+ },
761
+ AWSMachinePool : & expinfrav1.AWSMachinePool {
762
+ Spec : expinfrav1.AWSMachinePoolSpec {
763
+ MaxSize : 2 ,
764
+ MinSize : 0 ,
765
+ CapacityRebalance : true ,
766
+ MixedInstancesPolicy : & expinfrav1.MixedInstancesPolicy {
767
+ Overrides : []expinfrav1.Overrides {
768
+ {
769
+ InstanceType : "m6a.32xlarge" ,
770
+ },
771
+ },
772
+ },
773
+ },
774
+ },
775
+ Logger : * logger .NewLogger (logr .Discard ()),
776
+ },
777
+ existingASG : & expinfrav1.AutoScalingGroup {
778
+ DesiredCapacity : pointer .Int32 (1 ),
779
+ MaxSize : 2 ,
780
+ MinSize : 0 ,
781
+ CapacityRebalance : true ,
782
+ MixedInstancesPolicy : & expinfrav1.MixedInstancesPolicy {
783
+ InstancesDistribution : & expinfrav1.InstancesDistribution {
784
+ OnDemandAllocationStrategy : expinfrav1 .OnDemandAllocationStrategyPrioritized ,
785
+ SpotAllocationStrategy : expinfrav1 .SpotAllocationStrategyLowestPrice ,
786
+ OnDemandBaseCapacity : aws .Int64 (0 ),
787
+ OnDemandPercentageAboveBaseCapacity : aws .Int64 (100 ),
788
+ },
789
+ Overrides : []expinfrav1.Overrides {
790
+ {
791
+ InstanceType : "m6a.32xlarge" ,
792
+ },
793
+ },
794
+ },
795
+ },
796
+ },
797
+ want : false ,
798
+ },
698
799
{
699
800
name : "SuspendProcesses != asg.SuspendProcesses" ,
700
801
args : args {
@@ -821,7 +922,7 @@ func TestASGNeedsUpdates(t *testing.T) {
821
922
for _ , tt := range tests {
822
923
t .Run (tt .name , func (t * testing.T ) {
823
924
g := NewWithT (t )
824
- g .Expect (asgNeedsUpdates (tt .args .machinePoolScope , tt .args .existingASG )).To (Equal (tt .want ))
925
+ g .Expect (diffASG (tt .args .machinePoolScope , tt .args .existingASG ) != "" ).To (Equal (tt .want ))
825
926
})
826
927
}
827
928
}
0 commit comments