Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

various creates and deletes #49

Merged
merged 2 commits into from
May 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions server/.openapi-generator/FILES
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,17 @@ go.mod
go/api.go
go/api_apis.go
go/api_apis_service.go
go/api_create_new_fleet.go
go/api_create_new_fleet_service.go
go/api_create_new_static_route.go
go/api_create_new_static_route_service.go
go/api_fleets.go
go/api_namespaces.go
go/api_namespaces_service.go
go/api_services.go
go/api_services_service.go
go/api_static_route.go
go/api_static_route_service.go
go/api_static_routes.go
go/api_static_routes_service.go
go/error.go
Expand All @@ -21,6 +25,7 @@ go/model_api_item_fleet.go
go/model_api_item_service.go
go/model_envoy_fleet_item.go
go/model_inline_object.go
go/model_inline_object_1.go
go/model_namespace_item.go
go/model_service_item.go
go/model_service_port_item.go
Expand Down
2 changes: 1 addition & 1 deletion server/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ require (
github.com/gorilla/handlers v1.5.1
github.com/kubeshop/kusk-gateway v1.0.0
github.com/stretchr/testify v1.7.0
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b
gopkg.in/yaml.v3 v3.0.0
k8s.io/api v0.24.0
k8s.io/apimachinery v0.24.0
k8s.io/client-go v0.24.0
Expand Down
3 changes: 2 additions & 1 deletion server/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -972,8 +972,9 @@ gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b h1:h8qDotaEPuJATrMmW04NCwg7v22aHH28wwpauUhK9Oo=
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.0 h1:hjy8E9ON/egN1tAYqKb61G10WtihqetD4sz2H+8nIeA=
gopkg.in/yaml.v3 v3.0.0/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gotest.tools/v3 v3.0.2/go.mod h1:3SzNCllyD9/Y+b5r9JIKQ474KzkZyqLqEfYqMsX94Bk=
gotest.tools/v3 v3.0.3/go.mod h1:Z7Lb0S5l+klDB31fvDQX8ss/FlKDxtlFlw3Oa8Ymbl8=
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
Expand Down
36 changes: 35 additions & 1 deletion server/go/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,21 @@ import (
// 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 {
DeleteApi(http.ResponseWriter, *http.Request)
DeployApi(http.ResponseWriter, *http.Request)
GetApi(http.ResponseWriter, *http.Request)
GetApiCRD(http.ResponseWriter, *http.Request)
GetApiDefinition(http.ResponseWriter, *http.Request)
GetApis(http.ResponseWriter, *http.Request)
}

// CreateNewFleetApiRouter defines the required methods for binding the api requests to a responses for the CreateNewFleetApi
// The CreateNewFleetApiRouter implementation should parse necessary information from the http request,
// pass the data to a CreateNewFleetApiServicer to perform the required actions, then write the service results to the http response.
type CreateNewFleetApiRouter interface {
CreateFleet(http.ResponseWriter, *http.Request)
}

// CreateNewStaticRouteApiRouter defines the required methods for binding the api requests to a responses for the CreateNewStaticRouteApi
// The CreateNewStaticRouteApiRouter implementation should parse necessary information from the http request,
// pass the data to a CreateNewStaticRouteApiServicer to perform the required actions, then write the service results to the http response.
Expand All @@ -36,6 +44,7 @@ type CreateNewStaticRouteApiRouter interface {
// 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 {
DeleteFleet(http.ResponseWriter, *http.Request)
GetEnvoyFleet(http.ResponseWriter, *http.Request)
GetEnvoyFleetCRD(http.ResponseWriter, *http.Request)
GetEnvoyFleets(http.ResponseWriter, *http.Request)
Expand All @@ -56,6 +65,13 @@ type ServicesApiRouter interface {
GetServices(http.ResponseWriter, *http.Request)
}

// StaticRouteApiRouter defines the required methods for binding the api requests to a responses for the StaticRouteApi
// The StaticRouteApiRouter implementation should parse necessary information from the http request,
// pass the data to a StaticRouteApiServicer to perform the required actions, then write the service results to the http response.
type StaticRouteApiRouter interface {
DeleteStaticRoute(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.
Expand All @@ -70,26 +86,36 @@ type StaticRoutesApiRouter interface {
// while the service implementation can ignored with the .openapi-generator-ignore file
// and updated with the logic required for the API.
type ApisApiServicer interface {
DeleteApi(context.Context, string, string) (ImplResponse, error)
DeployApi(context.Context, InlineObject) (ImplResponse, error)
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)
}

// CreateNewFleetApiServicer defines the api actions for the CreateNewFleetApi 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 CreateNewFleetApiServicer interface {
CreateFleet(context.Context, ServiceItem) (ImplResponse, error)
}

// CreateNewStaticRouteApiServicer defines the api actions for the CreateNewStaticRouteApi 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 CreateNewStaticRouteApiServicer interface {
CreateStaticRoute(context.Context, StaticRouteItem) (ImplResponse, error)
CreateStaticRoute(context.Context, InlineObject1) (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 {
DeleteFleet(context.Context, string, string) (ImplResponse, error)
GetEnvoyFleet(context.Context, string, string) (ImplResponse, error)
GetEnvoyFleetCRD(context.Context, string, string) (ImplResponse, error)
GetEnvoyFleets(context.Context, string) (ImplResponse, error)
Expand All @@ -112,6 +138,14 @@ type ServicesApiServicer interface {
GetServices(context.Context, string) (ImplResponse, error)
}

// StaticRouteApiServicer defines the api actions for the StaticRouteApi 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 StaticRouteApiServicer interface {
DeleteStaticRoute(context.Context, string, 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
Expand Down
24 changes: 24 additions & 0 deletions server/go/api_apis.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ func NewApisApiController(s ApisApiServicer, opts ...ApisApiOption) Router {
// Routes returns all of the api route for the ApisApiController
func (c *ApisApiController) Routes() Routes {
return Routes{
{
"DeleteApi",
strings.ToUpper("Delete"),
"/apis/{namespace}/{name}",
c.DeleteApi,
},
{
"DeployApi",
strings.ToUpper("Post"),
Expand Down Expand Up @@ -83,6 +89,24 @@ func (c *ApisApiController) Routes() Routes {
}
}

// DeleteApi - Delete an API instance by namespace and name
func (c *ApisApiController) DeleteApi(w http.ResponseWriter, r *http.Request) {
params := mux.Vars(r)
namespaceParam := params["namespace"]

nameParam := params["name"]

result, err := c.service.DeleteApi(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)

}

// DeployApi - Deploy new API
func (c *ApisApiController) DeployApi(w http.ResponseWriter, r *http.Request) {
inlineObjectParam := InlineObject{}
Expand Down
12 changes: 11 additions & 1 deletion server/go/api_apis_service_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ package openapi

import (
"context"
"errors"
"net/http"
"strings"

Expand Down Expand Up @@ -139,7 +140,7 @@ func (s *ApisApiService) convertAPICRDtoAPIModel(api *kuskv1.API) ApiItem {

// DeployApi - Deploy new API
func (s *ApisApiService) DeployApi(ctx context.Context, payload InlineObject) (ImplResponse, error) {
api, err := s.kuskClient.CreateApi(payload.Name, payload.Namespace, payload.Openapi, payload.EnvoyFleetName, payload.EnvoyFleetNamespace)
api, err := s.kuskClient.CreateApi(payload.Namespace, payload.Name, payload.Openapi, payload.EnvoyFleetName, payload.EnvoyFleetNamespace)
if err != nil {
return Response(http.StatusInternalServerError, err), err
}
Expand All @@ -159,3 +160,12 @@ func getApiVersion(apiSpec string) string {
}
return ""
}

// DeleteApi - Delete an API instance by namespace and name
func (s *ApisApiService) DeleteApi(ctx context.Context, namespace string, name string) (ImplResponse, error) {
if err := s.kuskClient.DeleteAPI(namespace, name); err != nil {
return Response(http.StatusInternalServerError, err), errors.New("DeleteApi method failed")

}
return Response(http.StatusOK, nil), nil
}
82 changes: 82 additions & 0 deletions server/go/api_create_new_fleet.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/*
* 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 (
"encoding/json"
"net/http"
"strings"
)

// CreateNewFleetApiController binds http requests to an api service and writes the service results to the http response
type CreateNewFleetApiController struct {
service CreateNewFleetApiServicer
errorHandler ErrorHandler
}

// CreateNewFleetApiOption for how the controller is set up.
type CreateNewFleetApiOption func(*CreateNewFleetApiController)

// WithCreateNewFleetApiErrorHandler inject ErrorHandler into controller
func WithCreateNewFleetApiErrorHandler(h ErrorHandler) CreateNewFleetApiOption {
return func(c *CreateNewFleetApiController) {
c.errorHandler = h
}
}

// NewCreateNewFleetApiController creates a default api controller
func NewCreateNewFleetApiController(s CreateNewFleetApiServicer, opts ...CreateNewFleetApiOption) Router {
controller := &CreateNewFleetApiController{
service: s,
errorHandler: DefaultErrorHandler,
}

for _, opt := range opts {
opt(controller)
}

return controller
}

// Routes returns all of the api route for the CreateNewFleetApiController
func (c *CreateNewFleetApiController) Routes() Routes {
return Routes{
{
"CreateFleet",
strings.ToUpper("Post"),
"/fleets",
c.CreateFleet,
},
}
}

// CreateFleet - create new fleet
func (c *CreateNewFleetApiController) CreateFleet(w http.ResponseWriter, r *http.Request) {
serviceItemParam := ServiceItem{}
d := json.NewDecoder(r.Body)
d.DisallowUnknownFields()
if err := d.Decode(&serviceItemParam); err != nil {
c.errorHandler(w, r, &ParsingError{Err: err}, nil)
return
}
if err := AssertServiceItemRequired(serviceItemParam); err != nil {
c.errorHandler(w, r, err, nil)
return
}
result, err := c.service.CreateFleet(r.Context(), serviceItemParam)
// 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)

}
66 changes: 66 additions & 0 deletions server/go/api_create_new_fleet_service_impl.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
* 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"
"errors"
"net/http"

kusk "github.com/GIT_USER_ID/GIT_REPO_ID/kusk"
kuskv1 "github.com/kubeshop/kusk-gateway/api/v1alpha1"
corev1 "k8s.io/api/core/v1"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/intstr"
)

// CreateNewFleetApiService is a service that implements the logic for the CreateNewFleetApiServicer
// This service should implement the business logic for every endpoint for the CreateNewFleetApi API.
// Include any external packages or services that will be required by this service.
type CreateNewFleetApiService struct {
kuskClient kusk.Client
}

// NewCreateNewFleetApiService creates a default api service
func NewCreateNewFleetApiService(kuskClient kusk.Client) CreateNewFleetApiServicer {
return &CreateNewFleetApiService{kuskClient: kuskClient}
}

// CreateFleet - create new fleet
func (s *CreateNewFleetApiService) CreateFleet(ctx context.Context, serviceItem ServiceItem) (ImplResponse, error) {
fleet := kuskv1.EnvoyFleet{
ObjectMeta: v1.ObjectMeta{
Name: serviceItem.Name,
Namespace: serviceItem.Namespace,
},
Spec: kuskv1.EnvoyFleetSpec{
Service: &kuskv1.ServiceConfig{
Type: corev1.ServiceType(serviceItem.ServiceType),
Ports: []corev1.ServicePort{},
},
},
}

for _, p := range serviceItem.Ports {
fleet.Spec.Service.Ports = append(fleet.Spec.Service.Ports, corev1.ServicePort{
Name: p.Name,
NodePort: p.NodePort,
Port: p.Port,
Protocol: corev1.Protocol(p.Protocol),
TargetPort: intstr.FromString(p.TargetPort),
})
}

if f, err := s.kuskClient.CreateFleet(fleet); err != nil {
return Response(http.StatusInternalServerError, err), errors.New("CreateFleet method failed")
} else {
return Response(http.StatusCreated, f), nil
}
}
8 changes: 4 additions & 4 deletions server/go/api_create_new_static_route.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,18 +59,18 @@ func (c *CreateNewStaticRouteApiController) Routes() Routes {

// CreateStaticRoute - create new static route
func (c *CreateNewStaticRouteApiController) CreateStaticRoute(w http.ResponseWriter, r *http.Request) {
staticRouteItemParam := StaticRouteItem{}
inlineObject1Param := InlineObject1{}
d := json.NewDecoder(r.Body)
d.DisallowUnknownFields()
if err := d.Decode(&staticRouteItemParam); err != nil {
if err := d.Decode(&inlineObject1Param); err != nil {
c.errorHandler(w, r, &ParsingError{Err: err}, nil)
return
}
if err := AssertStaticRouteItemRequired(staticRouteItemParam); err != nil {
if err := AssertInlineObject1Required(inlineObject1Param); err != nil {
c.errorHandler(w, r, err, nil)
return
}
result, err := c.service.CreateStaticRoute(r.Context(), staticRouteItemParam)
result, err := c.service.CreateStaticRoute(r.Context(), inlineObject1Param)
// If an error occurred, encode the error with the status code
if err != nil {
c.errorHandler(w, r, err, &result)
Expand Down
10 changes: 0 additions & 10 deletions server/go/api_create_new_static_route_service.go

This file was deleted.

Loading