Skip to content

Conversation

@R-Lawton
Copy link
Contributor

@R-Lawton R-Lawton commented Jan 16, 2026

Closes one part of Kuadrant/kuadrant-backstage-plugin#96

Changes:

  • Added StatusConditionOpenAPISpecReady to track OpenAPI spec fetch status
  • Added custom error type OpenAPISpecErr for structured error handling
  • Enhanced error handling for HTTP fetch failures (non-200 status codes)
  • Added 500KB size limit validation for OpenAPI specs
  • Fixed caching logic to prevent unnecessary re-fetching

#Verification

  • Create a Kind cluster and install dependencies:
make kind-create-cluster
make install
make gateway-api-install
make kuadrant-core-install
  • Deploy the controller locally:
make run
  • Create Gateway and httproute
kubectl create ns gateway-system

kubectl apply -f - <<EOF
apiVersion: gateway.networking.k8s.io/v1
kind: Gateway
metadata:
 name: my-gateway
 namespace: gateway-system
spec:
 gatewayClassName: istio
 listeners:
 - name: http
   protocol: HTTP
   port: 80
   hostname: "example.com"
   allowedRoutes:
     namespaces:
       from: All
EOF

kubectl create ns toystore

kubectl apply -f - <<EOF
apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
 name: my-route
 namespace: toystore
spec:
 hostnames:
   - example.com
 parentRefs:
   - name: my-gateway
     namespace: gateway-system
 rules:
   - matches:
       - path:
           type: PathPrefix
           value: "/"
     backendRefs:
       - name: toystore
         port: 80
EOF
  • Create APiProduct (To not reinvent the wheel im using King Eguzki gist for the openapispec url)
kubectl apply -f - <<EOF
apiVersion: devportal.kuadrant.io/v1alpha1
kind: APIProduct
metadata:
  name: toystore-api
  namespace: toystore
spec:
  targetRef:
    group: gateway.networking.k8s.io
    kind: HTTPRoute
    name: my-route
  displayName: Toystore API
  description: Manage toy inventory
  approvalMode: manual
  publishStatus: Published
  documentation:
    openAPISpecURL: https://gist.githubusercontent.com/eguzki/1ba21b75a2df0b3a9c78f83181a5a950/raw/7460b6b7bb8e1761327adbfb979d8f4f8d2e7008/petstore-openapi.yaml
EOF
  • Everything should be hunky dory, so you should see
 - lastTransitionTime: "2026-01-16T11:55:33Z"
      message: OpenAPI spec was successfully fetched
      reason: SpecFetched
      status: "True"
      type: OpenAPISpecReady
    observedGeneration: 3
    openapi:
      lastSyncTime: "2026-01-16T11:55:33Z"
      raw: |-
        {
          "openapi": "3.1.0",
          "info": {
            "version": "1.0.0",
            "title": "Swagger Petstore",
            "license": {
              "name": "MIT",
              "url": "https://opensource.org/licenses/MIT"
            }
          },
  • Update file size limit to 1024 via env var OPENAPI_SPEC_MAX_SIZE=1024 make run

  • You should see in the conditions

- lastTransitionTime: "2026-01-16T11:42:16Z"
      message: OpenAPI spec exceeds size limit (1024 bytes)
      reason: SpecSizeTooLarge
      status: "False"
      type: OpenAPISpecReady
    observedGeneration: 3
    openapi:
      lastSyncTime: "2026-01-16T11:54:56Z"
      raw: ""
  • Edit the url to be wrong to create a 404 e.g change eguzki to eguz you should see
kubectl edit apiproduct -n toystore
 - lastTransitionTime: "2026-01-16T11:55:53Z"
      message: 'failed to fetch OpenAPI spec from https://gist.githubusercontent.com/egki/1ba21b75a2df0b3a9c78f83181a5a950/raw/7460b6b7bb8e1761327adbfb979d8f4f8d2e7008/petstore-openapi.yaml:
        unexpected status code 404'
      reason: FetchFailed
      status: "False"
      type: OpenAPISpecReady
    observedGeneration: 4
    openapi:
      lastSyncTime: "2026-01-16T11:55:53Z"
      raw: ""

Signed-off-by: R-Lawton <rlawton@redhat.com>
Signed-off-by: R-Lawton <rlawton@redhat.com>
@R-Lawton R-Lawton marked this pull request as ready for review January 16, 2026 14:03
@R-Lawton R-Lawton marked this pull request as draft January 16, 2026 14:06
@R-Lawton R-Lawton marked this pull request as ready for review January 16, 2026 14:57
Comment on lines 249 to 257
if envMaxSize := os.Getenv("OPENAPI_SPEC_MAX_SIZE"); envMaxSize != "" {
if parsed, err := strconv.Atoi(envMaxSize); err == nil && parsed > 0 {
openAPIMaxSize = parsed
setupLog.Info("using custom OpenAPI spec max size", "size", openAPIMaxSize)
} else {
setupLog.Error(err, "invalid OPENAPI_SPEC_MAX_SIZE env var, using default", openAPIMaxSize)
}
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i was on the fence about adding this ability in but it was in the issue, feels a bit overkill?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's a nice-to-have feature rather than a requirement, but since it's already here, I think we can leave it in.

Signed-off-by: R-Lawton <rlawton@redhat.com>

Fixed the tests

Signed-off-by: R-Lawton <rlawton@redhat.com>
…d. Also some spelling mistakes

Signed-off-by: R-Lawton <rlawton@redhat.com>
@R-Lawton R-Lawton changed the title Gh 96 Gh 96 adding status condition for openapispec Jan 19, 2026
Signed-off-by: R-Lawton <rlawton@redhat.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants