generated from kedacore/github-template
-
Notifications
You must be signed in to change notification settings - Fork 95
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Jan Wozniak <wozniak.jan@gmail.com>
- Loading branch information
1 parent
30e7571
commit c4e5571
Showing
2 changed files
with
276 additions
and
0 deletions.
There are no files selected for viewing
236 changes: 236 additions & 0 deletions
236
tests/checks/httproute_in_app_namespace/httproute_in_app_namespace.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,236 @@ | ||
//go:build e2e | ||
// +build e2e | ||
|
||
package ingress_in_app_namespace_test | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"k8s.io/client-go/kubernetes" | ||
|
||
. "github.com/kedacore/http-add-on/tests/helper" | ||
) | ||
|
||
const ( | ||
testName = "ingress-in-app-namespace-test" | ||
) | ||
|
||
var ( | ||
testNamespace = fmt.Sprintf("%s-ns", testName) | ||
deploymentName = fmt.Sprintf("%s-deployment", testName) | ||
serviceName = fmt.Sprintf("%s-service", testName) | ||
httprouteName = fmt.Sprintf("%s-httproute", testName) | ||
httpScaledObjectName = fmt.Sprintf("%s-http-so", testName) | ||
referenceGrantName = fmt.Sprintf("%s-rg", testName) | ||
gatewayHost = "http://envoy-gateway.envoy-gateway-system.svc.cluster.local" | ||
host = testName | ||
minReplicaCount = 0 | ||
maxReplicaCount = 1 | ||
) | ||
|
||
type templateData struct { | ||
TestNamespace string | ||
DeploymentName string | ||
ServiceName string | ||
HTTPRouteName string | ||
ReferenceGrantName string | ||
KEDANamespace string | ||
GatewayHost string | ||
HTTPScaledObjectName string | ||
Host string | ||
MinReplicas int | ||
MaxReplicas int | ||
} | ||
|
||
const ( | ||
httprouteTemplate = ` | ||
apiVersion: gateway.networking.k8s.io/v1 | ||
kind: HTTPRoute | ||
metadata: | ||
name: {{.HTTPRouteName}} | ||
namespace: {{.TestNamespace}} | ||
spec: | ||
parentRefs: | ||
- name: eg | ||
namespace: envoy-gateway-system | ||
hostnames: | ||
- {{.Host}} | ||
rules: | ||
- backendRefs: | ||
- kind: Service | ||
name: {{ .ServiceName }} | ||
namespace: keda | ||
port: 8080 | ||
matches: | ||
- path: | ||
type: PathPrefix | ||
value: / | ||
` | ||
|
||
referenceGrantTemplate = ` | ||
apiVersion: gateway.networking.k8s.io/v1 | ||
kind: ReferenceGrant | ||
metadata: | ||
name: {{.ReferenceGrantName}} | ||
namespace: {{.TestNamespace}} | ||
spec: | ||
from: | ||
- group: gateway.networking.k8s.io | ||
kind: HTTPRoute | ||
namespace: {{.TestNamespace}} | ||
to: | ||
- group: "" | ||
kind: Service | ||
name: keda-http-add-on-interceptor-proxy | ||
` | ||
serviceTemplate = ` | ||
apiVersion: v1 | ||
kind: Service | ||
metadata: | ||
name: {{.ServiceName}} | ||
namespace: {{.TestNamespace}} | ||
labels: | ||
app: {{.DeploymentName}} | ||
spec: | ||
ports: | ||
- port: 8080 | ||
targetPort: http | ||
protocol: TCP | ||
name: http | ||
selector: | ||
app: {{.DeploymentName}} | ||
` | ||
|
||
deploymentTemplate = ` | ||
apiVersion: apps/v1 | ||
kind: Deployment | ||
metadata: | ||
name: {{.DeploymentName}} | ||
namespace: {{.TestNamespace}} | ||
labels: | ||
app: {{.DeploymentName}} | ||
spec: | ||
replicas: 0 | ||
selector: | ||
matchLabels: | ||
app: {{.DeploymentName}} | ||
template: | ||
metadata: | ||
labels: | ||
app: {{.DeploymentName}} | ||
spec: | ||
containers: | ||
- name: {{.DeploymentName}} | ||
image: registry.k8s.io/e2e-test-images/agnhost:2.45 | ||
args: | ||
- netexec | ||
ports: | ||
- name: http | ||
containerPort: 8080 | ||
protocol: TCP | ||
readinessProbe: | ||
httpGet: | ||
path: / | ||
port: http | ||
` | ||
|
||
loadJobTemplate = ` | ||
apiVersion: batch/v1 | ||
kind: Job | ||
metadata: | ||
name: generate-request | ||
namespace: {{.TestNamespace}} | ||
spec: | ||
template: | ||
spec: | ||
containers: | ||
- name: curl-client | ||
image: curlimages/curl | ||
imagePullPolicy: Always | ||
command: ["curl", "-H", "Host: {{.Host}}", "{{.GatewayHost}}"] | ||
restartPolicy: Never | ||
activeDeadlineSeconds: 600 | ||
backoffLimit: 5 | ||
` | ||
|
||
httpScaledObjectTemplate = ` | ||
kind: HTTPScaledObject | ||
apiVersion: http.keda.sh/v1alpha1 | ||
metadata: | ||
name: {{.HTTPScaledObjectName}} | ||
namespace: {{.TestNamespace}} | ||
spec: | ||
hosts: | ||
- {{.Host}} | ||
targetPendingRequests: 100 | ||
scaledownPeriod: 10 | ||
scaleTargetRef: | ||
deployment: {{.DeploymentName}} | ||
service: {{.ServiceName}} | ||
port: 8080 | ||
replicas: | ||
min: {{ .MinReplicas }} | ||
max: {{ .MaxReplicas }} | ||
` | ||
) | ||
|
||
func TestCheck(t *testing.T) { | ||
// setup | ||
t.Log("--- setting up ---") | ||
// Create kubernetes resources | ||
kc := GetKubernetesClient(t) | ||
data, templates := getTemplateData() | ||
CreateKubernetesResources(t, kc, testNamespace, data, templates) | ||
|
||
assert.True(t, WaitForDeploymentReplicaReadyCount(t, kc, deploymentName, testNamespace, minReplicaCount, 6, 10), | ||
"replica count should be %d after 1 minutes", minReplicaCount) | ||
assert.True(t, WaitForIngressReady(t, kc, httprouteName, testNamespace, 12, 10), | ||
"ingress should be ready after 2 minutes") | ||
|
||
testScaleOut(t, kc, data) | ||
testScaleIn(t, kc, data) | ||
|
||
// cleanup | ||
DeleteKubernetesResources(t, testNamespace, data, templates) | ||
} | ||
|
||
func testScaleOut(t *testing.T, kc *kubernetes.Clientset, data templateData) { | ||
t.Log("--- testing scale out ---") | ||
|
||
KubectlApplyWithTemplate(t, data, "loadJobTemplate", loadJobTemplate) | ||
|
||
assert.True(t, WaitForDeploymentReplicaReadyCount(t, kc, deploymentName, testNamespace, maxReplicaCount, 6, 10), | ||
"replica count should be %d after 1 minutes", maxReplicaCount) | ||
} | ||
|
||
func testScaleIn(t *testing.T, kc *kubernetes.Clientset, data templateData) { | ||
t.Log("--- testing scale out ---") | ||
|
||
KubectlDeleteWithTemplate(t, data, "loadJobTemplate", loadJobTemplate) | ||
assert.True(t, WaitForDeploymentReplicaReadyCount(t, kc, deploymentName, testNamespace, minReplicaCount, 12, 10), | ||
"replica count should be %d after 2 minutes", minReplicaCount) | ||
} | ||
|
||
func getTemplateData() (templateData, []Template) { | ||
return templateData{ | ||
TestNamespace: testNamespace, | ||
DeploymentName: deploymentName, | ||
ServiceName: serviceName, | ||
HTTPRouteName: httprouteName, | ||
ReferenceGrantName: referenceGrantName, | ||
KEDANamespace: KEDANamespace, | ||
HTTPScaledObjectName: httpScaledObjectName, | ||
GatewayHost: gatewayHost, | ||
Host: host, | ||
MinReplicas: minReplicaCount, | ||
MaxReplicas: maxReplicaCount, | ||
}, []Template{ | ||
{Name: "deploymentTemplate", Config: deploymentTemplate}, | ||
{Name: "serviceTemplate", Config: serviceTemplate}, | ||
{Name: "httprouteTemplate", Config: httprouteTemplate}, | ||
{Name: "httpScaledObjectTemplate", Config: httpScaledObjectTemplate}, | ||
{Name: "referenceGrantTemplate", Config: referenceGrantTemplate}, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters