Skip to content

Commit

Permalink
versionupgrade: upgraded k8s autoscaling version in middleware
Browse files Browse the repository at this point in the history
  • Loading branch information
shudeshp authored and openshift-merge-bot[bot] committed Nov 1, 2024
1 parent 9757978 commit fd244d8
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
4 changes: 2 additions & 2 deletions pkg/middleware/middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
route "github.com/openshift/api/route/v1"
quaycontext "github.com/quay/quay-operator/pkg/context"
appsv1 "k8s.io/api/apps/v1"
autoscalingv1 "k8s.io/api/autoscaling/v1"
autoscalingv2 "k8s.io/api/autoscaling/v2"
batchv1 "k8s.io/api/batch/v1"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/meta"
Expand Down Expand Up @@ -226,7 +226,7 @@ func Process(quay *v1.QuayRegistry, qctx *quaycontext.QuayRegistryContext, obj c
return pvc, nil
}

if _, ok := obj.(*autoscalingv1.HorizontalPodAutoscaler); ok {
if _, ok := obj.(*autoscalingv2.HorizontalPodAutoscaler); ok {
componentMap := map[string]v1.ComponentKind{
"mirror": v1.ComponentMirror,
"clair": v1.ComponentClair,
Expand Down
34 changes: 34 additions & 0 deletions pkg/middleware/middleware_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
route "github.com/openshift/api/route/v1"
quaycontext "github.com/quay/quay-operator/pkg/context"
"github.com/stretchr/testify/assert"
autoscalingv2 "k8s.io/api/autoscaling/v2"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down Expand Up @@ -249,3 +250,36 @@ func parseResourceString(s string) *resource.Quantity {
resourceSize := resource.MustParse(s)
return &resourceSize
}

func TestHPAWithUnmanagedMirrorAndClair(t *testing.T) {
quayRegistry := &v1.QuayRegistry{
Spec: v1.QuayRegistrySpec{
Components: []v1.Component{
{Kind: "mirror", Managed: false},
{Kind: "clair", Managed: false},
{Kind: "horizontalpodautoscaler", Managed: true},
},
},
}

hpa := &autoscalingv2.HorizontalPodAutoscaler{
ObjectMeta: metav1.ObjectMeta{
Name: "registry-quay-app",
Labels: map[string]string{
"quay-component": "clair",
},
},
}

// Create a mock context and logger
qctx := &quaycontext.QuayRegistryContext{}

// Call the Process function
result, err := Process(quayRegistry, qctx, hpa, false)

// Assert that there is no error
assert.NoError(t, err)

// Assert that the result is nil
assert.Nil(t, result)
}

0 comments on commit fd244d8

Please sign in to comment.