Skip to content

Commit

Permalink
check gvkr == nil
Browse files Browse the repository at this point in the history
Signed-off-by: Zbynek Roubalik <zroubalik@gmail.com>
  • Loading branch information
zroubalik committed Jun 14, 2023
1 parent 739b770 commit eaa8350
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions pkg/scaling/resolver/scale_resolvers.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,22 @@ func ResolveScaleTargetPodSpec(ctx context.Context, kubeClient client.Client, sc
case *kedav1alpha1.ScaledObject:
// Try to get a real object instance for better cache usage, but fall back to an Unstructured if needed.
podTemplateSpec := corev1.PodTemplateSpec{}

if obj.Status.ScaleTargetGVKR == nil {
scaledObject := &kedav1alpha1.ScaledObject{}
err := kubeClient.Get(ctx, types.NamespacedName{Name: obj.Name, Namespace: obj.Namespace}, scaledObject)
if err != nil {
log.Error(err, "failed to get ScaledObject", "name", obj.Name, "namespace", obj.Namespace)
return nil, "", err
}
obj = scaledObject
}
if obj.Status.ScaleTargetGVKR == nil {
err := fmt.Errorf("failed to get ScaledObject.Status.ScaleTargetGVKR, probably invalid ScaledObject cache")
log.Error(err, "failed to get ScaledObject.Status.ScaleTargetGVKR, probably invalid ScaledObject cache", "scaledObject.Name", obj.Name, "scaledObject.Namespace", obj.Namespace)
return nil, "", err
}

gvk := obj.Status.ScaleTargetGVKR.GroupVersionKind()
objKey := client.ObjectKey{Namespace: obj.Namespace, Name: obj.Spec.ScaleTargetRef.Name}

Expand Down

0 comments on commit eaa8350

Please sign in to comment.