Skip to content

Commit b8d93b2

Browse files
authored
refactor: replace autoscalingv1.CrossVersionObjectReference with autoscalingv2 (#871)
Signed-off-by: Vivek Karunai Kiri Ragavan <vkarunai@redhat.com>
1 parent 1426fdd commit b8d93b2

13 files changed

Lines changed: 43 additions & 46 deletions

File tree

api/v1alpha1/variantautoscaling_types.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package v1alpha1
22

33
import (
4-
autoscalingv1 "k8s.io/api/autoscaling/v1"
4+
autoscalingv2 "k8s.io/api/autoscaling/v2"
55
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
66
)
77

@@ -21,7 +21,7 @@ type VariantAutoscalingSpec struct {
2121
// ScaleTargetRef references the scalable resource to manage.
2222
// This follows the same pattern as HorizontalPodAutoscaler.
2323
// +kubebuilder:validation:Required
24-
ScaleTargetRef autoscalingv1.CrossVersionObjectReference `json:"scaleTargetRef"`
24+
ScaleTargetRef autoscalingv2.CrossVersionObjectReference `json:"scaleTargetRef"`
2525

2626
// ModelID specifies the unique identifier of the model to be autoscaled.
2727
// +kubebuilder:validation:MinLength=1

api/v1alpha1/variantautoscaling_types_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66
"testing"
77
"time"
88

9-
autoscalingv1 "k8s.io/api/autoscaling/v1"
9+
autoscalingv2 "k8s.io/api/autoscaling/v2"
1010
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1111
"k8s.io/apimachinery/pkg/runtime"
1212
)
@@ -27,7 +27,7 @@ func makeValidVA() *VariantAutoscaling {
2727
},
2828
},
2929
Spec: VariantAutoscalingSpec{
30-
ScaleTargetRef: autoscalingv1.CrossVersionObjectReference{
30+
ScaleTargetRef: autoscalingv2.CrossVersionObjectReference{
3131
Kind: "Deployment",
3232
Name: "va-sample-deployment",
3333
},
@@ -140,7 +140,7 @@ func TestStatusOmitEmpty(t *testing.T) {
140140
Namespace: "default",
141141
},
142142
Spec: VariantAutoscalingSpec{
143-
ScaleTargetRef: autoscalingv1.CrossVersionObjectReference{
143+
ScaleTargetRef: autoscalingv2.CrossVersionObjectReference{
144144
Kind: "Deployment",
145145
Name: "va-empty-status-deployment",
146146
},

charts/workload-variant-autoscaler/crds/llmd.ai_variantautoscalings.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@ spec:
8383
- kind
8484
- name
8585
type: object
86-
x-kubernetes-map-type: atomic
8786
variantCost:
8887
default: "10.0"
8988
description: VariantCost specifies the cost per replica for this variant

config/crd/bases/llmd.ai_variantautoscalings.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@ spec:
8383
- kind
8484
- name
8585
type: object
86-
x-kubernetes-map-type: atomic
8786
variantCost:
8887
default: "10.0"
8988
description: VariantCost specifies the cost per replica for this variant

internal/actuator/actuator_test.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import (
2727
. "github.com/onsi/gomega"
2828
"github.com/prometheus/client_golang/prometheus"
2929
appsv1 "k8s.io/api/apps/v1"
30-
autoscalingv1 "k8s.io/api/autoscaling/v1"
30+
autoscalingv2 "k8s.io/api/autoscaling/v2"
3131
corev1 "k8s.io/api/core/v1"
3232
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
3333
"k8s.io/apimachinery/pkg/runtime"
@@ -118,7 +118,7 @@ var _ = Describe("Actuator", func() {
118118
Namespace: namespace,
119119
},
120120
Spec: llmdVariantAutoscalingV1alpha1.VariantAutoscalingSpec{
121-
ScaleTargetRef: autoscalingv1.CrossVersionObjectReference{
121+
ScaleTargetRef: autoscalingv2.CrossVersionObjectReference{
122122
Kind: "Deployment",
123123
Name: resourceName,
124124
},
@@ -149,7 +149,7 @@ var _ = Describe("Actuator", func() {
149149
Namespace: namespace,
150150
},
151151
Spec: llmdVariantAutoscalingV1alpha1.VariantAutoscalingSpec{
152-
ScaleTargetRef: autoscalingv1.CrossVersionObjectReference{
152+
ScaleTargetRef: autoscalingv2.CrossVersionObjectReference{
153153
Kind: "Deployment",
154154
Name: "non-existent",
155155
},
@@ -209,7 +209,7 @@ var _ = Describe("Actuator", func() {
209209
},
210210
},
211211
Spec: llmdVariantAutoscalingV1alpha1.VariantAutoscalingSpec{
212-
ScaleTargetRef: autoscalingv1.CrossVersionObjectReference{
212+
ScaleTargetRef: autoscalingv2.CrossVersionObjectReference{
213213
Kind: "Deployment",
214214
Name: contextResourceName,
215215
},
@@ -327,7 +327,7 @@ var _ = Describe("Actuator", func() {
327327
Namespace: namespace,
328328
},
329329
Spec: llmdVariantAutoscalingV1alpha1.VariantAutoscalingSpec{
330-
ScaleTargetRef: autoscalingv1.CrossVersionObjectReference{
330+
ScaleTargetRef: autoscalingv2.CrossVersionObjectReference{
331331
Kind: "Deployment",
332332
Name: contextResourceName,
333333
},
@@ -387,7 +387,7 @@ var _ = Describe("Actuator", func() {
387387
Namespace: namespace,
388388
},
389389
Spec: llmdVariantAutoscalingV1alpha1.VariantAutoscalingSpec{
390-
ScaleTargetRef: autoscalingv1.CrossVersionObjectReference{
390+
ScaleTargetRef: autoscalingv2.CrossVersionObjectReference{
391391
Kind: "Deployment",
392392
Name: "incomplete-va",
393393
},
@@ -456,7 +456,7 @@ var _ = Describe("Actuator", func() {
456456
Namespace: namespace,
457457
},
458458
Spec: llmdVariantAutoscalingV1alpha1.VariantAutoscalingSpec{
459-
ScaleTargetRef: autoscalingv1.CrossVersionObjectReference{
459+
ScaleTargetRef: autoscalingv2.CrossVersionObjectReference{
460460
Kind: "Deployment",
461461
Name: contextResourceName,
462462
},

internal/collector/source/pod_va_mapper_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66
. "github.com/onsi/ginkgo/v2"
77
. "github.com/onsi/gomega"
88
appsv1 "k8s.io/api/apps/v1"
9-
autoscalingv1 "k8s.io/api/autoscaling/v1"
9+
autoscalingv2 "k8s.io/api/autoscaling/v2"
1010
corev1 "k8s.io/api/core/v1"
1111
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1212
"k8s.io/apimachinery/pkg/runtime"
@@ -92,7 +92,7 @@ var _ = Describe("PodVAMapper", func() {
9292
Namespace: namespace,
9393
},
9494
Spec: llmdv1alpha1.VariantAutoscalingSpec{
95-
ScaleTargetRef: autoscalingv1.CrossVersionObjectReference{
95+
ScaleTargetRef: autoscalingv2.CrossVersionObjectReference{
9696
Kind: "Deployment",
9797
Name: deploymentName,
9898
APIVersion: "apps/v1",

internal/controller/indexers/indexers.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import (
2222

2323
llmdVariantAutoscalingV1alpha1 "github.com/llm-d/llm-d-workload-variant-autoscaler/api/v1alpha1"
2424
"github.com/llm-d/llm-d-workload-variant-autoscaler/internal/logging"
25-
autoscalingv1 "k8s.io/api/autoscaling/v1"
25+
autoscalingv2 "k8s.io/api/autoscaling/v2"
2626
ctrl "sigs.k8s.io/controller-runtime"
2727
"sigs.k8s.io/controller-runtime/pkg/client"
2828
"sigs.k8s.io/controller-runtime/pkg/manager"
@@ -38,7 +38,7 @@ const (
3838

3939
// scaleTargetIndexKey returns the composite index key for a scale target reference.
4040
// Format: Namespace/APIVersion/Kind/Name (e.g., "default/apps/v1/Deployment/my-app")
41-
func scaleTargetIndexKey(namespace string, ref autoscalingv1.CrossVersionObjectReference) string {
41+
func scaleTargetIndexKey(namespace string, ref autoscalingv2.CrossVersionObjectReference) string {
4242

4343
if ref.APIVersion == "" {
4444
switch ref.Kind {
@@ -77,7 +77,7 @@ func VAScaleTargetIndexFunc(o client.Object) []string {
7777
// FindVAForScaleTarget returns the VariantAutoscaling that targets the given scale resource.
7878
// Returns nil if no VariantAutoscaling targets this resource.
7979
// Note: A scale target should have at most one VariantAutoscaling targeting it, so the first match is returned.
80-
func FindVAForScaleTarget(ctx context.Context, c client.Client, ref autoscalingv1.CrossVersionObjectReference, namespace string) (*llmdVariantAutoscalingV1alpha1.VariantAutoscaling, error) {
80+
func FindVAForScaleTarget(ctx context.Context, c client.Client, ref autoscalingv2.CrossVersionObjectReference, namespace string) (*llmdVariantAutoscalingV1alpha1.VariantAutoscaling, error) {
8181
var vaList llmdVariantAutoscalingV1alpha1.VariantAutoscalingList
8282
if err := c.List(ctx, &vaList,
8383
client.InNamespace(namespace),
@@ -103,7 +103,7 @@ func FindVAForScaleTarget(ctx context.Context, c client.Client, ref autoscalingv
103103
// Returns nil if no VariantAutoscaling targets a Deployment with the given name.
104104
// This is a wrapper around FindVAForScaleTarget for the Deployment scale target.
105105
func FindVAForDeployment(ctx context.Context, c client.Client, deploymentName, namespace string) (*llmdVariantAutoscalingV1alpha1.VariantAutoscaling, error) {
106-
return FindVAForScaleTarget(ctx, c, autoscalingv1.CrossVersionObjectReference{
106+
return FindVAForScaleTarget(ctx, c, autoscalingv2.CrossVersionObjectReference{
107107
APIVersion: "apps/v1",
108108
Kind: "Deployment",
109109
Name: deploymentName,

internal/controller/indexers/indexers_test.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import (
2222

2323
. "github.com/onsi/ginkgo/v2"
2424
. "github.com/onsi/gomega"
25-
autoscalingv1 "k8s.io/api/autoscaling/v1"
25+
autoscalingv2 "k8s.io/api/autoscaling/v2"
2626
corev1 "k8s.io/api/core/v1"
2727
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2828
"sigs.k8s.io/controller-runtime/pkg/client"
@@ -110,7 +110,7 @@ var _ = Describe("Indexers", Ordered, func() {
110110
Namespace: namespace,
111111
},
112112
Spec: llmdv1alpha1.VariantAutoscalingSpec{
113-
ScaleTargetRef: autoscalingv1.CrossVersionObjectReference{
113+
ScaleTargetRef: autoscalingv2.CrossVersionObjectReference{
114114
APIVersion: "apps/v1",
115115
Kind: "Deployment",
116116
Name: deploymentName,
@@ -127,7 +127,7 @@ var _ = Describe("Indexers", Ordered, func() {
127127
Namespace: namespace,
128128
},
129129
Spec: llmdv1alpha1.VariantAutoscalingSpec{
130-
ScaleTargetRef: autoscalingv1.CrossVersionObjectReference{
130+
ScaleTargetRef: autoscalingv2.CrossVersionObjectReference{
131131
APIVersion: "apps/v1",
132132
Kind: "Deployment",
133133
Name: "other-deployment",
@@ -182,7 +182,7 @@ var _ = Describe("Indexers", Ordered, func() {
182182
Namespace: otherNs.Name,
183183
},
184184
Spec: llmdv1alpha1.VariantAutoscalingSpec{
185-
ScaleTargetRef: autoscalingv1.CrossVersionObjectReference{
185+
ScaleTargetRef: autoscalingv2.CrossVersionObjectReference{
186186
APIVersion: "apps/v1",
187187
Kind: "Deployment",
188188
Name: deploymentName, // Same deployment name but different namespace
@@ -217,7 +217,7 @@ var _ = Describe("Indexers", Ordered, func() {
217217
Namespace: namespace,
218218
},
219219
Spec: llmdv1alpha1.VariantAutoscalingSpec{
220-
ScaleTargetRef: autoscalingv1.CrossVersionObjectReference{
220+
ScaleTargetRef: autoscalingv2.CrossVersionObjectReference{
221221
APIVersion: "apps/v1",
222222
Kind: "Deployment",
223223
Name: sharedName,
@@ -237,7 +237,7 @@ var _ = Describe("Indexers", Ordered, func() {
237237
Namespace: namespace,
238238
},
239239
Spec: llmdv1alpha1.VariantAutoscalingSpec{
240-
ScaleTargetRef: autoscalingv1.CrossVersionObjectReference{
240+
ScaleTargetRef: autoscalingv2.CrossVersionObjectReference{
241241
APIVersion: "apps/v1",
242242
Kind: "StatefulSet",
243243
Name: sharedName,
@@ -261,7 +261,7 @@ var _ = Describe("Indexers", Ordered, func() {
261261

262262
// FindVAForScaleTarget with StatefulSet should return the StatefulSet-targeting VA
263263
Eventually(func() string {
264-
va, err := FindVAForScaleTarget(testCtx, mgrClient, autoscalingv1.CrossVersionObjectReference{
264+
va, err := FindVAForScaleTarget(testCtx, mgrClient, autoscalingv2.CrossVersionObjectReference{
265265
APIVersion: "apps/v1",
266266
Kind: "StatefulSet",
267267
Name: sharedName,
@@ -282,7 +282,7 @@ var _ = Describe("Indexers", Ordered, func() {
282282
Namespace: namespace,
283283
},
284284
Spec: llmdv1alpha1.VariantAutoscalingSpec{
285-
ScaleTargetRef: autoscalingv1.CrossVersionObjectReference{
285+
ScaleTargetRef: autoscalingv2.CrossVersionObjectReference{
286286
APIVersion: "apps/v1",
287287
Kind: "Deployment",
288288
Name: sharedName,
@@ -301,7 +301,7 @@ var _ = Describe("Indexers", Ordered, func() {
301301
Namespace: namespace,
302302
},
303303
Spec: llmdv1alpha1.VariantAutoscalingSpec{
304-
ScaleTargetRef: autoscalingv1.CrossVersionObjectReference{
304+
ScaleTargetRef: autoscalingv2.CrossVersionObjectReference{
305305
APIVersion: "apps/v1",
306306
Kind: "Deployment",
307307
Name: sharedName,
@@ -315,7 +315,7 @@ var _ = Describe("Indexers", Ordered, func() {
315315
}()
316316

317317
Eventually(func() error {
318-
_, err := FindVAForScaleTarget(testCtx, mgrClient, autoscalingv1.CrossVersionObjectReference{
318+
_, err := FindVAForScaleTarget(testCtx, mgrClient, autoscalingv2.CrossVersionObjectReference{
319319
APIVersion: "apps/v1",
320320
Kind: "Deployment",
321321
Name: sharedName,
@@ -335,7 +335,7 @@ var _ = Describe("Indexers", Ordered, func() {
335335
Namespace: namespace,
336336
},
337337
Spec: llmdv1alpha1.VariantAutoscalingSpec{
338-
ScaleTargetRef: autoscalingv1.CrossVersionObjectReference{
338+
ScaleTargetRef: autoscalingv2.CrossVersionObjectReference{
339339
APIVersion: "apps/v1",
340340
Kind: "Deployment",
341341
Name: deploymentName,
@@ -367,7 +367,7 @@ var _ = Describe("Indexers", Ordered, func() {
367367
Namespace: namespace,
368368
},
369369
Spec: llmdv1alpha1.VariantAutoscalingSpec{
370-
ScaleTargetRef: autoscalingv1.CrossVersionObjectReference{
370+
ScaleTargetRef: autoscalingv2.CrossVersionObjectReference{
371371
// APIVersion is not set - should default to apps/v1
372372
Kind: "Deployment",
373373
Name: deploymentName,

internal/controller/variantautoscaling_controller_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import (
2323
. "github.com/onsi/ginkgo/v2"
2424
. "github.com/onsi/gomega"
2525
promoperator "github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring/v1"
26-
autoscalingv1 "k8s.io/api/autoscaling/v1"
26+
autoscalingv2 "k8s.io/api/autoscaling/v2"
2727
v1 "k8s.io/api/core/v1"
2828
"k8s.io/apimachinery/pkg/api/errors"
2929
"k8s.io/apimachinery/pkg/types"
@@ -85,7 +85,7 @@ var _ = Describe("VariantAutoscalings Controller", func() {
8585
},
8686
// TODO(user): Specify other spec details if needed.
8787
Spec: llmdVariantAutoscalingV1alpha1.VariantAutoscalingSpec{
88-
ScaleTargetRef: autoscalingv1.CrossVersionObjectReference{
88+
ScaleTargetRef: autoscalingv2.CrossVersionObjectReference{
8989
Kind: "Deployment",
9090
Name: resourceName,
9191
},
@@ -192,7 +192,7 @@ var _ = Describe("VariantAutoscalings Controller", func() {
192192
Namespace: "default",
193193
},
194194
Spec: llmdVariantAutoscalingV1alpha1.VariantAutoscalingSpec{
195-
ScaleTargetRef: autoscalingv1.CrossVersionObjectReference{
195+
ScaleTargetRef: autoscalingv2.CrossVersionObjectReference{
196196
Kind: "Deployment",
197197
Name: "invalid-model-id",
198198
},
@@ -310,7 +310,7 @@ var _ = Describe("VariantAutoscalings Controller", func() {
310310
Namespace: "default",
311311
},
312312
Spec: llmdVariantAutoscalingV1alpha1.VariantAutoscalingSpec{
313-
ScaleTargetRef: autoscalingv1.CrossVersionObjectReference{
313+
ScaleTargetRef: autoscalingv2.CrossVersionObjectReference{
314314
Kind: "Deployment",
315315
Name: resourceName,
316316
},
@@ -402,7 +402,7 @@ var _ = Describe("VariantAutoscalings Controller", func() {
402402
Namespace: "default",
403403
},
404404
Spec: llmdVariantAutoscalingV1alpha1.VariantAutoscalingSpec{
405-
ScaleTargetRef: autoscalingv1.CrossVersionObjectReference{
405+
ScaleTargetRef: autoscalingv2.CrossVersionObjectReference{
406406
Kind: "Deployment",
407407
Name: resourceName,
408408
},

internal/engines/saturation/engine_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import (
2525
. "github.com/onsi/gomega"
2626
"github.com/prometheus/common/model"
2727
appsv1 "k8s.io/api/apps/v1"
28-
autoscalingv1 "k8s.io/api/autoscaling/v1"
28+
autoscalingv2 "k8s.io/api/autoscaling/v2"
2929
v1 "k8s.io/api/core/v1"
3030
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
3131
"sigs.k8s.io/controller-runtime/pkg/client"
@@ -145,7 +145,7 @@ data:
145145
},
146146
},
147147
Spec: llmdVariantAutoscalingV1alpha1.VariantAutoscalingSpec{
148-
ScaleTargetRef: autoscalingv1.CrossVersionObjectReference{
148+
ScaleTargetRef: autoscalingv2.CrossVersionObjectReference{
149149
Kind: "Deployment",
150150
Name: name,
151151
},
@@ -381,7 +381,7 @@ data:
381381
},
382382
},
383383
Spec: llmdVariantAutoscalingV1alpha1.VariantAutoscalingSpec{
384-
ScaleTargetRef: autoscalingv1.CrossVersionObjectReference{
384+
ScaleTargetRef: autoscalingv2.CrossVersionObjectReference{
385385
Kind: "Deployment",
386386
Name: name,
387387
},

0 commit comments

Comments
 (0)