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 <noah@coderanger.net>
  • Loading branch information
coderanger committed Jan 4, 2021
1 parent 84d3698 commit 4eb4cb0
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions pkg/scaling/executor/scale_scaledobjects.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package executor

import (
"context"
"strings"
"time"

"github.com/go-logr/logr"
Expand All @@ -23,18 +22,25 @@ 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
switch {
case 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 {
case 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
default:
var err error
currentScale, err = e.getScaleTargetScale(ctx, scaledObject)
if err != nil {
Expand Down

0 comments on commit 4eb4cb0

Please sign in to comment.