From 5946f1333380bdd8a7e18abd404ff102110195fb Mon Sep 17 00:00:00 2001 From: Jasmin Gacic Date: Mon, 4 Apr 2022 21:15:20 +0000 Subject: [PATCH 01/10] added serveral endpoints Signed-off-by: Jasmin Gacic --- server/.openapi-generator/FILES | 5 + server/Dockerfile | 22 +- server/README.md | 16 +- server/api/openapi.yaml | 246 ++++++++++++++++++-- server/go.mod | 13 +- server/go.sum | 30 ++- server/go/api.go | 50 ++-- server/go/api_apis.go | 53 ++--- server/go/api_apis_service.go | 16 -- server/go/api_apis_service_impl.go | 29 ++- server/go/api_fleets.go | 24 ++ server/go/api_fleets_service.go | 4 + server/go/api_services_service.go | 14 -- server/go/api_services_service_impl.go | 15 +- server/go/api_static_routes.go | 122 ++++++++++ server/go/api_static_routes_service_impl.go | 68 ++++++ server/go/helpers.go | 2 +- server/go/model_api_item.go | 10 +- server/go/model_api_item_fleet.go | 3 +- server/go/model_api_item_service.go | 3 +- server/go/model_envoy_fleet_item.go | 10 +- server/go/model_service_item.go | 11 +- server/go/model_service_port_item.go | 53 +++++ server/go/model_static_route_item.go | 44 ++++ server/go/model_static_route_item_fleet.go | 44 ++++ server/go/routers.go | 10 +- server/kusk/client.go | 26 ++- server/main.go | 4 + 28 files changed, 798 insertions(+), 149 deletions(-) create mode 100644 server/go/api_static_routes.go create mode 100644 server/go/api_static_routes_service_impl.go create mode 100644 server/go/model_service_port_item.go create mode 100644 server/go/model_static_route_item.go create mode 100644 server/go/model_static_route_item_fleet.go diff --git a/server/.openapi-generator/FILES b/server/.openapi-generator/FILES index 79bd3e3..90d0d30 100644 --- a/server/.openapi-generator/FILES +++ b/server/.openapi-generator/FILES @@ -8,6 +8,8 @@ go/api_apis_service.go go/api_fleets.go go/api_services.go go/api_services_service.go +go/api_static_routes.go +go/api_static_routes_service.go go/error.go go/helpers.go go/impl.go @@ -17,4 +19,7 @@ go/model_api_item_fleet.go go/model_api_item_service.go go/model_envoy_fleet_item.go go/model_service_item.go +go/model_service_port_item.go +go/model_static_route_item.go +go/model_static_route_item_fleet.go go/routers.go diff --git a/server/Dockerfile b/server/Dockerfile index b52ca96..e1baa3a 100644 --- a/server/Dockerfile +++ b/server/Dockerfile @@ -1,18 +1,14 @@ -FROM golang:1.17 AS build +FROM golang:1.10 AS build WORKDIR /go/src -# Copy `go.mod` for definitions and `go.sum` to invalidate the next layer -# in case of a change in the dependencies -COPY go.mod go.sum ./ -# Download dependencies -RUN go mod download +COPY go ./go +COPY main.go . -COPY . . -RUN CGO_ENABLED=0 GOOS=linux go build -v -o kusk-gateway-api +ENV CGO_ENABLED=0 +RUN go get -d -v ./... + +RUN go build -a -installsuffix cgo -o openapi . FROM scratch AS runtime -COPY --from=build --chown=65532:65532 /go/src/kusk-gateway-api ./ +COPY --from=build /go/src/openapi ./ EXPOSE 8080/tcp - -USER 65532:65532 - -ENTRYPOINT ["./kusk-gateway-api"] +ENTRYPOINT ["./openapi"] diff --git a/server/README.md b/server/README.md index fe0c480..9ecf620 100644 --- a/server/README.md +++ b/server/README.md @@ -13,7 +13,7 @@ To see how to make this your own, look here: [README](https://openapi-generator.tech) - API version: 1.0.0 -- Build date: 2022-03-18T10:28:30.091Z[Etc/UTC] +- Build date: 2022-04-04T20:47:47.857Z[Etc/UTC] ### Running the server @@ -25,20 +25,10 @@ go run main.go To run the server in a docker container ``` -make build +docker build --network=host -t openapi . ``` Once image is built use ``` -make run -``` - -To run in Minikube -``` -make run-minikube -``` - -To stop the api -``` -docker-compose down +docker run --rm -it openapi ``` diff --git a/server/api/openapi.yaml b/server/api/openapi.yaml index a353e30..90bfc21 100644 --- a/server/api/openapi.yaml +++ b/server/api/openapi.yaml @@ -9,6 +9,8 @@ externalDocs: servers: - description: My local endpoint mockup url: http://localhost:4010 +- description: Testing endpoint + url: http://147.75.33.177:8080 tags: - description: Get the list of the APIs name: apis @@ -16,6 +18,8 @@ tags: name: services - description: Get the list of all envoy fleets name: fleets +- description: Get the list of all static routes + name: static routes paths: /apis: get: @@ -38,6 +42,14 @@ paths: schema: type: string style: form + - description: optional filter on namespace + explode: true + in: query + name: namespace + required: false + schema: + type: string + style: form responses: "200": content: @@ -50,7 +62,7 @@ paths: summary: Get a list of APIs tags: - apis - /apis/{namespace}/{name}": + /apis/{namespace}/{name}: get: operationId: getApi parameters: @@ -81,10 +93,9 @@ paths: summary: Get an API instance by namespace and name tags: - apis - /apis/{namespace}/{name}/rawOpenApiSpec: + /apis/{namespace}/{name}/crd: get: - description: Returns the raw OpenAPI specification - operationId: getRawOpenApiSpec + operationId: getApiCRD parameters: - explode: false in: path @@ -106,17 +117,16 @@ paths: content: application/json: schema: - type: string - description: Raw OpenAPI spec + type: object + description: returns the CRD of the API ( Raw Api Spec ) "404": - description: Raw OpenAPI spec not found - summary: Get the raw OpenAPI spec by API id + description: API CRD not found + summary: Get API CRD from cluster tags: - apis - /apis/{namespace}/{name}/postProcessedOpenApiSpec: + /apis/{namespace}/{name}/definition: get: - description: Returns the post-processed OpenAPI specification - operationId: getPostProcessedOpenApiSpec + operationId: getApiDefinition parameters: - explode: false in: path @@ -138,11 +148,11 @@ paths: content: application/json: schema: - type: string - description: Post-processed OpenAPI spec + type: object + description: API definition item "404": - description: Post-processed OpenAPI spec not found - summary: Get the post-processed OpenAPI spec by API id + description: API definition not found + summary: Get API definition ( Post-Processed version ) tags: - apis /services: @@ -262,6 +272,127 @@ paths: summary: Get details for a single envoy fleet tags: - fleets + /fleets/{namespace}/{name}/crd: + get: + operationId: getEnvoyFleetCRD + parameters: + - explode: false + in: path + name: namespace + required: true + schema: + default: default + type: string + style: simple + - explode: false + in: path + name: name + required: true + schema: + type: string + style: simple + responses: + "200": + content: + application/json: + schema: + type: object + description: Envoy fleet CRD + "404": + description: Envoy fleet CRD not found + summary: Get envoy fleet CRD + tags: + - fleets + /staticroutes: + get: + description: Returns a list of static routes + operationId: getStaticRoutes + parameters: + - description: optional filter on namespace + explode: true + in: query + name: namespace + required: false + schema: + type: string + style: form + responses: + "200": + content: + application/json: + schema: + items: + $ref: '#/components/schemas/StaticRouteItem' + type: array + description: list of static routes + summary: Get a list of static routes + tags: + - static routes + /staticroutes/{namespace}/{name}: + get: + description: Returns an object containing info about the static route corresponding + to the namespace and name + operationId: getStaticRoute + parameters: + - description: the namespace of the static route + explode: false + in: path + name: namespace + required: true + schema: + type: string + style: simple + - description: the name of the static route + explode: false + in: path + name: name + required: true + schema: + type: string + style: simple + responses: + "200": + content: + application/json: + schema: + $ref: '#/components/schemas/StaticRouteItem' + description: get static route details + "404": + description: Static Route not found by namespace-name combination + summary: Get details for a single static route + tags: + - static routes + /staticroutes/{namespace}/{name}/crd: + get: + operationId: getStaticRouteCRD + parameters: + - explode: false + in: path + name: namespace + required: true + schema: + default: default + type: string + style: simple + - explode: false + in: path + name: name + required: true + schema: + type: string + style: simple + responses: + "200": + content: + application/json: + schema: + type: object + description: Static route CRD + "404": + description: Static route CRD not found + summary: Get static route CRD + tags: + - static routes components: schemas: ApiItem: @@ -274,6 +405,7 @@ components: namespace: namespace name: name namespace: namespace + version: version properties: name: type: string @@ -283,16 +415,25 @@ components: $ref: '#/components/schemas/ApiItem_Fleet' service: $ref: '#/components/schemas/ApiItem_Service' + version: + type: string required: - fleet - name - namespace - service + - version type: object ServiceItem: example: name: name namespace: namespace + ports: + protocol: protocol + port: 6.027456183070403 + name: name + nodePort: 0.8008281904610115 + targetPort: targetPort status: available properties: name: @@ -304,13 +445,21 @@ components: type: string namespace: type: string + ports: + $ref: '#/components/schemas/ServicePortItem' required: - name - namespace + - ports - status type: object EnvoyFleetItem: example: + staticRoutes: + - name: name + namespace: namespace + - name: name + namespace: namespace apis: - name: name namespace: namespace @@ -321,9 +470,21 @@ components: services: - name: name namespace: namespace + ports: + protocol: protocol + port: 6.027456183070403 + name: name + nodePort: 0.8008281904610115 + targetPort: targetPort status: available - name: name namespace: namespace + ports: + protocol: protocol + port: 6.027456183070403 + name: name + nodePort: 0.8008281904610115 + targetPort: targetPort status: available properties: name: @@ -338,6 +499,23 @@ components: items: $ref: '#/components/schemas/ServiceItem' type: array + staticRoutes: + items: + $ref: '#/components/schemas/StaticRouteItem_Fleet' + type: array + required: + - name + - namespace + type: object + StaticRouteItem: + example: + name: name + namespace: namespace + properties: + name: + type: string + namespace: + type: string required: - name - namespace @@ -355,6 +533,44 @@ components: - name - namespace type: object + ServicePortItem: + example: + protocol: protocol + port: 6.027456183070403 + name: name + nodePort: 0.8008281904610115 + targetPort: targetPort + properties: + name: + type: string + nodePort: + type: number + port: + type: number + protocol: + type: string + targetPort: + type: string + required: + - name + - nodePort + - port + - protocol + - targetPort + type: object + StaticRouteItem_Fleet: + example: + name: name + namespace: namespace + properties: + name: + type: string + namespace: + type: string + required: + - name + - namespace + type: object ApiItem_Service: example: name: name diff --git a/server/go.mod b/server/go.mod index 49be041..77b79c1 100644 --- a/server/go.mod +++ b/server/go.mod @@ -2,16 +2,17 @@ module github.com/GIT_USER_ID/GIT_REPO_ID go 1.17 +require github.com/gorilla/mux v1.8.0 + require ( github.com/gorilla/handlers v1.5.1 - github.com/gorilla/mux v1.8.0 - github.com/kubeshop/kusk-gateway v0.0.0-alpha.2.1.4.0.20220316121026-aef038baad91 + github.com/kubeshop/kusk-gateway v1.0.0-beta2 gopkg.in/yaml.v2 v2.4.0 gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b - k8s.io/api v0.23.4 - k8s.io/apimachinery v0.23.4 - k8s.io/client-go v0.23.4 - sigs.k8s.io/controller-runtime v0.11.1 + k8s.io/api v0.23.5 + k8s.io/apimachinery v0.23.5 + k8s.io/client-go v0.23.5 + sigs.k8s.io/controller-runtime v0.11.2 ) require ( diff --git a/server/go.sum b/server/go.sum index 3dabb6b..55b307a 100644 --- a/server/go.sum +++ b/server/go.sum @@ -312,6 +312,7 @@ github.com/jstemmer/go-junit-report v0.9.1/go.mod h1:Brl9GWCQeLvo8nXZwPNNblvFj/X github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU= github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w= github.com/julienschmidt/httprouter v1.3.0/go.mod h1:JR6WtHb+2LUe8TCKY3cZOxFyyO8IZAc4RVcycCCAKdM= +github.com/kelseyhightower/envconfig v1.4.0/go.mod h1:cccZRl6mQpaq41TPp5QxidR+Sa3axMbJDNb//FQX6Gg= github.com/kisielk/errcheck v1.1.0/go.mod h1:EZBBE59ingxPouuu3KfxchcWSUPOHkagtvWXihfKN4Q= github.com/kisielk/errcheck v1.2.0/go.mod h1:/BMXB+zMLi60iA8Vv6Ksmxu/1UDYcXs4uQLJ+jE2L00= github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8= @@ -326,8 +327,8 @@ github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= -github.com/kubeshop/kusk-gateway v0.0.0-alpha.2.1.4.0.20220316121026-aef038baad91 h1:oWIjaae23Y8sGGR5oywzcTBLiRE46GZh2SpWHYAJl8o= -github.com/kubeshop/kusk-gateway v0.0.0-alpha.2.1.4.0.20220316121026-aef038baad91/go.mod h1:HuF2BQbScnABO1Hu6vFkOrqZOyx+rJ3oDoFOJmlOdH0= +github.com/kubeshop/kusk-gateway v1.0.0-beta2 h1:iN/+3b/r/HhsS2JZQZyrqjrv98UfpYj5m3W0Hlxcyu8= +github.com/kubeshop/kusk-gateway v1.0.0-beta2/go.mod h1:C9QwbwrTRoqPZwV4x7OAW/dUhdggJvRmvqW+pv7ayHQ= github.com/magiconair/properties v1.8.1/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ= github.com/magiconair/properties v1.8.5/go.mod h1:y3VJvCyxH9uVvJTWEGAELF3aiYNyPKd5NZ3oSwXrF60= github.com/mailru/easyjson v0.0.0-20190614124828-94de47d64c63/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc= @@ -940,22 +941,26 @@ honnef.co/go/tools v0.0.1-2020.1.3/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9 honnef.co/go/tools v0.0.1-2020.1.4/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k= k8s.io/api v0.23.0/go.mod h1:8wmDdLBHBNxtOIytwLstXt5E9PddnZb0GaMcqsvDBpg= k8s.io/api v0.23.1/go.mod h1:WfXnOnwSqNtG62Y1CdjoMxh7r7u9QXGCkA1u0na2jgo= -k8s.io/api v0.23.4 h1:85gnfXQOWbJa1SiWGpE9EEtHs0UVvDyIsSMpEtl2D4E= -k8s.io/api v0.23.4/go.mod h1:i77F4JfyNNrhOjZF7OwwNJS5Y1S9dpwvb9iYRYRczfI= -k8s.io/apiextensions-apiserver v0.23.0 h1:uii8BYmHYiT2ZTAJxmvc3X8UhNYMxl2A0z0Xq3Pm+WY= +k8s.io/api v0.23.5 h1:zno3LUiMubxD/V1Zw3ijyKO3wxrhbUF1Ck+VjBvfaoA= +k8s.io/api v0.23.5/go.mod h1:Na4XuKng8PXJ2JsploYYrivXrINeTaycCGcYgF91Xm8= k8s.io/apiextensions-apiserver v0.23.0/go.mod h1:xIFAEEDlAZgpVBl/1VSjGDmLoXAWRG40+GsWhKhAxY4= +k8s.io/apiextensions-apiserver v0.23.5 h1:5SKzdXyvIJKu+zbfPc3kCbWpbxi+O+zdmAJBm26UJqI= +k8s.io/apiextensions-apiserver v0.23.5/go.mod h1:ntcPWNXS8ZPKN+zTXuzYMeg731CP0heCTl6gYBxLcuQ= k8s.io/apimachinery v0.23.0/go.mod h1:fFCTTBKvKcwTPFzjlcxp91uPFZr+JA0FubU4fLzzFYc= k8s.io/apimachinery v0.23.1/go.mod h1:SADt2Kl8/sttJ62RRsi9MIV4o8f5S3coArm0Iu3fBno= -k8s.io/apimachinery v0.23.4 h1:fhnuMd/xUL3Cjfl64j5ULKZ1/J9n8NuQEgNL+WXWfdM= -k8s.io/apimachinery v0.23.4/go.mod h1:BEuFMMBaIbcOqVIJqNZJXGFTP4W6AycEpb5+m/97hrM= +k8s.io/apimachinery v0.23.5 h1:Va7dwhp8wgkUPWsEXk6XglXWU4IKYLKNlv8VkX7SDM0= +k8s.io/apimachinery v0.23.5/go.mod h1:BEuFMMBaIbcOqVIJqNZJXGFTP4W6AycEpb5+m/97hrM= k8s.io/apiserver v0.23.0/go.mod h1:Cec35u/9zAepDPPFyT+UMrgqOCjgJ5qtfVJDxjZYmt4= +k8s.io/apiserver v0.23.5/go.mod h1:7wvMtGJ42VRxzgVI7jkbKvMbuCbVbgsWFT7RyXiRNTw= k8s.io/client-go v0.23.0/go.mod h1:hrDnpnK1mSr65lHHcUuIZIXDgEbzc7/683c6hyG4jTA= k8s.io/client-go v0.23.1/go.mod h1:6QSI8fEuqD4zgFK0xbdwfB/PthBsIxCJMa3s17WlcO0= -k8s.io/client-go v0.23.4 h1:YVWvPeerA2gpUudLelvsolzH7c2sFoXXR5wM/sWqNFU= -k8s.io/client-go v0.23.4/go.mod h1:PKnIL4pqLuvYUK1WU7RLTMYKPiIh7MYShLshtRY9cj0= +k8s.io/client-go v0.23.5 h1:zUXHmEuqx0RY4+CsnkOn5l0GU+skkRXKGJrhmE2SLd8= +k8s.io/client-go v0.23.5/go.mod h1:flkeinTO1CirYgzMPRWxUCnV0G4Fbu2vLhYCObnt/r4= k8s.io/code-generator v0.23.0/go.mod h1:vQvOhDXhuzqiVfM/YHp+dmg10WDZCchJVObc9MvowsE= -k8s.io/component-base v0.23.0 h1:UAnyzjvVZ2ZR1lF35YwtNY6VMN94WtOnArcXBu34es8= +k8s.io/code-generator v0.23.5/go.mod h1:S0Q1JVA+kSzTI1oUvbKAxZY/DYbA/ZUb4Uknog12ETk= k8s.io/component-base v0.23.0/go.mod h1:DHH5uiFvLC1edCpvcTDV++NKULdYYU6pR9Tt3HIKMKI= +k8s.io/component-base v0.23.5 h1:8qgP5R6jG1BBSXmRYW+dsmitIrpk8F/fPEvgDenMCCE= +k8s.io/component-base v0.23.5/go.mod h1:c5Nq44KZyt1aLl0IpHX82fhsn84Sb0jjzwjpcA42bY0= k8s.io/gengo v0.0.0-20210813121822-485abfe95c7c/go.mod h1:FiNAH4ZV3gBg2Kwh89tzAEV2be7d5xI0vBa/VySYy3E= k8s.io/klog/v2 v2.0.0/go.mod h1:PBfzABfn139FHAV07az/IF9Wp1bkk3vpT2XSJ76fSDE= k8s.io/klog/v2 v2.2.0/go.mod h1:Od+F08eJP+W3HUb4pSrPpgp9DGU4GzlpG/TmITuYh/Y= @@ -971,9 +976,10 @@ rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8 rsc.io/quote/v3 v3.1.0/go.mod h1:yEA65RcK8LyAZtP9Kv3t0HmxON59tX3rD+tICJqUlj0= rsc.io/sampler v1.3.0/go.mod h1:T1hPZKmBbMNahiBKFy5HrXp6adAjACjK9JXDnKaTXpA= sigs.k8s.io/apiserver-network-proxy/konnectivity-client v0.0.25/go.mod h1:Mlj9PNLmG9bZ6BHFwFKDo5afkpWyUISkb9Me0GnK66I= +sigs.k8s.io/apiserver-network-proxy/konnectivity-client v0.0.30/go.mod h1:fEO7lRTdivWO2qYVCVG7dEADOMo/MLDCVr8So2g88Uw= sigs.k8s.io/controller-runtime v0.11.0/go.mod h1:KKwLiTooNGu+JmLZGn9Sl3Gjmfj66eMbCQznLP5zcqA= -sigs.k8s.io/controller-runtime v0.11.1 h1:7YIHT2QnHJArj/dk9aUkYhfqfK5cIxPOX5gPECfdZLU= -sigs.k8s.io/controller-runtime v0.11.1/go.mod h1:KKwLiTooNGu+JmLZGn9Sl3Gjmfj66eMbCQznLP5zcqA= +sigs.k8s.io/controller-runtime v0.11.2 h1:H5GTxQl0Mc9UjRJhORusqfJCIjBO8UtUxGggCwL1rLA= +sigs.k8s.io/controller-runtime v0.11.2/go.mod h1:P6QCzrEjLaZGqHsfd+os7JQ+WFZhvB8MRFsn4dWF7O4= sigs.k8s.io/json v0.0.0-20211020170558-c049b76a60c6 h1:fD1pz4yfdADVNfFmcP2aBEtudwUQ1AlLnRBALr33v3s= sigs.k8s.io/json v0.0.0-20211020170558-c049b76a60c6/go.mod h1:p4QtZmO4uMYipTQNzagwnNoseA6OxSUutVw05NhYDRs= sigs.k8s.io/structured-merge-diff/v4 v4.0.2/go.mod h1:bJZC9H9iH24zzfZ/41RGcq60oK1F7G282QMXDPYydCw= diff --git a/server/go/api.go b/server/go/api.go index 4acdd16..fc87515 100644 --- a/server/go/api.go +++ b/server/go/api.go @@ -14,57 +14,81 @@ import ( "net/http" ) + + // ApisApiRouter defines the required methods for binding the api requests to a responses for the ApisApi // The ApisApiRouter implementation should parse necessary information from the http request, // pass the data to a ApisApiServicer to perform the required actions, then write the service results to the http response. -type ApisApiRouter interface { +type ApisApiRouter interface { GetApi(http.ResponseWriter, *http.Request) + GetApiCRD(http.ResponseWriter, *http.Request) + GetApiDefinition(http.ResponseWriter, *http.Request) GetApis(http.ResponseWriter, *http.Request) - GetPostProcessedOpenApiSpec(http.ResponseWriter, *http.Request) - GetRawOpenApiSpec(http.ResponseWriter, *http.Request) } - // FleetsApiRouter defines the required methods for binding the api requests to a responses for the FleetsApi // The FleetsApiRouter implementation should parse necessary information from the http request, // pass the data to a FleetsApiServicer to perform the required actions, then write the service results to the http response. -type FleetsApiRouter interface { +type FleetsApiRouter interface { GetEnvoyFleet(http.ResponseWriter, *http.Request) + GetEnvoyFleetCRD(http.ResponseWriter, *http.Request) GetEnvoyFleets(http.ResponseWriter, *http.Request) } - // ServicesApiRouter defines the required methods for binding the api requests to a responses for the ServicesApi // The ServicesApiRouter implementation should parse necessary information from the http request, // pass the data to a ServicesApiServicer to perform the required actions, then write the service results to the http response. -type ServicesApiRouter interface { +type ServicesApiRouter interface { GetService(http.ResponseWriter, *http.Request) GetServices(http.ResponseWriter, *http.Request) } +// StaticRoutesApiRouter defines the required methods for binding the api requests to a responses for the StaticRoutesApi +// The StaticRoutesApiRouter implementation should parse necessary information from the http request, +// pass the data to a StaticRoutesApiServicer to perform the required actions, then write the service results to the http response. +type StaticRoutesApiRouter interface { + GetStaticRoute(http.ResponseWriter, *http.Request) + GetStaticRouteCRD(http.ResponseWriter, *http.Request) + GetStaticRoutes(http.ResponseWriter, *http.Request) +} + // ApisApiServicer defines the api actions for the ApisApi service // This interface intended to stay up to date with the openapi yaml used to generate it, // while the service implementation can ignored with the .openapi-generator-ignore file // and updated with the logic required for the API. -type ApisApiServicer interface { +type ApisApiServicer interface { GetApi(context.Context, string, string) (ImplResponse, error) - GetApis(context.Context, string, string) (ImplResponse, error) - GetPostProcessedOpenApiSpec(context.Context, string, string) (ImplResponse, error) - GetRawOpenApiSpec(context.Context, string, string) (ImplResponse, error) + GetApiCRD(context.Context, string, string) (ImplResponse, error) + GetApiDefinition(context.Context, string, string) (ImplResponse, error) + GetApis(context.Context, string, string, string) (ImplResponse, error) } + // FleetsApiServicer defines the api actions for the FleetsApi service // This interface intended to stay up to date with the openapi yaml used to generate it, // while the service implementation can ignored with the .openapi-generator-ignore file // and updated with the logic required for the API. -type FleetsApiServicer interface { +type FleetsApiServicer interface { GetEnvoyFleet(context.Context, string, string) (ImplResponse, error) + GetEnvoyFleetCRD(context.Context, string, string) (ImplResponse, error) GetEnvoyFleets(context.Context, string) (ImplResponse, error) } + // ServicesApiServicer defines the api actions for the ServicesApi service // This interface intended to stay up to date with the openapi yaml used to generate it, // while the service implementation can ignored with the .openapi-generator-ignore file // and updated with the logic required for the API. -type ServicesApiServicer interface { +type ServicesApiServicer interface { GetService(context.Context, string, string) (ImplResponse, error) GetServices(context.Context, string) (ImplResponse, error) } + + +// StaticRoutesApiServicer defines the api actions for the StaticRoutesApi service +// This interface intended to stay up to date with the openapi yaml used to generate it, +// while the service implementation can ignored with the .openapi-generator-ignore file +// and updated with the logic required for the API. +type StaticRoutesApiServicer interface { + GetStaticRoute(context.Context, string, string) (ImplResponse, error) + GetStaticRouteCRD(context.Context, string, string) (ImplResponse, error) + GetStaticRoutes(context.Context, string) (ImplResponse, error) +} diff --git a/server/go/api_apis.go b/server/go/api_apis.go index f343ba1..b8cd64f 100644 --- a/server/go/api_apis.go +++ b/server/go/api_apis.go @@ -56,22 +56,22 @@ func (c *ApisApiController) Routes() Routes { c.GetApi, }, { - "GetApis", + "GetApiCRD", strings.ToUpper("Get"), - "/apis", - c.GetApis, + "/apis/{namespace}/{name}/crd", + c.GetApiCRD, }, { - "GetPostProcessedOpenApiSpec", + "GetApiDefinition", strings.ToUpper("Get"), - "/apis/{namespace}/{name}/postProcessedOpenApiSpec", - c.GetPostProcessedOpenApiSpec, + "/apis/{namespace}/{name}/definition", + c.GetApiDefinition, }, { - "GetRawOpenApiSpec", + "GetApis", strings.ToUpper("Get"), - "/apis/{namespace}/{name}/rawOpenApiSpec", - c.GetRawOpenApiSpec, + "/apis", + c.GetApis, }, } } @@ -94,12 +94,14 @@ func (c *ApisApiController) GetApi(w http.ResponseWriter, r *http.Request) { } -// GetApis - Get a list of APIs -func (c *ApisApiController) GetApis(w http.ResponseWriter, r *http.Request) { - query := r.URL.Query() - fleetnameParam := query.Get("fleetname") - fleetnamespaceParam := query.Get("fleetnamespace") - result, err := c.service.GetApis(r.Context(), fleetnameParam, fleetnamespaceParam) +// GetApiCRD - Get API CRD from cluster +func (c *ApisApiController) GetApiCRD(w http.ResponseWriter, r *http.Request) { + params := mux.Vars(r) + namespaceParam := params["namespace"] + + nameParam := params["name"] + + result, err := c.service.GetApiCRD(r.Context(), namespaceParam, nameParam) // If an error occurred, encode the error with the status code if err != nil { c.errorHandler(w, r, err, &result) @@ -110,14 +112,14 @@ func (c *ApisApiController) GetApis(w http.ResponseWriter, r *http.Request) { } -// GetPostProcessedOpenApiSpec - Get the post-processed OpenAPI spec by API id -func (c *ApisApiController) GetPostProcessedOpenApiSpec(w http.ResponseWriter, r *http.Request) { +// GetApiDefinition - Get API definition ( Post-Processed version ) +func (c *ApisApiController) GetApiDefinition(w http.ResponseWriter, r *http.Request) { params := mux.Vars(r) namespaceParam := params["namespace"] nameParam := params["name"] - result, err := c.service.GetPostProcessedOpenApiSpec(r.Context(), namespaceParam, nameParam) + result, err := c.service.GetApiDefinition(r.Context(), namespaceParam, nameParam) // If an error occurred, encode the error with the status code if err != nil { c.errorHandler(w, r, err, &result) @@ -128,14 +130,13 @@ func (c *ApisApiController) GetPostProcessedOpenApiSpec(w http.ResponseWriter, r } -// GetRawOpenApiSpec - Get the raw OpenAPI spec by API id -func (c *ApisApiController) GetRawOpenApiSpec(w http.ResponseWriter, r *http.Request) { - params := mux.Vars(r) - namespaceParam := params["namespace"] - - nameParam := params["name"] - - result, err := c.service.GetRawOpenApiSpec(r.Context(), namespaceParam, nameParam) +// GetApis - Get a list of APIs +func (c *ApisApiController) GetApis(w http.ResponseWriter, r *http.Request) { + query := r.URL.Query() + fleetnameParam := query.Get("fleetname") + fleetnamespaceParam := query.Get("fleetnamespace") + namespaceParam := query.Get("namespace") + result, err := c.service.GetApis(r.Context(), fleetnameParam, fleetnamespaceParam, namespaceParam) // If an error occurred, encode the error with the status code if err != nil { c.errorHandler(w, r, err, &result) diff --git a/server/go/api_apis_service.go b/server/go/api_apis_service.go index 6a0bc92..f49f899 100644 --- a/server/go/api_apis_service.go +++ b/server/go/api_apis_service.go @@ -8,19 +8,3 @@ */ package openapi - -import ( - kusk "github.com/GIT_USER_ID/GIT_REPO_ID/kusk" -) - -// ApisApiService is a service that implements the logic for the ApisApiServicer -// This service should implement the business logic for every endpoint for the ApisApi API. -// Include any external packages or services that will be required by this service. -type ApisApiService struct { - kuskClient kusk.Client -} - -// NewApisApiService creates a default api service -func NewApisApiService(kuskClient kusk.Client) ApisApiServicer { - return &ApisApiService{kuskClient: kuskClient} -} diff --git a/server/go/api_apis_service_impl.go b/server/go/api_apis_service_impl.go index e1adaa7..706f168 100644 --- a/server/go/api_apis_service_impl.go +++ b/server/go/api_apis_service_impl.go @@ -14,6 +14,7 @@ import ( "net/http" "strings" + kusk "github.com/GIT_USER_ID/GIT_REPO_ID/kusk" "github.com/GIT_USER_ID/GIT_REPO_ID/util" "github.com/kubeshop/kusk-gateway/api/v1alpha1" kuskv1 "github.com/kubeshop/kusk-gateway/api/v1alpha1" @@ -21,12 +22,24 @@ import ( "gopkg.in/yaml.v2" ) +// ApisApiService is a service that implements the logic for the ApisApiServicer +// This service should implement the business logic for every endpoint for the ApisApi API. +// Include any external packages or services that will be required by this service. +type ApisApiService struct { + kuskClient kusk.Client +} + +// NewApisApiService creates a default api service +func NewApisApiService(kuskClient kusk.Client) ApisApiServicer { + return &ApisApiService{kuskClient: kuskClient} +} + // GetApis - Get a list of APIs -func (s *ApisApiService) GetApis(ctx context.Context, fleetname string, fleetnamespace string) (ImplResponse, error) { +func (s *ApisApiService) GetApis(ctx context.Context, namespace string, fleetname string, fleetnamespace string) (ImplResponse, error) { apis := &kuskv1.APIList{} var err error if fleetname == "" { - apis, err = s.kuskClient.GetApis() + apis, err = s.kuskClient.GetApis(namespace) if err != nil { return Response(http.StatusInternalServerError, err), err } @@ -51,8 +64,18 @@ func (s *ApisApiService) GetApi(ctx context.Context, namespace string, name stri return Response(http.StatusOK, s.convertAPICRDtoAPIModel(api)), nil } +// GetApiCRD - Get API CRD from cluster +func (s *ApisApiService) GetApiCRD(ctx context.Context, namespace string, name string) (ImplResponse, error) { + api, err := s.kuskClient.GetApi(namespace, name) + if err != nil { + return Response(http.StatusInternalServerError, err), err + } + + return Response(http.StatusOK, api), nil +} + // GetPostProcessedOpenApiSpec - Get the post-processed OpenAPI spec by API id -func (s *ApisApiService) GetRawOpenApiSpec(ctx context.Context, namespace string, name string) (ImplResponse, error) { +func (s *ApisApiService) GetApiDefinition(ctx context.Context, namespace string, name string) (ImplResponse, error) { api, err := s.kuskClient.GetApi(namespace, name) if err != nil { return Response(http.StatusInternalServerError, err), err diff --git a/server/go/api_fleets.go b/server/go/api_fleets.go index 08f3cd8..5c7c40b 100644 --- a/server/go/api_fleets.go +++ b/server/go/api_fleets.go @@ -55,6 +55,12 @@ func (c *FleetsApiController) Routes() Routes { "/fleets/{namespace}/{name}", c.GetEnvoyFleet, }, + { + "GetEnvoyFleetCRD", + strings.ToUpper("Get"), + "/fleets/{namespace}/{name}/crd", + c.GetEnvoyFleetCRD, + }, { "GetEnvoyFleets", strings.ToUpper("Get"), @@ -82,6 +88,24 @@ func (c *FleetsApiController) GetEnvoyFleet(w http.ResponseWriter, r *http.Reque } +// GetEnvoyFleetCRD - Get envoy fleet CRD +func (c *FleetsApiController) GetEnvoyFleetCRD(w http.ResponseWriter, r *http.Request) { + params := mux.Vars(r) + namespaceParam := params["namespace"] + + nameParam := params["name"] + + result, err := c.service.GetEnvoyFleetCRD(r.Context(), namespaceParam, nameParam) + // If an error occurred, encode the error with the status code + if err != nil { + c.errorHandler(w, r, err, &result) + return + } + // If no error, encode the body and the result code + EncodeJSONResponse(result.Body, &result.Code, w) + +} + // GetEnvoyFleets - Get a list of envoy fleets func (c *FleetsApiController) GetEnvoyFleets(w http.ResponseWriter, r *http.Request) { query := r.URL.Query() diff --git a/server/go/api_fleets_service.go b/server/go/api_fleets_service.go index 2280c9f..79b6367 100644 --- a/server/go/api_fleets_service.go +++ b/server/go/api_fleets_service.go @@ -46,6 +46,10 @@ func (s *FleetsApiService) GetEnvoyFleet(ctx context.Context, namespace string, return Response(http.StatusOK, s.convertEnvoyFleetCRDtoEnvoyFleetModel(fleet)), nil } +func (s *FleetsApiService) GetEnvoyFleetCRD(ctx context.Context, namespace string, name string) (ImplResponse, error) { + return Response(http.StatusOK, nil), nil +} + // GetEnvoyFleets - Get a list of envoy fleets func (s *FleetsApiService) GetEnvoyFleets(ctx context.Context, namespace string) (ImplResponse, error) { fleets, err := s.kuskClient.GetEnvoyFleets() diff --git a/server/go/api_services_service.go b/server/go/api_services_service.go index f1a6ad1..f49f899 100644 --- a/server/go/api_services_service.go +++ b/server/go/api_services_service.go @@ -8,17 +8,3 @@ */ package openapi - -import kusk "github.com/GIT_USER_ID/GIT_REPO_ID/kusk" - -// ServicesApiService is a service that implements the logic for the ServicesApiServicer -// This service should implement the business logic for every endpoint for the ServicesApi API. -// Include any external packages or services that will be required by this service. -type ServicesApiService struct { - kuskClient kusk.Client -} - -// NewServicesApiService creates a default api service -func NewServicesApiService(kuskClient kusk.Client) ServicesApiServicer { - return &ServicesApiService{kuskClient: kuskClient} -} diff --git a/server/go/api_services_service_impl.go b/server/go/api_services_service_impl.go index 790b268..301f7be 100644 --- a/server/go/api_services_service_impl.go +++ b/server/go/api_services_service_impl.go @@ -14,9 +14,22 @@ import ( "net/http" "strings" + kusk "github.com/GIT_USER_ID/GIT_REPO_ID/kusk" "github.com/kubeshop/kusk-gateway/pkg/spec" ) +// ServicesApiService is a service that implements the logic for the ServicesApiServicer +// This service should implement the business logic for every endpoint for the ServicesApi API. +// Include any external packages or services that will be required by this service. +type ServicesApiService struct { + kuskClient kusk.Client +} + +// NewServicesApiService creates a default api service +func NewServicesApiService(kuskClient kusk.Client) ServicesApiServicer { + return &ServicesApiService{kuskClient: kuskClient} +} + // GetService - Get details for a single service func (s *ServicesApiService) GetService(ctx context.Context, namespace string, name string) (ImplResponse, error) { svc, err := s.kuskClient.GetSvc(namespace, name) @@ -33,7 +46,7 @@ func (s *ServicesApiService) GetService(ctx context.Context, namespace string, n // GetServices - Get a list of services func (s *ServicesApiService) GetServices(ctx context.Context, namespace string) (ImplResponse, error) { - apis, err := s.kuskClient.GetApis() + apis, err := s.kuskClient.GetApis(namespace) if err != nil { return Response(http.StatusInternalServerError, err), err } diff --git a/server/go/api_static_routes.go b/server/go/api_static_routes.go new file mode 100644 index 0000000..5852260 --- /dev/null +++ b/server/go/api_static_routes.go @@ -0,0 +1,122 @@ +/* + * Kusk Gateway API + * + * This is the Kusk Gateway Management API + * + * API version: 1.0.0 + * Generated by: OpenAPI Generator (https://openapi-generator.tech) + */ + +package openapi + +import ( + "net/http" + "strings" + + "github.com/gorilla/mux" +) + +// StaticRoutesApiController binds http requests to an api service and writes the service results to the http response +type StaticRoutesApiController struct { + service StaticRoutesApiServicer + errorHandler ErrorHandler +} + +// StaticRoutesApiOption for how the controller is set up. +type StaticRoutesApiOption func(*StaticRoutesApiController) + +// WithStaticRoutesApiErrorHandler inject ErrorHandler into controller +func WithStaticRoutesApiErrorHandler(h ErrorHandler) StaticRoutesApiOption { + return func(c *StaticRoutesApiController) { + c.errorHandler = h + } +} + +// NewStaticRoutesApiController creates a default api controller +func NewStaticRoutesApiController(s StaticRoutesApiServicer, opts ...StaticRoutesApiOption) Router { + controller := &StaticRoutesApiController{ + service: s, + errorHandler: DefaultErrorHandler, + } + + for _, opt := range opts { + opt(controller) + } + + return controller +} + +// Routes returns all of the api route for the StaticRoutesApiController +func (c *StaticRoutesApiController) Routes() Routes { + return Routes{ + { + "GetStaticRoute", + strings.ToUpper("Get"), + "/staticroutes/{namespace}/{name}", + c.GetStaticRoute, + }, + { + "GetStaticRouteCRD", + strings.ToUpper("Get"), + "/staticroutes/{namespace}/{name}/crd", + c.GetStaticRouteCRD, + }, + { + "GetStaticRoutes", + strings.ToUpper("Get"), + "/staticroutes", + c.GetStaticRoutes, + }, + } +} + +// GetStaticRoute - Get details for a single static route +func (c *StaticRoutesApiController) GetStaticRoute(w http.ResponseWriter, r *http.Request) { + params := mux.Vars(r) + namespaceParam := params["namespace"] + + nameParam := params["name"] + + result, err := c.service.GetStaticRoute(r.Context(), namespaceParam, nameParam) + // If an error occurred, encode the error with the status code + if err != nil { + c.errorHandler(w, r, err, &result) + return + } + // If no error, encode the body and the result code + EncodeJSONResponse(result.Body, &result.Code, w) + +} + +// GetStaticRouteCRD - Get static route CRD +func (c *StaticRoutesApiController) GetStaticRouteCRD(w http.ResponseWriter, r *http.Request) { + params := mux.Vars(r) + namespaceParam := params["namespace"] + + nameParam := params["name"] + + result, err := c.service.GetStaticRouteCRD(r.Context(), namespaceParam, nameParam) + // If an error occurred, encode the error with the status code + if err != nil { + c.errorHandler(w, r, err, &result) + return + } + // If no error, encode the body and the result code + EncodeJSONResponse(result.Body, &result.Code, w) + +} + +// GetStaticRoutes - Get a list of static routes +func (c *StaticRoutesApiController) GetStaticRoutes(w http.ResponseWriter, r *http.Request) { + query := r.URL.Query() + namespaceParam := query.Get("namespace") + result, err := c.service.GetStaticRoutes(r.Context(), namespaceParam) + // If an error occurred, encode the error with the status code + if err != nil { + c.errorHandler(w, r, err, &result) + return + } + // If no error, encode the body and the result code + EncodeJSONResponse(result.Body, &result.Code, w) + +} diff --git a/server/go/api_static_routes_service_impl.go b/server/go/api_static_routes_service_impl.go new file mode 100644 index 0000000..6214019 --- /dev/null +++ b/server/go/api_static_routes_service_impl.go @@ -0,0 +1,68 @@ +/* + * Kusk Gateway API + * + * This is the Kusk Gateway Management API + * + * API version: 1.0.0 + * Generated by: OpenAPI Generator (https://openapi-generator.tech) + */ + +package openapi + +import ( + "context" + "net/http" + + kusk "github.com/GIT_USER_ID/GIT_REPO_ID/kusk" +) + +// StaticRoutesApiService is a service that implements the logic for the StaticRoutesApiServicer +// This service should implement the business logic for every endpoint for the StaticRoutesApi API. +// Include any external packages or services that will be required by this service. +type StaticRoutesApiService struct { + kuskClient kusk.Client +} + +// NewStaticRoutesApiService creates a default api service +func NewStaticRoutesApiService(kuskClient kusk.Client) StaticRoutesApiServicer { + return &StaticRoutesApiService{kuskClient: kuskClient} +} + +// GetStaticRoute - Get details for a single static route +func (s *StaticRoutesApiService) GetStaticRoute(ctx context.Context, namespace string, name string) (ImplResponse, error) { + staticRoute, err := s.kuskClient.GetStaticRoute(namespace, name) + if err != nil { + return Response(http.StatusInternalServerError, err), err + } + return Response(http.StatusOK, StaticRouteItem{ + Name: staticRoute.Name, + Namespace: staticRoute.Namespace, + }), nil +} + +// GetStaticRouteCRD - Get static route CRD +func (s *StaticRoutesApiService) GetStaticRouteCRD(ctx context.Context, namespace string, name string) (ImplResponse, error) { + staticRoute, err := s.kuskClient.GetStaticRoute(namespace, name) + if err != nil { + return Response(http.StatusInternalServerError, err), err + } + + return Response(http.StatusOK, staticRoute), nil +} + +// GetStaticRoutes - Get a list of static routes +func (s *StaticRoutesApiService) GetStaticRoutes(ctx context.Context, namespace string) (ImplResponse, error) { + staticRoutes, err := s.kuskClient.GetStaticRoutes(namespace) + if err != nil { + return Response(http.StatusInternalServerError, err), err + } + + toReturn := []StaticRouteItem{} + for _, sr := range staticRoutes.Items { + toReturn = append(toReturn, StaticRouteItem{ + Name: sr.Name, + Namespace: sr.Namespace, + }) + } + return Response(http.StatusOK, toReturn), nil +} diff --git a/server/go/helpers.go b/server/go/helpers.go index e67a44c..f7ca0cc 100644 --- a/server/go/helpers.go +++ b/server/go/helpers.go @@ -15,7 +15,7 @@ import ( // Response return a ImplResponse struct filled func Response(code int, body interface{}) ImplResponse { - return ImplResponse{ + return ImplResponse { Code: code, Body: body, } diff --git a/server/go/model_api_item.go b/server/go/model_api_item.go index b0a89f6..55b5c87 100644 --- a/server/go/model_api_item.go +++ b/server/go/model_api_item.go @@ -10,6 +10,7 @@ package openapi type ApiItem struct { + Name string `json:"name"` Namespace string `json:"namespace"` @@ -17,15 +18,18 @@ type ApiItem struct { Fleet ApiItemFleet `json:"fleet"` Service ApiItemService `json:"service"` + + Version string `json:"version"` } // AssertApiItemRequired checks if the required fields are not zero-ed func AssertApiItemRequired(obj ApiItem) error { elements := map[string]interface{}{ - "name": obj.Name, + "name": obj.Name, "namespace": obj.Namespace, - "fleet": obj.Fleet, - "service": obj.Service, + "fleet": obj.Fleet, + "service": obj.Service, + "version": obj.Version, } for name, el := range elements { if isZero := IsZeroValue(el); isZero { diff --git a/server/go/model_api_item_fleet.go b/server/go/model_api_item_fleet.go index bd629f1..b7ef712 100644 --- a/server/go/model_api_item_fleet.go +++ b/server/go/model_api_item_fleet.go @@ -10,6 +10,7 @@ package openapi type ApiItemFleet struct { + Name string `json:"name"` Namespace string `json:"namespace"` @@ -18,7 +19,7 @@ type ApiItemFleet struct { // AssertApiItemFleetRequired checks if the required fields are not zero-ed func AssertApiItemFleetRequired(obj ApiItemFleet) error { elements := map[string]interface{}{ - "name": obj.Name, + "name": obj.Name, "namespace": obj.Namespace, } for name, el := range elements { diff --git a/server/go/model_api_item_service.go b/server/go/model_api_item_service.go index bcd09a8..bdd8c5a 100644 --- a/server/go/model_api_item_service.go +++ b/server/go/model_api_item_service.go @@ -10,6 +10,7 @@ package openapi type ApiItemService struct { + Name string `json:"name"` Namespace string `json:"namespace"` @@ -18,7 +19,7 @@ type ApiItemService struct { // AssertApiItemServiceRequired checks if the required fields are not zero-ed func AssertApiItemServiceRequired(obj ApiItemService) error { elements := map[string]interface{}{ - "name": obj.Name, + "name": obj.Name, "namespace": obj.Namespace, } for name, el := range elements { diff --git a/server/go/model_envoy_fleet_item.go b/server/go/model_envoy_fleet_item.go index 6c0ea55..2082700 100644 --- a/server/go/model_envoy_fleet_item.go +++ b/server/go/model_envoy_fleet_item.go @@ -10,6 +10,7 @@ package openapi type EnvoyFleetItem struct { + Name string `json:"name"` Namespace string `json:"namespace"` @@ -17,12 +18,14 @@ type EnvoyFleetItem struct { Apis []ApiItemFleet `json:"apis,omitempty"` Services []ServiceItem `json:"services,omitempty"` + + StaticRoutes []StaticRouteItemFleet `json:"staticRoutes,omitempty"` } // AssertEnvoyFleetItemRequired checks if the required fields are not zero-ed func AssertEnvoyFleetItemRequired(obj EnvoyFleetItem) error { elements := map[string]interface{}{ - "name": obj.Name, + "name": obj.Name, "namespace": obj.Namespace, } for name, el := range elements { @@ -41,6 +44,11 @@ func AssertEnvoyFleetItemRequired(obj EnvoyFleetItem) error { return err } } + for _, el := range obj.StaticRoutes { + if err := AssertStaticRouteItemFleetRequired(el); err != nil { + return err + } + } return nil } diff --git a/server/go/model_service_item.go b/server/go/model_service_item.go index 10240a0..ac3342d 100644 --- a/server/go/model_service_item.go +++ b/server/go/model_service_item.go @@ -10,19 +10,23 @@ package openapi type ServiceItem struct { + Name string `json:"name"` Status string `json:"status"` Namespace string `json:"namespace"` + + Ports ServicePortItem `json:"ports"` } // AssertServiceItemRequired checks if the required fields are not zero-ed func AssertServiceItemRequired(obj ServiceItem) error { elements := map[string]interface{}{ - "name": obj.Name, - "status": obj.Status, + "name": obj.Name, + "status": obj.Status, "namespace": obj.Namespace, + "ports": obj.Ports, } for name, el := range elements { if isZero := IsZeroValue(el); isZero { @@ -30,6 +34,9 @@ func AssertServiceItemRequired(obj ServiceItem) error { } } + if err := AssertServicePortItemRequired(obj.Ports); err != nil { + return err + } return nil } diff --git a/server/go/model_service_port_item.go b/server/go/model_service_port_item.go new file mode 100644 index 0000000..e151d74 --- /dev/null +++ b/server/go/model_service_port_item.go @@ -0,0 +1,53 @@ +/* + * Kusk Gateway API + * + * This is the Kusk Gateway Management API + * + * API version: 1.0.0 + * Generated by: OpenAPI Generator (https://openapi-generator.tech) + */ + +package openapi + +type ServicePortItem struct { + + Name string `json:"name"` + + NodePort float32 `json:"nodePort"` + + Port float32 `json:"port"` + + Protocol string `json:"protocol"` + + TargetPort string `json:"targetPort"` +} + +// AssertServicePortItemRequired checks if the required fields are not zero-ed +func AssertServicePortItemRequired(obj ServicePortItem) error { + elements := map[string]interface{}{ + "name": obj.Name, + "nodePort": obj.NodePort, + "port": obj.Port, + "protocol": obj.Protocol, + "targetPort": obj.TargetPort, + } + for name, el := range elements { + if isZero := IsZeroValue(el); isZero { + return &RequiredError{Field: name} + } + } + + return nil +} + +// AssertRecurseServicePortItemRequired recursively checks if required fields are not zero-ed in a nested slice. +// Accepts only nested slice of ServicePortItem (e.g. [][]ServicePortItem), otherwise ErrTypeAssertionError is thrown. +func AssertRecurseServicePortItemRequired(objSlice interface{}) error { + return AssertRecurseInterfaceRequired(objSlice, func(obj interface{}) error { + aServicePortItem, ok := obj.(ServicePortItem) + if !ok { + return ErrTypeAssertionError + } + return AssertServicePortItemRequired(aServicePortItem) + }) +} diff --git a/server/go/model_static_route_item.go b/server/go/model_static_route_item.go new file mode 100644 index 0000000..2ed1b5b --- /dev/null +++ b/server/go/model_static_route_item.go @@ -0,0 +1,44 @@ +/* + * Kusk Gateway API + * + * This is the Kusk Gateway Management API + * + * API version: 1.0.0 + * Generated by: OpenAPI Generator (https://openapi-generator.tech) + */ + +package openapi + +type StaticRouteItem struct { + + Name string `json:"name"` + + Namespace string `json:"namespace"` +} + +// AssertStaticRouteItemRequired checks if the required fields are not zero-ed +func AssertStaticRouteItemRequired(obj StaticRouteItem) error { + elements := map[string]interface{}{ + "name": obj.Name, + "namespace": obj.Namespace, + } + for name, el := range elements { + if isZero := IsZeroValue(el); isZero { + return &RequiredError{Field: name} + } + } + + return nil +} + +// AssertRecurseStaticRouteItemRequired recursively checks if required fields are not zero-ed in a nested slice. +// Accepts only nested slice of StaticRouteItem (e.g. [][]StaticRouteItem), otherwise ErrTypeAssertionError is thrown. +func AssertRecurseStaticRouteItemRequired(objSlice interface{}) error { + return AssertRecurseInterfaceRequired(objSlice, func(obj interface{}) error { + aStaticRouteItem, ok := obj.(StaticRouteItem) + if !ok { + return ErrTypeAssertionError + } + return AssertStaticRouteItemRequired(aStaticRouteItem) + }) +} diff --git a/server/go/model_static_route_item_fleet.go b/server/go/model_static_route_item_fleet.go new file mode 100644 index 0000000..33a129c --- /dev/null +++ b/server/go/model_static_route_item_fleet.go @@ -0,0 +1,44 @@ +/* + * Kusk Gateway API + * + * This is the Kusk Gateway Management API + * + * API version: 1.0.0 + * Generated by: OpenAPI Generator (https://openapi-generator.tech) + */ + +package openapi + +type StaticRouteItemFleet struct { + + Name string `json:"name"` + + Namespace string `json:"namespace"` +} + +// AssertStaticRouteItemFleetRequired checks if the required fields are not zero-ed +func AssertStaticRouteItemFleetRequired(obj StaticRouteItemFleet) error { + elements := map[string]interface{}{ + "name": obj.Name, + "namespace": obj.Namespace, + } + for name, el := range elements { + if isZero := IsZeroValue(el); isZero { + return &RequiredError{Field: name} + } + } + + return nil +} + +// AssertRecurseStaticRouteItemFleetRequired recursively checks if required fields are not zero-ed in a nested slice. +// Accepts only nested slice of StaticRouteItemFleet (e.g. [][]StaticRouteItemFleet), otherwise ErrTypeAssertionError is thrown. +func AssertRecurseStaticRouteItemFleetRequired(objSlice interface{}) error { + return AssertRecurseInterfaceRequired(objSlice, func(obj interface{}) error { + aStaticRouteItemFleet, ok := obj.(StaticRouteItemFleet) + if !ok { + return ErrTypeAssertionError + } + return AssertStaticRouteItemFleetRequired(aStaticRouteItemFleet) + }) +} diff --git a/server/go/routers.go b/server/go/routers.go index 79c9de2..9331a27 100644 --- a/server/go/routers.go +++ b/server/go/routers.go @@ -12,8 +12,8 @@ package openapi import ( "encoding/json" "errors" - "github.com/gorilla/handlers" "github.com/gorilla/mux" + "github.com/gorilla/handlers" "io/ioutil" "mime/multipart" "net/http" @@ -24,9 +24,9 @@ import ( // A Route defines the parameters for an api endpoint type Route struct { - Name string - Method string - Pattern string + Name string + Method string + Pattern string HandlerFunc http.HandlerFunc } @@ -216,4 +216,4 @@ func parseInt32ArrayParameter(param, delim string, required bool) ([]int32, erro } return ints, nil -} +} \ No newline at end of file diff --git a/server/kusk/client.go b/server/kusk/client.go index 6fd900e..0555177 100644 --- a/server/kusk/client.go +++ b/server/kusk/client.go @@ -12,9 +12,11 @@ type Client interface { GetEnvoyFleets() (*kuskv1.EnvoyFleetList, error) GetEnvoyFleet(namespace, name string) (*kuskv1.EnvoyFleet, error) - GetApis() (*kuskv1.APIList, error) + GetApis(namespace string) (*kuskv1.APIList, error) GetApi(namespace, name string) (*kuskv1.API, error) GetApiByEnvoyFleet(fleetNamespace, fleetName string) (*kuskv1.APIList, error) + GetStaticRoute(namespace, name string) (*kuskv1.StaticRoute, error) + GetStaticRoutes(namespace string) (*kuskv1.StaticRouteList, error) GetSvc(namespace, name string) (*corev1.Service, error) } @@ -49,9 +51,9 @@ func (k *kuskClient) GetEnvoyFleet(namespace, name string) (*kuskv1.EnvoyFleet, return envoy, nil } -func (k *kuskClient) GetApis() (*kuskv1.APIList, error) { +func (k *kuskClient) GetApis(namespace string) (*kuskv1.APIList, error) { list := &kuskv1.APIList{} - if err := k.client.List(context.TODO(), list, &client.ListOptions{}); err != nil { + if err := k.client.List(context.TODO(), list, &client.ListOptions{Namespace: namespace}); err != nil { return nil, err } @@ -93,3 +95,21 @@ func (k *kuskClient) GetSvc(namespace, name string) (*corev1.Service, error) { return svc, nil } + +func (k *kuskClient) GetStaticRoute(namespace, name string) (*kuskv1.StaticRoute, error) { + staticRoute := &kuskv1.StaticRoute{} + if err := k.client.Get(context.TODO(), client.ObjectKey{Namespace: namespace, Name: name}, staticRoute); err != nil { + return nil, err + } + + return staticRoute, nil +} + +func (k *kuskClient) GetStaticRoutes(namespace string) (*kuskv1.StaticRouteList, error) { + list := &kuskv1.StaticRouteList{} + if err := k.client.List(context.TODO(), list, &client.ListOptions{}); err != nil { + return nil, err + } + + return list, nil +} diff --git a/server/main.go b/server/main.go index 47057c9..7165893 100644 --- a/server/main.go +++ b/server/main.go @@ -46,12 +46,16 @@ func main() { ServicesApiService := openapi.NewServicesApiService(kuskClient) ServicesApiController := openapi.NewServicesApiController(ServicesApiService) + StaticRouteApiService := openapi.NewStaticRoutesApiService(kuskClient) + StaticRouteApiController := openapi.NewStaticRoutesApiController(StaticRouteApiService) + ProbeController := openapi.NewProbeController() router := openapi.NewRouter( ApisApiController, FleetsApiController, ServicesApiController, + StaticRouteApiController, ProbeController, ) From d77d3e3b5a0385ffe979c9464168e47389c55366 Mon Sep 17 00:00:00 2001 From: Jasmin Gacic Date: Mon, 4 Apr 2022 21:22:08 +0000 Subject: [PATCH 02/10] reverted dockerfile Signed-off-by: Jasmin Gacic --- kgw-api.yaml | 3 ++- server/Dockerfile | 22 +++++++++++++--------- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/kgw-api.yaml b/kgw-api.yaml index ba33bc8..3f853a8 100644 --- a/kgw-api.yaml +++ b/kgw-api.yaml @@ -17,7 +17,8 @@ spec: app: kgwtest spec: containers: - - image: jasmingacic/kuskgateway-api + - image: jasmingacic/kuskgateway-api:latest + imagePullPolicy: Always name: kuskgateway-api serviceAccountName: kusk-gateway-manager --- diff --git a/server/Dockerfile b/server/Dockerfile index e1baa3a..b52ca96 100644 --- a/server/Dockerfile +++ b/server/Dockerfile @@ -1,14 +1,18 @@ -FROM golang:1.10 AS build +FROM golang:1.17 AS build WORKDIR /go/src -COPY go ./go -COPY main.go . +# Copy `go.mod` for definitions and `go.sum` to invalidate the next layer +# in case of a change in the dependencies +COPY go.mod go.sum ./ +# Download dependencies +RUN go mod download -ENV CGO_ENABLED=0 -RUN go get -d -v ./... - -RUN go build -a -installsuffix cgo -o openapi . +COPY . . +RUN CGO_ENABLED=0 GOOS=linux go build -v -o kusk-gateway-api FROM scratch AS runtime -COPY --from=build /go/src/openapi ./ +COPY --from=build --chown=65532:65532 /go/src/kusk-gateway-api ./ EXPOSE 8080/tcp -ENTRYPOINT ["./openapi"] + +USER 65532:65532 + +ENTRYPOINT ["./kusk-gateway-api"] From 216664d92d999e4a6e0472d592dd724df2d62d07 Mon Sep 17 00:00:00 2001 From: Jasmin Gacic Date: Mon, 4 Apr 2022 21:36:59 +0000 Subject: [PATCH 03/10] various fixes Signed-off-by: Jasmin Gacic --- kgw-api.yaml | 1 + server/.openapi-generator-ignore | 3 ++- server/go/api_fleets_service.go | 10 +++++++++- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/kgw-api.yaml b/kgw-api.yaml index 3f853a8..938066e 100644 --- a/kgw-api.yaml +++ b/kgw-api.yaml @@ -33,6 +33,7 @@ spec: ports: - port: 8080 targetPort: 8080 + type: LoadBalancer selector: app: kgwtest # --- diff --git a/server/.openapi-generator-ignore b/server/.openapi-generator-ignore index 121f564..bc5c6fc 100644 --- a/server/.openapi-generator-ignore +++ b/server/.openapi-generator-ignore @@ -1,4 +1,5 @@ go/api_fleets_service.go main.go go/go.mod -go/Dockerfile \ No newline at end of file +go/Dockerfile +Dockerfile \ No newline at end of file diff --git a/server/go/api_fleets_service.go b/server/go/api_fleets_service.go index 79b6367..f6c68a5 100644 --- a/server/go/api_fleets_service.go +++ b/server/go/api_fleets_service.go @@ -47,7 +47,15 @@ func (s *FleetsApiService) GetEnvoyFleet(ctx context.Context, namespace string, } func (s *FleetsApiService) GetEnvoyFleetCRD(ctx context.Context, namespace string, name string) (ImplResponse, error) { - return Response(http.StatusOK, nil), nil + fleet, err := s.kuskClient.GetEnvoyFleet(namespace, name) + + if err != nil { + if strings.Contains(err.Error(), fmt.Sprintf(`envoyfleet.gateway.kusk.io "%s" not found`, name)) { + return Response(http.StatusNotFound, err), err + } + return Response(http.StatusInternalServerError, err), err + } + return Response(http.StatusOK, fleet), nil } // GetEnvoyFleets - Get a list of envoy fleets From 1d581ce6bee9b1027830699943aa2061a297963a Mon Sep 17 00:00:00 2001 From: Jasmin Gacic Date: Mon, 4 Apr 2022 21:38:12 +0000 Subject: [PATCH 04/10] fixed test file Signed-off-by: Jasmin Gacic --- server/kusk/client_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/kusk/client_test.go b/server/kusk/client_test.go index e909684..30c649d 100644 --- a/server/kusk/client_test.go +++ b/server/kusk/client_test.go @@ -88,7 +88,7 @@ func TestGetApi(t *testing.T) { func TestGetApis(t *testing.T) { setup(t) - apis, err := testClient.GetApis() + apis, err := testClient.GetApis("default") if err != nil { t.Error(err) t.Fail() From 3fc7efa50f21de74442a360074320be9a84e9956 Mon Sep 17 00:00:00 2001 From: Jasmin Gacic Date: Mon, 4 Apr 2022 22:46:53 +0000 Subject: [PATCH 05/10] fixed tests some more Signed-off-by: Jasmin Gacic --- server/kusk/client_test.go | 47 +++++++++++++++++++++++++++++++++----- 1 file changed, 41 insertions(+), 6 deletions(-) diff --git a/server/kusk/client_test.go b/server/kusk/client_test.go index 30c649d..625a250 100644 --- a/server/kusk/client_test.go +++ b/server/kusk/client_test.go @@ -9,6 +9,8 @@ import ( kuskv1 "github.com/kubeshop/kusk-gateway/api/v1alpha1" corev1 "k8s.io/api/core/v1" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/runtime" "k8s.io/client-go/rest" "k8s.io/client-go/tools/clientcmd" @@ -20,8 +22,8 @@ var testClient Client func setup(tb testing.TB) { if _, fakeIt := os.LookupEnv("FAKE"); fakeIt { - fakeClient := fake.NewClientBuilder().Build() - testClient = NewClient(fakeClient) + + testClient = NewClient(getFakeClient()) return } k8sclient, err := getClient() @@ -88,29 +90,62 @@ func TestGetApi(t *testing.T) { func TestGetApis(t *testing.T) { setup(t) - apis, err := testClient.GetApis("default") + _, err := testClient.GetApis("default") if err != nil { t.Error(err) t.Fail() return } - fmt.Println(len(apis.Items)) } func TestGetSvc(t *testing.T) { setup(t) - svc, err := testClient.GetSvc("default", "kubernetes") + _, err := testClient.GetSvc("default", "kubernetes") if err != nil { t.Error(err) t.Fail() return } - fmt.Println(svc) +} + +func getFakeClient() client.Client { + + scheme := runtime.NewScheme() + kuskv1.AddToScheme(scheme) + corev1.AddToScheme(scheme) + + initObjects := []client.Object{ + &corev1.Service{ + ObjectMeta: metav1.ObjectMeta{ + Name: "kubernetes", + Namespace: "default", + }, + }, + &kuskv1.API{ + ObjectMeta: metav1.ObjectMeta{ + Name: "httpbin-sample", + Namespace: "default", + }, + }, + &kuskv1.EnvoyFleet{ + ObjectMeta: metav1.ObjectMeta{ + Name: "default", + Namespace: "default", + }, + }, + } + + fakeClient := fake.NewClientBuilder(). + WithScheme(scheme). + WithObjects(initObjects...). + Build() + return fakeClient } func getClient() (client.Client, error) { + fmt.Println("HERE") scheme := runtime.NewScheme() kuskv1.AddToScheme(scheme) corev1.AddToScheme(scheme) From 14e745c278387779e526b6213b57a8ffd03d9f1e Mon Sep 17 00:00:00 2001 From: Jasmin Gacic Date: Mon, 4 Apr 2022 23:09:12 +0000 Subject: [PATCH 06/10] fixed GH actions Signed-off-by: Jasmin Gacic --- .github/workflows/build.yml | 14 +++++++++----- Makefile | 2 ++ server/kusk/client_test.go | 21 ++++++++++----------- 3 files changed, 21 insertions(+), 16 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index d799502..0dd6a73 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -6,14 +6,18 @@ concurrency: on: push: - branches: [ main ] + branches: [main] pull_request: - branches: [ main ] + branches: [main] jobs: build: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 - - name: build - run: make build + - uses: actions/checkout@v2 + - name: build + run: make build + - name: Set up Go + uses: actions/setup-go@v2 + with: + go-version: 1.16 diff --git a/Makefile b/Makefile index 8e1ed7d..9bc4b2d 100644 --- a/Makefile +++ b/Makefile @@ -9,3 +9,5 @@ run: run-minikube: docker-compose -f docker-compose.yaml -f docker-compose-minikube.yaml up --build -d +test: + cd ./server && FAKE=true go test -v ./... \ No newline at end of file diff --git a/server/kusk/client_test.go b/server/kusk/client_test.go index 625a250..30c3d8a 100644 --- a/server/kusk/client_test.go +++ b/server/kusk/client_test.go @@ -76,27 +76,27 @@ func TestClientGetEnvoyFleet(t *testing.T) { } } -func TestGetApi(t *testing.T) { +func TestGetApis(t *testing.T) { setup(t) - api, err := testClient.GetApi("default", "httpbin-sample") + apis, err := testClient.GetApis("default") if err != nil { t.Error(err) t.Fail() return } - - fmt.Println(api.Spec.Spec) + fmt.Println(len(apis.Items)) } -func TestGetApis(t *testing.T) { +func TestGetApi(t *testing.T) { setup(t) - _, err := testClient.GetApis("default") + api, err := testClient.GetApi("default", "sample") if err != nil { t.Error(err) t.Fail() return } + fmt.Println(api.Spec.Spec) } func TestGetSvc(t *testing.T) { @@ -117,15 +117,15 @@ func getFakeClient() client.Client { corev1.AddToScheme(scheme) initObjects := []client.Object{ - &corev1.Service{ + &kuskv1.API{ ObjectMeta: metav1.ObjectMeta{ - Name: "kubernetes", + Name: "sample", Namespace: "default", }, }, - &kuskv1.API{ + &corev1.Service{ ObjectMeta: metav1.ObjectMeta{ - Name: "httpbin-sample", + Name: "kubernetes", Namespace: "default", }, }, @@ -145,7 +145,6 @@ func getFakeClient() client.Client { } func getClient() (client.Client, error) { - fmt.Println("HERE") scheme := runtime.NewScheme() kuskv1.AddToScheme(scheme) corev1.AddToScheme(scheme) From eea2243bde75e9d68d9a7fc7eaa4366ff320138a Mon Sep 17 00:00:00 2001 From: Jasmin Gacic Date: Mon, 4 Apr 2022 23:14:01 +0000 Subject: [PATCH 07/10] added ports to serviceitem Signed-off-by: Jasmin Gacic --- server/go/api_services_service_impl.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/server/go/api_services_service_impl.go b/server/go/api_services_service_impl.go index 301f7be..e287faa 100644 --- a/server/go/api_services_service_impl.go +++ b/server/go/api_services_service_impl.go @@ -36,11 +36,15 @@ func (s *ServicesApiService) GetService(ctx context.Context, namespace string, n if err != nil { return Response(http.StatusInternalServerError, err), err } - + port := ServicePortItem{ + Port: float32(svc.Spec.Ports[0].Port), + Protocol: string(svc.Spec.Ports[0].Protocol), + } return Response(http.StatusOK, ServiceItem{ Name: svc.Name, Namespace: svc.Namespace, Status: "available", + Ports: port, }), nil } From f46c25ff63ce98d8caca517fbf1a4ea097bff2d2 Mon Sep 17 00:00:00 2001 From: Jasmin Gacic Date: Tue, 5 Apr 2022 02:21:35 +0000 Subject: [PATCH 08/10] extended getFleets Signed-off-by: Jasmin Gacic --- server/go/api_apis_service_impl.go | 5 ++--- server/go/api_fleets_service.go | 20 +++++++++++++++++--- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/server/go/api_apis_service_impl.go b/server/go/api_apis_service_impl.go index 706f168..7afa0b0 100644 --- a/server/go/api_apis_service_impl.go +++ b/server/go/api_apis_service_impl.go @@ -16,7 +16,6 @@ import ( kusk "github.com/GIT_USER_ID/GIT_REPO_ID/kusk" "github.com/GIT_USER_ID/GIT_REPO_ID/util" - "github.com/kubeshop/kusk-gateway/api/v1alpha1" kuskv1 "github.com/kubeshop/kusk-gateway/api/v1alpha1" "github.com/kubeshop/kusk-gateway/pkg/spec" "gopkg.in/yaml.v2" @@ -96,7 +95,7 @@ func (s *ApisApiService) GetPostProcessedOpenApiSpec(ctx context.Context, namesp return Response(http.StatusOK, string(yml)), nil } -func (s *ApisApiService) convertAPIListCRDtoAPIsModel(apis v1alpha1.APIList) []ApiItem { +func (s *ApisApiService) convertAPIListCRDtoAPIsModel(apis kuskv1.APIList) []ApiItem { toReturn := []ApiItem{} for _, api := range apis.Items { toReturn = append(toReturn, s.convertAPICRDtoAPIModel(&api)) @@ -104,7 +103,7 @@ func (s *ApisApiService) convertAPIListCRDtoAPIsModel(apis v1alpha1.APIList) []A return toReturn } -func (s *ApisApiService) convertAPICRDtoAPIModel(api *v1alpha1.API) ApiItem { +func (s *ApisApiService) convertAPICRDtoAPIModel(api *kuskv1.API) ApiItem { parser := spec.NewParser(nil) apiItem := ApiItem{ Name: api.Name, diff --git a/server/go/api_fleets_service.go b/server/go/api_fleets_service.go index f6c68a5..cd04d97 100644 --- a/server/go/api_fleets_service.go +++ b/server/go/api_fleets_service.go @@ -86,9 +86,23 @@ func (s *FleetsApiService) convertEnvoyFleetCRDtoEnvoyFleetModel(fleet *v1alpha1 }) } } + srs := []StaticRouteItemFleet{} + staticRoutes, err := s.kuskClient.GetStaticRoutes("") + if err == nil { + for _, sr := range staticRoutes.Items { + if sr.Spec.Fleet.Name == fleet.Name && sr.Spec.Fleet.Namespace == fleet.Namespace { + srs = append(srs, StaticRouteItemFleet{ + Name: sr.Name, + Namespace: sr.Namespace, + }) + } + } + } + return EnvoyFleetItem{ - Name: fleet.Name, - Namespace: fleet.Namespace, - Apis: apifs, + Name: fleet.Name, + Namespace: fleet.Namespace, + Apis: apifs, + StaticRoutes: srs, } } From 7bb9cbb5fe25a7300c1cb7abca1a3150cfc0437c Mon Sep 17 00:00:00 2001 From: Jasmin Gacic Date: Tue, 5 Apr 2022 13:48:08 +0000 Subject: [PATCH 09/10] addressing remarks from the PR Signed-off-by: Jasmin Gacic --- Makefile | 2 +- server/.openapi-generator-ignore | 2 +- server/README.md | 2 +- server/go/routers.go | 13 +++++++------ 4 files changed, 10 insertions(+), 9 deletions(-) diff --git a/Makefile b/Makefile index 9bc4b2d..63eb4fa 100644 --- a/Makefile +++ b/Makefile @@ -10,4 +10,4 @@ run: run-minikube: docker-compose -f docker-compose.yaml -f docker-compose-minikube.yaml up --build -d test: - cd ./server && FAKE=true go test -v ./... \ No newline at end of file + cd ./server && FAKE=true go test -v ./... diff --git a/server/.openapi-generator-ignore b/server/.openapi-generator-ignore index bc5c6fc..3a8a998 100644 --- a/server/.openapi-generator-ignore +++ b/server/.openapi-generator-ignore @@ -2,4 +2,4 @@ go/api_fleets_service.go main.go go/go.mod go/Dockerfile -Dockerfile \ No newline at end of file +Dockerfile diff --git a/server/README.md b/server/README.md index 9ecf620..d8c10be 100644 --- a/server/README.md +++ b/server/README.md @@ -30,5 +30,5 @@ docker build --network=host -t openapi . Once image is built use ``` -docker run --rm -it openapi +make build ``` diff --git a/server/go/routers.go b/server/go/routers.go index 9331a27..06a5160 100644 --- a/server/go/routers.go +++ b/server/go/routers.go @@ -12,21 +12,22 @@ package openapi import ( "encoding/json" "errors" - "github.com/gorilla/mux" - "github.com/gorilla/handlers" "io/ioutil" "mime/multipart" "net/http" "os" "strconv" "strings" + + "github.com/gorilla/handlers" + "github.com/gorilla/mux" ) // A Route defines the parameters for an api endpoint type Route struct { - Name string - Method string - Pattern string + Name string + Method string + Pattern string HandlerFunc http.HandlerFunc } @@ -216,4 +217,4 @@ func parseInt32ArrayParameter(param, delim string, required bool) ([]int32, erro } return ints, nil -} \ No newline at end of file +} From 3123b6260bf85f25ed6e1dfe8ffa6b65720b220d Mon Sep 17 00:00:00 2001 From: Jasmin Gacic Date: Tue, 5 Apr 2022 13:54:54 +0000 Subject: [PATCH 10/10] formatting Signed-off-by: Jasmin Gacic --- server/go/api.go | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/server/go/api.go b/server/go/api.go index fc87515..9f127ea 100644 --- a/server/go/api.go +++ b/server/go/api.go @@ -14,80 +14,77 @@ import ( "net/http" ) - - // ApisApiRouter defines the required methods for binding the api requests to a responses for the ApisApi // The ApisApiRouter implementation should parse necessary information from the http request, // pass the data to a ApisApiServicer to perform the required actions, then write the service results to the http response. -type ApisApiRouter interface { +type ApisApiRouter interface { GetApi(http.ResponseWriter, *http.Request) GetApiCRD(http.ResponseWriter, *http.Request) GetApiDefinition(http.ResponseWriter, *http.Request) GetApis(http.ResponseWriter, *http.Request) } + // FleetsApiRouter defines the required methods for binding the api requests to a responses for the FleetsApi // The FleetsApiRouter implementation should parse necessary information from the http request, // pass the data to a FleetsApiServicer to perform the required actions, then write the service results to the http response. -type FleetsApiRouter interface { +type FleetsApiRouter interface { GetEnvoyFleet(http.ResponseWriter, *http.Request) GetEnvoyFleetCRD(http.ResponseWriter, *http.Request) GetEnvoyFleets(http.ResponseWriter, *http.Request) } + // ServicesApiRouter defines the required methods for binding the api requests to a responses for the ServicesApi // The ServicesApiRouter implementation should parse necessary information from the http request, // pass the data to a ServicesApiServicer to perform the required actions, then write the service results to the http response. -type ServicesApiRouter interface { +type ServicesApiRouter interface { GetService(http.ResponseWriter, *http.Request) GetServices(http.ResponseWriter, *http.Request) } + // StaticRoutesApiRouter defines the required methods for binding the api requests to a responses for the StaticRoutesApi // The StaticRoutesApiRouter implementation should parse necessary information from the http request, // pass the data to a StaticRoutesApiServicer to perform the required actions, then write the service results to the http response. -type StaticRoutesApiRouter interface { +type StaticRoutesApiRouter interface { GetStaticRoute(http.ResponseWriter, *http.Request) GetStaticRouteCRD(http.ResponseWriter, *http.Request) GetStaticRoutes(http.ResponseWriter, *http.Request) } - // ApisApiServicer defines the api actions for the ApisApi service // This interface intended to stay up to date with the openapi yaml used to generate it, // while the service implementation can ignored with the .openapi-generator-ignore file // and updated with the logic required for the API. -type ApisApiServicer interface { +type ApisApiServicer interface { GetApi(context.Context, string, string) (ImplResponse, error) GetApiCRD(context.Context, string, string) (ImplResponse, error) GetApiDefinition(context.Context, string, string) (ImplResponse, error) GetApis(context.Context, string, string, string) (ImplResponse, error) } - // FleetsApiServicer defines the api actions for the FleetsApi service // This interface intended to stay up to date with the openapi yaml used to generate it, // while the service implementation can ignored with the .openapi-generator-ignore file // and updated with the logic required for the API. -type FleetsApiServicer interface { +type FleetsApiServicer interface { GetEnvoyFleet(context.Context, string, string) (ImplResponse, error) GetEnvoyFleetCRD(context.Context, string, string) (ImplResponse, error) GetEnvoyFleets(context.Context, string) (ImplResponse, error) } - // ServicesApiServicer defines the api actions for the ServicesApi service // This interface intended to stay up to date with the openapi yaml used to generate it, // while the service implementation can ignored with the .openapi-generator-ignore file // and updated with the logic required for the API. -type ServicesApiServicer interface { +type ServicesApiServicer interface { GetService(context.Context, string, string) (ImplResponse, error) GetServices(context.Context, string) (ImplResponse, error) } - // StaticRoutesApiServicer defines the api actions for the StaticRoutesApi service // This interface intended to stay up to date with the openapi yaml used to generate it, // while the service implementation can ignored with the .openapi-generator-ignore file // and updated with the logic required for the API. -type StaticRoutesApiServicer interface { +type StaticRoutesApiServicer interface { GetStaticRoute(context.Context, string, string) (ImplResponse, error) GetStaticRouteCRD(context.Context, string, string) (ImplResponse, error) GetStaticRoutes(context.Context, string) (ImplResponse, error)