Skip to content

Commit

Permalink
add conformance tests
Browse files Browse the repository at this point in the history
  • Loading branch information
skonto committed Dec 11, 2024
1 parent 03dafbc commit b41f736
Show file tree
Hide file tree
Showing 4 changed files with 159 additions and 0 deletions.
42 changes: 42 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Copyright 2024 The Knative Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

FROM golang AS builder

ARG TARGETOS
ARG TARGETARCH

# Create and change to the app directory.
WORKDIR /app

# Copy local code to the container image.
COPY . ./

RUN go mod tidy

# Build the command inside the container.
RUN CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build -o ./autoscaler-keda ./cmd/autoscaler-keda/

# Use a Docker multi-stage build to create a lean production image.
# https://docs.docker.com/develop/develop-images/multistage-build/#use-multi-stage-builds
# https://github.com/GoogleContainerTools/distroless#readme
FROM gcr.io/distroless/base:nonroot

# Copy the binaries to the production image from the builder stage.
COPY --from=builder /app/autoscaler-keda /autoscaler-keda

WORKDIR /home/nonroot

# Run the service on container startup.
ENTRYPOINT ["/autoscaler-keda"]
99 changes: 99 additions & 0 deletions hack/patches/conformance.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
diff --git a/test/conformance/api/v1/resources_test.go b/test/conformance/api/v1/resources_test.go
index 03abcb012..d447c8e56 100644
--- a/test/conformance/api/v1/resources_test.go
+++ b/test/conformance/api/v1/resources_test.go
@@ -126,6 +126,7 @@ func createResources() corev1.ResourceRequirements {
corev1.ResourceMemory: resource.MustParse("350Mi"),
},
Requests: corev1.ResourceList{
+ corev1.ResourceCPU: resource.MustParse("30m"),
corev1.ResourceMemory: resource.MustParse("350Mi"),
},
}
diff --git a/test/conformance/api/v1/service_test.go b/test/conformance/api/v1/service_test.go
index 3c9c9833f..9eafd44d0 100644
--- a/test/conformance/api/v1/service_test.go
+++ b/test/conformance/api/v1/service_test.go
@@ -727,6 +727,14 @@ func TestServiceCreateWithMultipleContainers(t *testing.T) {
Image: pkgtest.ImagePath(names.Sidecars[0]),
}}

+ for i, c := range containers {
+ c.Resources = corev1.ResourceRequirements{Requests: corev1.ResourceList{
+ corev1.ResourceCPU: resource.MustParse("30m"),
+ corev1.ResourceMemory: resource.MustParse("20Mi"),
+ }}
+ containers[i] = c
+ }
+
// Please see the comment in test/v1/configuration.go.
if !test.ServingFlags.DisableOptionalAPI {
for _, c := range containers {
diff --git a/test/test_images/runtime/handlers/runtime.go b/test/test_images/runtime/handlers/runtime.go
index 203160de7..c357f0ee7 100644
--- a/test/test_images/runtime/handlers/runtime.go
+++ b/test/test_images/runtime/handlers/runtime.go
@@ -56,6 +56,7 @@ func runtimeHandler(w http.ResponseWriter, r *http.Request) {
},
}

+ log.Printf("Runtime Info: %+v", k)
writeJSON(w, k)
}

diff --git a/test/v1/configuration.go b/test/v1/configuration.go
index b5b2fedf8..b0ccb50c9 100644
--- a/test/v1/configuration.go
+++ b/test/v1/configuration.go
@@ -19,6 +19,7 @@ package v1
import (
"context"
"fmt"
+ "k8s.io/apimachinery/pkg/api/resource"
"testing"

corev1 "k8s.io/api/core/v1"
@@ -113,6 +114,15 @@ func ConfigurationSpec(imagePath string) *v1.ConfigurationSpec {
PodSpec: corev1.PodSpec{
Containers: []corev1.Container{{
Image: imagePath,
+ Resources: corev1.ResourceRequirements{
+ Requests: corev1.ResourceList{
+ corev1.ResourceCPU: resource.MustParse("30m"),
+ corev1.ResourceMemory: resource.MustParse("20Mi"),
+ },
+ Limits: corev1.ResourceList{
+ corev1.ResourceCPU: resource.MustParse("300m"),
+ },
+ },
}},
},
},
diff --git a/test/v1/service.go b/test/v1/service.go
index 9d8db16c8..11ad078f8 100644
--- a/test/v1/service.go
+++ b/test/v1/service.go
@@ -20,6 +20,7 @@ import (
"context"
"encoding/json"
"fmt"
+ "k8s.io/apimachinery/pkg/api/resource"
"testing"

corev1 "k8s.io/api/core/v1"
@@ -243,6 +244,15 @@ func Service(names test.ResourceNames, fopt ...rtesting.ServiceOption) *v1.Servi
if names.Image != "" && len(names.Sidecars) == 0 {
a := append([]rtesting.ServiceOption{
rtesting.WithConfigSpec(ConfigurationSpec(pkgTest.ImagePath(names.Image))),
+ rtesting.WithResourceRequirements(corev1.ResourceRequirements{
+ Requests: corev1.ResourceList{
+ corev1.ResourceCPU: resource.MustParse("30m"),
+ corev1.ResourceMemory: resource.MustParse("20Mi"),
+ },
+ Limits: corev1.ResourceList{
+ corev1.ResourceCPU: resource.MustParse("300m"),
+ },
+ }),
}, fopt...)
return rtesting.ServiceWithoutNamespace(names.Service, a...)
}
14 changes: 14 additions & 0 deletions test/e2e-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,20 @@ header "Running HPA tests"
# Needed for HPA Mem test, see https://keda.sh/docs/2.14/scalers/memory/#prerequisites
toggle_feature queueproxy.resource-defaults "enabled" config-features
go_test_e2e -timeout=30m -tags=hpa ./test/e2e "${E2E_TEST_FLAGS[@]}" || failed=1

git apply ../hack/patches/conformance.patch
# Run conformance tests
# set pod-autoscaler-class to hpa.autoscaling.knative.dev
kubectl patch cm config-autoscaler -n ${SYSTEM_NAMESPACE} -p '{"data":{"pod-autoscaler-class": "hpa.autoscaling.knative.dev"}}'
header "Running conformance tests"
go_test_e2e -timeout=30m \
"${GO_TEST_FLAGS[@]}" \
./test/conformance/api/... \
./test/conformance/runtime/... \
"${E2E_TEST_FLAGS[@]}" || failed=1
git apply -R ../hack/patches/conformance.patch
# restore deault pod-autoscaler-class
kubectl patch cm config-autoscaler -n ${SYSTEM_NAMESPACE} -p '{"data":{"pod-autoscaler-class": "kpa.autoscaling.knative.dev"}}'
popd

# run e2e tests in this repo
Expand Down
4 changes: 4 additions & 0 deletions test/test_images/metrics-test/service_cpu.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ spec:
ports:
- name: http1
containerPort: 8080
resources:
requests:
cpu: 30m
memory: 40Mi
---
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
Expand Down

0 comments on commit b41f736

Please sign in to comment.