Skip to content

Commit

Permalink
added fleet name and namespace to API creation
Browse files Browse the repository at this point in the history
Signed-off-by: Jasmin Gacic <jasmin.gacic@gmail.com>
  • Loading branch information
jasmingacic committed May 11, 2022
1 parent 7181ddc commit 56ab6ea
Show file tree
Hide file tree
Showing 12 changed files with 96 additions and 86 deletions.
2 changes: 2 additions & 0 deletions server/.openapi-generator/FILES
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ go.mod
go/api.go
go/api_apis.go
go/api_apis_service.go
go/api_create_new_static_route.go
go/api_create_new_static_route_service.go
go/api_fleets.go
go/api_services.go
go/api_services_service.go
Expand Down
60 changes: 5 additions & 55 deletions server/go.mod
Original file line number Diff line number Diff line change
@@ -1,65 +1,15 @@
module github.com/GIT_USER_ID/GIT_REPO_ID

go 1.17
go 1.13

require github.com/gorilla/mux v1.8.0

require (
github.com/gorilla/handlers v1.5.1
github.com/kubeshop/kusk-gateway v1.0.0-beta2
gopkg.in/yaml.v2 v2.4.0
github.com/kubeshop/kusk-gateway v1.0.0
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b
k8s.io/api v0.23.5
k8s.io/apimachinery v0.23.5
k8s.io/client-go v0.23.5
k8s.io/api v0.24.0
k8s.io/apimachinery v0.24.0
k8s.io/client-go v0.24.0
sigs.k8s.io/controller-runtime v0.11.2
)

require (
github.com/asaskevich/govalidator v0.0.0-20200108200545-475eaeb16496 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/cespare/xxhash/v2 v2.1.1 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/evanphx/json-patch v4.12.0+incompatible // indirect
github.com/felixge/httpsnoop v1.0.1 // indirect
github.com/getkin/kin-openapi v0.76.0 // indirect
github.com/ghodss/yaml v1.0.0 // indirect
github.com/go-logr/logr v1.2.0 // indirect
github.com/go-openapi/jsonpointer v0.19.5 // indirect
github.com/go-openapi/swag v0.19.14 // indirect
github.com/go-ozzo/ozzo-validation/v4 v4.3.0 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/google/go-cmp v0.5.5 // indirect
github.com/google/gofuzz v1.1.0 // indirect
github.com/googleapis/gnostic v0.5.5 // indirect
github.com/imdario/mergo v0.3.12 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/mailru/easyjson v0.7.6 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.2-0.20181231171920-c182affec369 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/prometheus/client_golang v1.11.0 // indirect
github.com/prometheus/client_model v0.2.0 // indirect
github.com/prometheus/common v0.28.0 // indirect
github.com/prometheus/procfs v0.6.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
golang.org/x/net v0.0.0-20211209124913-491a49abca63 // indirect
golang.org/x/oauth2 v0.0.0-20210819190943-2bc19b11175f // indirect
golang.org/x/sys v0.0.0-20211029165221-6e7872819dc8 // indirect
golang.org/x/term v0.0.0-20210615171337-6886f2dfbf5b // indirect
golang.org/x/text v0.3.7 // indirect
golang.org/x/time v0.0.0-20210723032227-1f47c861a9ac // indirect
gomodules.xyz/jsonpatch/v2 v2.2.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/protobuf v1.27.1 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
k8s.io/klog/v2 v2.30.0 // indirect
k8s.io/kube-openapi v0.0.0-20211115234752-e816edb12b65 // indirect
k8s.io/utils v0.0.0-20211116205334-6203023598ed // indirect
sigs.k8s.io/json v0.0.0-20211020170558-c049b76a60c6 // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.2.1 // indirect
sigs.k8s.io/yaml v1.3.0 // indirect
)
62 changes: 47 additions & 15 deletions server/go.sum

Large diffs are not rendered by default.

15 changes: 15 additions & 0 deletions server/go/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@ type ApisApiRouter interface {
GetApis(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.
type CreateNewStaticRouteApiRouter interface {
CreateStaticRoute(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.
Expand Down Expand Up @@ -63,6 +70,14 @@ type ApisApiServicer interface {
GetApis(context.Context, string, string, string) (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)
}

// 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
Expand Down
10 changes: 5 additions & 5 deletions server/go/api_apis.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,31 +53,31 @@ func (c *ApisApiController) Routes() Routes {
{
"DeployApi",
strings.ToUpper("Post"),
"/apis",
"/api/apis",
c.DeployApi,
},
{
"GetApi",
strings.ToUpper("Get"),
"/apis/{namespace}/{name}",
"/api/apis/{namespace}/{name}",
c.GetApi,
},
{
"GetApiCRD",
strings.ToUpper("Get"),
"/apis/{namespace}/{name}/crd",
"/api/apis/{namespace}/{name}/crd",
c.GetApiCRD,
},
{
"GetApiDefinition",
strings.ToUpper("Get"),
"/apis/{namespace}/{name}/definition",
"/api/apis/{namespace}/{name}/definition",
c.GetApiDefinition,
},
{
"GetApis",
strings.ToUpper("Get"),
"/apis",
"/api/apis",
c.GetApis,
},
}
Expand Down
2 changes: 1 addition & 1 deletion server/go/api_apis_service_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ func (s *ApisApiService) convertAPICRDtoAPIModel(api *kuskv1.API) ApiItem {

// DeployApi - Deploy new API
func (s *ApisApiService) DeployApi(ctx context.Context, payload APIPayload) (ImplResponse, error) {
api, err := s.kuskClient.CreateApi(payload.Name, payload.Namespace, payload.Openapi)
api, err := s.kuskClient.CreateApi(payload.Name, payload.Namespace, payload.Openapi, payload.EnvoyFleetName, payload.EnvoyFleetNamespace)
if err != nil {
return Response(http.StatusInternalServerError, err), err
}
Expand Down
6 changes: 3 additions & 3 deletions server/go/api_fleets.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,19 +52,19 @@ func (c *FleetsApiController) Routes() Routes {
{
"GetEnvoyFleet",
strings.ToUpper("Get"),
"/fleets/{namespace}/{name}",
"/api/fleets/{namespace}/{name}",
c.GetEnvoyFleet,
},
{
"GetEnvoyFleetCRD",
strings.ToUpper("Get"),
"/fleets/{namespace}/{name}/crd",
"/api/fleets/{namespace}/{name}/crd",
c.GetEnvoyFleetCRD,
},
{
"GetEnvoyFleets",
strings.ToUpper("Get"),
"/fleets",
"/api/fleets",
c.GetEnvoyFleets,
},
}
Expand Down
4 changes: 2 additions & 2 deletions server/go/api_services.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,13 @@ func (c *ServicesApiController) Routes() Routes {
{
"GetService",
strings.ToUpper("Get"),
"/services/{namespace}/{name}",
"/api/services/{namespace}/{name}",
c.GetService,
},
{
"GetServices",
strings.ToUpper("Get"),
"/services",
"/api/services",
c.GetServices,
},
}
Expand Down
6 changes: 3 additions & 3 deletions server/go/api_static_routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,19 +52,19 @@ func (c *StaticRoutesApiController) Routes() Routes {
{
"GetStaticRoute",
strings.ToUpper("Get"),
"/staticroutes/{namespace}/{name}",
"/api/staticroutes/{namespace}/{name}",
c.GetStaticRoute,
},
{
"GetStaticRouteCRD",
strings.ToUpper("Get"),
"/staticroutes/{namespace}/{name}/crd",
"/api/staticroutes/{namespace}/{name}/crd",
c.GetStaticRouteCRD,
},
{
"GetStaticRoutes",
strings.ToUpper("Get"),
"/staticroutes",
"/api/staticroutes",
c.GetStaticRoutes,
},
}
Expand Down
4 changes: 4 additions & 0 deletions server/go/model_inline_object.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ type APIPayload struct {

Namespace string `json:"namespace,omitempty"`

EnvoyFleetName string `json:"envoyFleetName,omitempty"`

EnvoyFleetNamespace string `json:"envoyFleetNamespace,omitempty"`

Openapi string `json:"openapi,omitempty"`
}

Expand Down
3 changes: 3 additions & 0 deletions server/go/routers.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"net/http"
"os"

"github.com/gorilla/handlers"
"github.com/gorilla/mux"
)

Expand Down Expand Up @@ -43,6 +44,8 @@ func NewRouter(routers ...Router) *mux.Router {
var handler http.Handler
handler = route.HandlerFunc
handler = Logger(handler, route.Name)
handler = handlers.CORS()(handler)

router.
Methods(route.Method).
Path(route.Pattern).
Expand Down
8 changes: 6 additions & 2 deletions server/kusk/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ type Client interface {
GetApis(namespace string) (*kuskv1.APIList, error)
GetApi(namespace, name string) (*kuskv1.API, error)
GetApiByEnvoyFleet(namespace, fleetNamespace, fleetName string) (*kuskv1.APIList, error)
CreateApi(name, namespace, openapispec string) (*kuskv1.API, error)
CreateApi(name, namespace, openapispec, fleetName, fleetnamespace string) (*kuskv1.API, error)

GetStaticRoute(namespace, name string) (*kuskv1.StaticRoute, error)
GetStaticRoutes(namespace string) (*kuskv1.StaticRouteList, error)
Expand Down Expand Up @@ -90,14 +90,18 @@ func (k *kuskClient) GetApiByEnvoyFleet(namespace, fleetNamespace, fleetName str
return &kuskv1.APIList{Items: toReturn}, nil
}

func (k *kuskClient) CreateApi(name, namespace, openapispec string) (*kuskv1.API, error) {
func (k *kuskClient) CreateApi(name, namespace, openapispec string, fleetName string, fleetnamespace string) (*kuskv1.API, error) {
api := &kuskv1.API{
ObjectMeta: v1.ObjectMeta{
Name: name,
Namespace: namespace,
},
Spec: kuskv1.APISpec{
Spec: openapispec,
Fleet: &kuskv1.EnvoyFleetID{
Name: fleetName,
Namespace: fleetnamespace,
},
},
}
if err := k.client.Create(context.TODO(), api, &client.CreateOptions{}); err != nil {
Expand Down

0 comments on commit 56ab6ea

Please sign in to comment.