Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run Serving conformance tests and more #88

Merged
merged 3 commits into from
Dec 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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...)
}
17 changes: 16 additions & 1 deletion test/e2e-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ source ./test/e2e-common.sh
knative_setup

echo ">> Uploading test images..."
ko resolve --jobs=4 -RBf ./test/test_images/autoscale > /dev/null
./test/upload-test-images.sh
popd

# Setup Helm - TODO move to the infra image
Expand Down Expand Up @@ -83,6 +83,21 @@ 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"
E2E_TEST_FLAGS+=("-enable-alpha" "-enable-beta")
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
Loading