Skip to content

Commit

Permalink
Use the already-normalized GVKR data so less weird string parsing.
Browse files Browse the repository at this point in the history
Also adds support for StatefulSets for symmetry.

Signed-off-by: Noah Kantrowitz <[email protected]>
  • Loading branch information
coderanger committed Jan 4, 2021
1 parent 84d3698 commit 1e48733
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions pkg/scaling/executor/scale_scaledobjects.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,23 @@ func (e *scaleExecutor) RequestScale(ctx context.Context, scaledObject *kedav1al
// to reduce API calls. Everything else uses the scale subresource.
var currentScale *autoscalingv1.Scale
var currentReplicas int32
targetRef := scaledObject.Spec.ScaleTargetRef
// TODO Should this use a more generic runtime.Object approach using scheme.Scheme.New()?
if (targetRef.APIVersion == "" || strings.HasPrefix(targetRef.APIVersion, "apps/")) &&
(targetRef.Kind == "" || targetRef.Kind == "Deployment") {
targetGVKR := scaledObject.Status.ScaleTargetGVKR
if targetGVKR.Group == "apps" && targetGVKR.Kind == "Deployment" {
deployment := &appsv1.Deployment{}
err := e.client.Get(ctx, client.ObjectKey{Name: targetRef.Name, Namespace: scaledObject.Namespace}, deployment)
err := e.client.Get(ctx, client.ObjectKey{Name: targetGVKR.Resource, Namespace: scaledObject.Namespace}, deployment)
if err != nil {
logger.Error(err, "Error getting information on the current Scale (ie. replias count) on the scaleTarget")
return
}
currentReplicas = *deployment.Spec.Replicas
} else if targetGVKR.Group == "apps" && targetGVKR.Kind == "StatefulSet" {
statefulSet := &appsv1.StatefulSet{}
err := e.client.Get(ctx, client.ObjectKey{Name: targetGVKR.Resource, Namespace: scaledObject.Namespace}, statefulSet)
if err != nil {
logger.Error(err, "Error getting information on the current Scale (ie. replias count) on the scaleTarget")
return
}
currentReplicas = *statefulSet.Spec.Replicas
} else {
var err error
currentScale, err = e.getScaleTargetScale(ctx, scaledObject)
Expand Down

0 comments on commit 1e48733

Please sign in to comment.