mirror of
https://github.com/cozystack/cozystack.git
synced 2026-03-14 20:48:58 +00:00
This commit refactors the apiserver REST handlers to use typed objects (appsv1alpha1.Application) instead of unstructured.Unstructured, eliminating the need for runtime conversions and simplifying the codebase. Additionally, it fixes an issue where UnstructuredList objects were using the first registered kind from typeToGVK instead of the kind from the object's field when multiple kinds are registered with the same Go type. This is a more comprehensive fix for the problem addressed in https://github.com/cozystack/cozystack/pull/1630, which was reverted in https://github.com/cozystack/cozystack/pull/1677. The fix includes the upstream fix from kubernetes/kubernetes#135537, which enables short-circuit path for UnstructuredList similar to regular Unstructured objects, using GVK from the object field instead of typeToGVK. Changes: - Refactored rest.go handlers to use typed Application objects - Removed unstructured.Unstructured conversions - Fixed UnstructuredList GVK handling - Updated dependencies in go.mod/go.sum - Added e2e test for OpenAPI validation - Updated Dockerfile Signed-off-by: Andrei Kvapil <kvapss@gmail.com>
54 lines
1.9 KiB
Bash
54 lines
1.9 KiB
Bash
#!/usr/bin/env bats
|
|
# -----------------------------------------------------------------------------
|
|
# Test OpenAPI endpoints in a Kubernetes cluster
|
|
# -----------------------------------------------------------------------------
|
|
|
|
@test "Test OpenAPI v2 endpoint" {
|
|
kubectl get -v7 --raw '/openapi/v2?timeout=32s' > /dev/null
|
|
}
|
|
|
|
@test "Test OpenAPI v3 endpoint" {
|
|
kubectl get -v7 --raw '/openapi/v3/apis/apps.cozystack.io/v1alpha1' > /dev/null
|
|
kubectl get -v7 --raw '/openapi/v3/apis/core.cozystack.io/v1alpha1' > /dev/null
|
|
}
|
|
|
|
@test "Test OpenAPI v2 endpoint (protobuf)" {
|
|
(
|
|
kubectl proxy --port=21234 & sleep 0.5
|
|
trap "kill $!" EXIT
|
|
curl -sS --fail 'http://localhost:21234/openapi/v2?timeout=32s' -H 'Accept: application/com.github.proto-openapi.spec.v2@v1.0+protobuf' > /dev/null
|
|
)
|
|
}
|
|
|
|
@test "Test kinds" {
|
|
val=$(kubectl get --raw /apis/apps.cozystack.io/v1alpha1/tenants | jq -r '.kind')
|
|
if [ "$val" != "TenantList" ]; then
|
|
echo "Expected kind to be TenantList, got $val"
|
|
exit 1
|
|
fi
|
|
val=$(kubectl get --raw /apis/apps.cozystack.io/v1alpha1/tenants | jq -r '.items[0].kind')
|
|
if [ "$val" != "Tenant" ]; then
|
|
echo "Expected kind to be Tenant, got $val"
|
|
exit 1
|
|
fi
|
|
val=$(kubectl get --raw /apis/apps.cozystack.io/v1alpha1/ingresses | jq -r '.kind')
|
|
if [ "$val" != "IngressList" ]; then
|
|
echo "Expected kind to be IngressList, got $val"
|
|
exit 1
|
|
fi
|
|
val=$(kubectl get --raw /apis/apps.cozystack.io/v1alpha1/ingresses | jq -r '.items[0].kind')
|
|
if [ "$val" != "Ingress" ]; then
|
|
echo "Expected kind to be Ingress, got $val"
|
|
exit 1
|
|
fi
|
|
}
|
|
|
|
@test "Create and delete namespace" {
|
|
kubectl create ns cozy-test-create-and-delete-namespace --dry-run=client -o yaml | kubectl apply -f -
|
|
if ! kubectl delete ns cozy-test-create-and-delete-namespace; then
|
|
echo "Failed to delete namespace"
|
|
kubectl describe ns cozy-test-create-and-delete-namespace
|
|
exit 1
|
|
fi
|
|
}
|