@@ -843,8 +843,101 @@ var _ = Describe("ScaledObjectController", func() {
843
843
}, 1 * time .Minute ).Should (Equal (2 ))
844
844
})
845
845
846
+ // Fix issue 4253
847
+ It ("scaledobject paused condition status changes to true on annotation" , func () {
848
+ // Create the scaling target.
849
+ deploymentName := "toggled-to-paused-annotation-name"
850
+ soName := "so-" + deploymentName
851
+ err := k8sClient .Create (context .Background (), generateDeployment (deploymentName ))
852
+ Expect (err ).ToNot (HaveOccurred ())
853
+
854
+ // Create the ScaledObject without specifying name.
855
+ so := & kedav1alpha1.ScaledObject {
856
+ ObjectMeta : metav1.ObjectMeta {
857
+ Name : soName ,
858
+ Namespace : "default" ,
859
+ },
860
+ Spec : kedav1alpha1.ScaledObjectSpec {
861
+ ScaleTargetRef : & kedav1alpha1.ScaleTarget {
862
+ Name : deploymentName ,
863
+ },
864
+ Advanced : & kedav1alpha1.AdvancedConfig {
865
+ HorizontalPodAutoscalerConfig : & kedav1alpha1.HorizontalPodAutoscalerConfig {},
866
+ },
867
+ Triggers : []kedav1alpha1.ScaleTriggers {
868
+ {
869
+ Type : "cron" ,
870
+ Metadata : map [string ]string {
871
+ "timezone" : "UTC" ,
872
+ "start" : "0 * * * *" ,
873
+ "end" : "1 * * * *" ,
874
+ "desiredReplicas" : "1" ,
875
+ },
876
+ },
877
+ },
878
+ },
879
+ }
880
+ pollingInterval := int32 (5 )
881
+ so .Spec .PollingInterval = & pollingInterval
882
+ err = k8sClient .Create (context .Background (), so )
883
+ Expect (err ).ToNot (HaveOccurred ())
884
+
885
+ // And validate that hpa is created.
886
+ hpa := & autoscalingv2.HorizontalPodAutoscaler {}
887
+ Eventually (func () error {
888
+ return k8sClient .Get (context .Background (), types.NamespacedName {Name : fmt .Sprintf ("keda-hpa-%s" , soName ), Namespace : "default" }, hpa )
889
+ }).ShouldNot (HaveOccurred ())
890
+
891
+ // wait so's ready condition Ready
892
+ Eventually (func () metav1.ConditionStatus {
893
+ err := k8sClient .Get (context .Background (), types.NamespacedName {Name : soName , Namespace : "default" }, so )
894
+ if err != nil {
895
+ return metav1 .ConditionUnknown
896
+ }
897
+ return so .Status .Conditions .GetReadyCondition ().Status
898
+ }).Should (Equal (metav1 .ConditionTrue ))
899
+
900
+ Eventually (func () metav1.ConditionStatus {
901
+ err := k8sClient .Get (context .Background (), types.NamespacedName {Name : soName , Namespace : "default" }, so )
902
+ if err != nil {
903
+ return metav1 .ConditionTrue
904
+ }
905
+ return so .Status .Conditions .GetPausedCondition ().Status
906
+ }, 5 * time .Second ).Should (Or (Equal (metav1 .ConditionFalse ), Equal (metav1 .ConditionUnknown )))
907
+
908
+ // set annotation
909
+ Eventually (func () error {
910
+ err = k8sClient .Get (context .Background (), types.NamespacedName {Name : soName , Namespace : "default" }, so )
911
+ Expect (err ).ToNot (HaveOccurred ())
912
+ annotations := make (map [string ]string )
913
+ annotations [kedacontrollerutil .PausedReplicasAnnotation ] = "1"
914
+ so .SetAnnotations (annotations )
915
+ pollingInterval := int32 (6 )
916
+ so .Spec .PollingInterval = & pollingInterval
917
+ return k8sClient .Update (context .Background (), so )
918
+ }).WithTimeout (1 * time .Minute ).WithPolling (10 * time .Second ).ShouldNot (HaveOccurred ())
919
+ testLogger .Info ("annotation is set" )
920
+
921
+ // validate annotation is set correctly
922
+ Eventually (func () bool {
923
+ err = k8sClient .Get (context .Background (), types.NamespacedName {Name : soName , Namespace : "default" }, so )
924
+ Expect (err ).ToNot (HaveOccurred ())
925
+ _ , paused := so .GetAnnotations ()[kedacontrollerutil .PausedReplicasAnnotation ]
926
+ return paused
927
+ }).WithTimeout (1 * time .Minute ).WithPolling (2 * time .Second ).Should (BeTrue ())
928
+
929
+ Eventually (func () metav1.ConditionStatus {
930
+ err := k8sClient .Get (context .Background (), types.NamespacedName {Name : soName , Namespace : "default" }, so )
931
+ if err != nil {
932
+ return metav1 .ConditionUnknown
933
+ }
934
+ return so .Status .Conditions .GetPausedCondition ().Status
935
+ }).WithTimeout (2 * time .Minute ).WithPolling (10 * time .Second ).Should (Equal (metav1 .ConditionTrue ))
936
+ })
937
+
846
938
// Fix issue 4253
847
939
It ("deletes hpa when scaledobject has pause annotation" , func () {
940
+ pausedReplicasCountForAnnotation := "1"
848
941
// Create the scaling target.
849
942
deploymentName := "to-be-paused-name"
850
943
soName := "so-" + deploymentName
@@ -857,7 +950,7 @@ var _ = Describe("ScaledObjectController", func() {
857
950
Name : soName ,
858
951
Namespace : "default" ,
859
952
Annotations : map [string ]string {
860
- kedacontrollerutil .PausedReplicasAnnotation : "0" ,
953
+ kedacontrollerutil .PausedReplicasAnnotation : pausedReplicasCountForAnnotation ,
861
954
},
862
955
},
863
956
Spec : kedav1alpha1.ScaledObjectSpec {
@@ -880,6 +973,8 @@ var _ = Describe("ScaledObjectController", func() {
880
973
},
881
974
},
882
975
}
976
+ pollingInterval := int32 (5 )
977
+ so .Spec .PollingInterval = & pollingInterval
883
978
err = k8sClient .Create (context .Background (), so )
884
979
Expect (err ).ToNot (HaveOccurred ())
885
980
@@ -895,14 +990,27 @@ var _ = Describe("ScaledObjectController", func() {
895
990
// validate annotation is set correctly
896
991
err = k8sClient .Get (context .Background (), types.NamespacedName {Name : soName , Namespace : "default" }, so )
897
992
Expect (err ).ToNot (HaveOccurred ())
898
- _ , paused := so .GetAnnotations ()[kedacontrollerutil .PausedReplicasAnnotation ]
993
+ pausedReplicasCount , paused := so .GetAnnotations ()[kedacontrollerutil .PausedReplicasAnnotation ]
899
994
Expect (paused ).To (Equal (true ))
995
+ Expect (pausedReplicasCount ).To (Equal (pausedReplicasCountForAnnotation ))
900
996
901
- // And validate that hpa is deleted.
902
- hpa := & autoscalingv2.HorizontalPodAutoscaler {}
903
- Eventually (func () error {
904
- return k8sClient .Get (context .Background (), types.NamespacedName {Name : fmt .Sprintf ("keda-hpa-%s" , soName ), Namespace : "default" }, hpa )
905
- }).Should (HaveOccurred ())
997
+ // wait so's ready condition Ready
998
+ Eventually (func () metav1.ConditionStatus {
999
+ err := k8sClient .Get (context .Background (), types.NamespacedName {Name : soName , Namespace : "default" }, so )
1000
+ if err != nil {
1001
+ return metav1 .ConditionUnknown
1002
+ }
1003
+ return so .Status .Conditions .GetReadyCondition ().Status
1004
+ }).Should (Equal (metav1 .ConditionTrue ))
1005
+
1006
+ // wait so's paused condition True
1007
+ Eventually (func () metav1.ConditionStatus {
1008
+ err := k8sClient .Get (context .Background (), types.NamespacedName {Name : soName , Namespace : "default" }, so )
1009
+ if err != nil {
1010
+ return metav1 .ConditionUnknown
1011
+ }
1012
+ return so .Status .Conditions .GetPausedCondition ().Status
1013
+ }).Should (Equal (metav1 .ConditionTrue ))
906
1014
907
1015
// wait so's Paused condition true
908
1016
Eventually (func () metav1.ConditionStatus {
@@ -911,7 +1019,13 @@ var _ = Describe("ScaledObjectController", func() {
911
1019
return metav1 .ConditionUnknown
912
1020
}
913
1021
return so .Status .Conditions .GetPausedCondition ().Status
914
- }, 1 * time .Minute ).Should (Equal (metav1 .ConditionTrue ))
1022
+ }).WithTimeout (1 * time .Minute ).WithPolling (10 * time .Second ).Should (Equal (metav1 .ConditionTrue ))
1023
+
1024
+ // And validate that hpa is deleted.
1025
+ hpa := & autoscalingv2.HorizontalPodAutoscaler {}
1026
+ Eventually (func () error {
1027
+ return k8sClient .Get (context .Background (), types.NamespacedName {Name : fmt .Sprintf ("keda-hpa-%s" , soName ), Namespace : "default" }, hpa )
1028
+ }).Should (HaveOccurred ())
915
1029
})
916
1030
})
917
1031
0 commit comments