## What this PR does This PR 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 ### Release note ```release-note [apps] Refactor apiserver to use typed objects and fix UnstructuredList GVK handling This change refactors the apiserver REST handlers to use typed Application objects instead of unstructured.Unstructured, eliminating runtime conversions and simplifying the codebase. Additionally, it fixes an issue where UnstructuredList objects were incorrectly 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 fix includes the upstream fix from kubernetes/kubernetes#135537. ``` <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Chores** * Added a module replacement in dependency configuration to ensure reproducible builds. * **Refactor** * REST internals now use strongly-typed Application and TenantModule resources and return typed API objects with consistent metadata. * **Tests** * Strengthened end-to-end checks for resource kinds and added a create/delete namespace scenario. <sub>✏️ Tip: You can customize this high-level summary in your review settings.</sub> <!-- end of auto-generated comment: release notes by coderabbit.ai -->
53 lines
1.9 KiB
Bash
53 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
|
|
}
|