Kuadrant / kuadrantctl

Kuadrant configuration command line utility
Apache License 2.0
6 stars 13 forks source link

Adds Gateway API HTTPRoute integration #39

Closed jjaferson closed 2 years ago

jjaferson commented 2 years ago

Adds integration to Gateway API to generate HTTPRoute

Command to generate Gateway API routing integration from Open API specification:

kuadrantctl generate gatewayapi httproute 

Example:

---
openapi: "3.0.0"
info:
  title: "Pet Store API"
  version: "1.0.0"
servers:
  - url: https://toplevel.example.io/v1
paths:
  /cat:
    get:
      parameters:
        - in: header
          name: X-username
          schema:
            type: string
      operationId: "getCat"
      responses:
        405:
          description: "invalid input"
    post:
      operationId: "postCat"
      responses:
        405:
          description: "invalid input"
  /dog:
    get:
      operationId: "getDog"
      responses:
        405:
          description: "invalid input"

Running the defined parameters below --namespace myns, --oas ./examples/oas3/petstore.yaml, --public-host www.kuadrant.io, --service-name myservice and --gateway kuadrant-gateway

kuadrantctl generate gatewayapi httproute --namespace myns --oas ./examples/oas3/petstore.yaml --public-host www.kuadrant.io --service-name myservice --gateway kuadrant-gateway

The CLI will generate the result below:

{
   "kind":"HTTPRoute",
   "apiVersion":"gateway.networking.k8s.io/v1alpha2",
   "metadata":{
      "creationTimestamp":null
   },
   "spec":{
      "hostnames":[
         "www.kuadrant.io"
      ],
      "rules":[
         {
            "matches":[
               {
                  "path":{
                     "type":"PathPrefix",
                     "value":"/cat"
                  },
                  "headers":[
                     {
                        "type":"Exact",
                        "name":"X-username",
                        "value":""
                     }
                  ],
                  "method":"GET"
               },
               {
                  "path":{
                     "type":"PathPrefix",
                     "value":"/cat"
                  },
                  "method":"POST"
               },
               {
                  "path":{
                     "type":"PathPrefix",
                     "value":"/dog"
                  },
                  "method":"GET"
               }
            ],
            "backendRefs":[
               {
                  "name":"myservice.myns.svc",
                  "port":80
               }
            ]
         }
      ]
   },
   "status":{
      "parents":null
   }
}
eguzki commented 2 years ago

Missing some (basic) doc at README.md and /doc/generate-gatewayapi-httproute.md