1515package currentalert
1616
1717import (
18+ "strconv"
19+
1820 "github.com/banzaicloud/kafka-operator/api/v1beta1"
1921 "github.com/banzaicloud/kafka-operator/pkg/k8sutil"
22+ "github.com/banzaicloud/kafka-operator/pkg/resources/kafka"
2023 "github.com/banzaicloud/kafka-operator/pkg/scale"
2124 "github.com/banzaicloud/kafka-operator/pkg/util"
25+ "github.com/go-logr/logr"
2226 "github.com/prometheus/common/model"
2327 corev1 "k8s.io/api/core/v1"
2428 "k8s.io/apimachinery/pkg/api/resource"
@@ -93,22 +97,26 @@ func (e *examiner) processAlert(ds disableScaling) (bool, error) {
9397 }
9498 case "downScale" :
9599 if ds .Down {
96- e .Log .Info ("downscaling is skipped due to downscale limit" )
100+ e .Log .Info ("downscale is skipped due to downscale limit" )
97101 return true , nil
98102 }
99- err := downScale (e .Alert .Labels , e .Client )
103+ err := downScale (e .Log , e . Alert .Labels , e .Client )
100104 if err != nil {
101105 return false , err
102106 }
107+
108+ return true , nil
103109 case "upScale" :
104110 if ds .Up {
105- e .Log .Info ("upscaling is skipped due to upscale limit" )
111+ e .Log .Info ("upscale is skipped due to upscale limit" )
106112 return true , nil
107113 }
108- err := upScale (e .Alert .Labels , e .Alert .Annotations , e .Client )
114+ err := upScale (e .Log , e . Alert .Labels , e .Alert .Annotations , e .Client )
109115 if err != nil {
110116 return false , err
111117 }
118+
119+ return true , nil
112120 }
113121 return false , nil
114122}
@@ -118,13 +126,25 @@ func addPVC(labels model.LabelSet, annotations model.LabelSet, client client.Cli
118126 return nil
119127}
120128
121- func downScale (labels model.LabelSet , client client.Client ) error {
129+ func downScale (log logr. Logger , labels model.LabelSet , client client.Client ) error {
122130
123131 cr , err := k8sutil .GetCr (string (labels ["kafka_cr" ]), string (labels ["namespace" ]), client )
124132 if err != nil {
125133 return err
126134 }
127135
136+ if ids := kafka .GetBrokersWithPendingOrRunningCCTask (cr ); len (ids ) > 0 {
137+ var keyVals []interface {}
138+ for _ , id := range ids {
139+ brokerId := strconv .Itoa (int (id ))
140+ keyVals = append (keyVals , brokerId , cr .Status .BrokersState [brokerId ].GracefulActionState .CruiseControlState )
141+ }
142+
143+ log .Info ("downscale is skipped as there are brokers which have tasks pending or running in CC" , keyVals )
144+
145+ return nil
146+ }
147+
128148 brokerId , err := scale .GetBrokerIDWithLeastPartition (string (labels ["namespace" ]), cr .Spec .CruiseControlConfig .CruiseControlEndpoint , cr .Name )
129149 if err != nil {
130150 return err
@@ -136,13 +156,25 @@ func downScale(labels model.LabelSet, client client.Client) error {
136156 return nil
137157}
138158
139- func upScale (labels model.LabelSet , annotations model.LabelSet , client client.Client ) error {
159+ func upScale (log logr. Logger , labels model.LabelSet , annotations model.LabelSet , client client.Client ) error {
140160
141161 cr , err := k8sutil .GetCr (string (labels ["kafka_cr" ]), string (labels ["namespace" ]), client )
142162 if err != nil {
143163 return err
144164 }
145165
166+ if ids := kafka .GetBrokersWithPendingOrRunningCCTask (cr ); len (ids ) > 0 {
167+ var keyVals []interface {}
168+ for _ , id := range ids {
169+ brokerId := strconv .Itoa (int (id ))
170+ keyVals = append (keyVals , brokerId , cr .Status .BrokersState [brokerId ].GracefulActionState .CruiseControlState )
171+ }
172+
173+ log .Info ("upscale is skipped as there are brokers which have tasks pending or running in CC" , keyVals )
174+
175+ return nil
176+ }
177+
146178 biggestId := int32 (0 )
147179 for _ , broker := range cr .Spec .Brokers {
148180 if broker .Id > biggestId {
@@ -160,6 +192,10 @@ func upScale(labels model.LabelSet, annotations model.LabelSet, client client.Cl
160192 broker .Id = biggestId + 1
161193
162194 } else {
195+ var storageClassName * string
196+ if annotations ["storageClass" ] != "" {
197+ storageClassName = util .StringPointer (string (annotations ["storageClass" ]))
198+ }
163199
164200 broker = v1beta1.Broker {
165201 Id : biggestId + 1 ,
@@ -172,7 +208,7 @@ func upScale(labels model.LabelSet, annotations model.LabelSet, client client.Cl
172208 AccessModes : []corev1.PersistentVolumeAccessMode {
173209 corev1 .ReadWriteOnce ,
174210 },
175- StorageClassName : util . StringPointer ( string ( annotations [ "storageClass" ])) ,
211+ StorageClassName : storageClassName ,
176212 Resources : corev1.ResourceRequirements {
177213 Requests : corev1.ResourceList {
178214 "storage" : resource .MustParse (string (annotations ["diskSize" ])),
0 commit comments