@@ -104,7 +104,7 @@ func main() {
104
104
autoScalingClient = autoscaling .NewFromConfig (cfg )
105
105
eksClient = eks .NewFromConfig (cfg )
106
106
}
107
- case * bb_autoscaler.NodeGroupConfiguration_KubernetesDeployment :
107
+ case * bb_autoscaler.NodeGroupConfiguration_KubernetesDeployment , * bb_autoscaler. NodeGroupConfiguration_KubernetesStatefulSet :
108
108
if kubernetesClientset == nil {
109
109
config , err := rest .InClusterConfig ()
110
110
if err != nil {
@@ -116,7 +116,7 @@ func main() {
116
116
}
117
117
}
118
118
default :
119
- return status .Error (codes .InvalidArgument , "No ASG, EKS managed node group, or Kubernetes deployment name specified" )
119
+ return status .Error (codes .InvalidArgument , "No ASG, EKS managed node group, Kubernetes deployment, or Kubernetes stateful set specified" )
120
120
}
121
121
}
122
122
@@ -174,6 +174,9 @@ func main() {
174
174
case * bb_autoscaler.NodeGroupConfiguration_KubernetesDeployment :
175
175
minSize = kind .KubernetesDeployment .MinimumReplicas
176
176
maxSize = kind .KubernetesDeployment .MaximumReplicas
177
+ case * bb_autoscaler.NodeGroupConfiguration_KubernetesStatefulSet :
178
+ minSize = kind .KubernetesStatefulSet .MinimumReplicas
179
+ maxSize = kind .KubernetesStatefulSet .MaximumReplicas
177
180
default :
178
181
panic ("Incomplete switch on node group kind" )
179
182
}
@@ -250,6 +253,38 @@ func main() {
250
253
}); err != nil {
251
254
return util .StatusWrapf (err , "Failed to change number of replicas of Kubernetes deployment %#v in namespace %#v" , name , namespace )
252
255
}
256
+ case * bb_autoscaler.NodeGroupConfiguration_KubernetesStatefulSet :
257
+ namespace := kind .KubernetesStatefulSet .Namespace
258
+ name := kind .KubernetesStatefulSet .Name
259
+ metaKind := "StatefulSet"
260
+ metaAPIVersion := "apps/v1"
261
+ if _ , err := kubernetesClientset .
262
+ AppsV1 ().
263
+ StatefulSets (namespace ).
264
+ Apply (
265
+ ctx ,
266
+ & appsv1_apply.StatefulSetApplyConfiguration {
267
+ TypeMetaApplyConfiguration : metav1_apply.TypeMetaApplyConfiguration {
268
+ Kind : & metaKind ,
269
+ APIVersion : & metaAPIVersion ,
270
+ },
271
+ ObjectMetaApplyConfiguration : & metav1_apply.ObjectMetaApplyConfiguration {
272
+ Name : & name ,
273
+ Namespace : & namespace ,
274
+ Annotations : map [string ]string {
275
+ "kubernetes.io/change-cause" : "replicas updated by bb_autoscaler" ,
276
+ },
277
+ },
278
+ Spec : & appsv1_apply.StatefulSetSpecApplyConfiguration {
279
+ Replicas : & newDesiredCapacity ,
280
+ },
281
+ },
282
+ metav1.ApplyOptions {
283
+ FieldManager : "bb_autoscaler" ,
284
+ Force : true ,
285
+ }); err != nil {
286
+ return util .StatusWrapf (err , "Failed to change number of replicas of Kubernetes stateful set %#v in namespace %#v" , name , namespace )
287
+ }
253
288
default :
254
289
panic ("Incomplete switch on node group kind" )
255
290
}
@@ -261,3 +296,16 @@ func main() {
261
296
return nil
262
297
})
263
298
}
299
+
300
+ func createKubernetesClient () (* kubernetes.Clientset , error ) {
301
+ config , err := rest .InClusterConfig ()
302
+ if err != nil {
303
+ return nil , util .StatusWrap (err , "Failed to create Kubernetes client configuration" )
304
+ }
305
+ kubernetesClientset , err := kubernetes .NewForConfig (config )
306
+ if err != nil {
307
+ return nil , util .StatusWrap (err , "Failed to create Kubernetes client" )
308
+ }
309
+
310
+ return kubernetesClientset , nil
311
+ }
0 commit comments