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 1dde0e9
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 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,17 +22,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 1dde0e9

Please sign in to comment.