Skip to content

Commit

Permalink
Merge pull request #69 from kubeshop/create_fleet_fix
Browse files Browse the repository at this point in the history
Fix: CreateFleet
  • Loading branch information
jasmingacic authored Sep 7, 2022
2 parents b427eb9 + 35272f3 commit 0191745
Show file tree
Hide file tree
Showing 9 changed files with 27 additions and 106 deletions.
3 changes: 0 additions & 3 deletions api/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -605,7 +605,6 @@ components:
type: object
required:
- name
- status
- namespace
- serviceType
- ports
Expand Down Expand Up @@ -678,9 +677,7 @@ components:
type: object
required:
- name
- nodePort
- port
- protocol
- targetPort
properties:
name:
Expand Down
15 changes: 12 additions & 3 deletions server/go/api_apis.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,10 @@ func (c *ApisApiController) DeleteApi(w http.ResponseWriter, r *http.Request) {
return
}
// If no error, encode the body and the result code
EncodeJSONResponse(result.Body, &result.Code, w)
if err := EncodeJSONResponse(result.Body, &result.Code, w); err != nil {
c.errorHandler(w, r, err, &result)
return
}

}

Expand Down Expand Up @@ -143,7 +146,10 @@ func (c *ApisApiController) UpdateApi(w http.ResponseWriter, r *http.Request) {
return
}
// If no error, encode the body and the result code
EncodeJSONResponse(result.Body, &result.Code, w)
if err := EncodeJSONResponse(result.Body, &result.Code, w); err != nil {
c.errorHandler(w, r, err, &result)
return
}
}

// DeployApi - Deploy new API
Expand All @@ -161,7 +167,10 @@ func (c *ApisApiController) DeployApi(w http.ResponseWriter, r *http.Request) {
return
}
// If no error, encode the body and the result code
EncodeJSONResponse(result.Body, &result.Code, w)
if err := EncodeJSONResponse(result.Body, &result.Code, w); err != nil {
c.errorHandler(w, r, err, &result)
return
}

}

Expand Down
19 changes: 3 additions & 16 deletions server/go/api_apis_service_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (
"strings"

kusk "github.com/GIT_USER_ID/GIT_REPO_ID/kusk"
"github.com/GIT_USER_ID/GIT_REPO_ID/util"
kuskv1 "github.com/kubeshop/kusk-gateway/api/v1alpha1"
"github.com/kubeshop/kusk-gateway/pkg/analytics"
"github.com/kubeshop/kusk-gateway/pkg/spec"
Expand Down Expand Up @@ -89,20 +88,6 @@ func (s *ApisApiService) GetApiDefinition(ctx context.Context, namespace string,
return Response(http.StatusOK, api.Spec.Spec), nil
}

// GetPostProcessedOpenApiSpec - Get the post-processed OpenAPI spec by API id
func (s *ApisApiService) GetPostProcessedOpenApiSpec(ctx context.Context, namespace string, name string) (ImplResponse, error) {
analytics.SendAnonymousInfo(ctx, s.kuskClient.K8sClient(), "GetPostProcessedOpenApiSpec")
api, err := s.kuskClient.GetApi(namespace, name)
if err != nil {
return GetResponseFromK8sError(err), err
}

rawyaml := util.ParseKuskOpenAPI(api.Spec.Spec)
yml, _ := yaml.Marshal(rawyaml)

return Response(http.StatusOK, string(yml)), nil
}

func (s *ApisApiService) convertAPIListCRDtoAPIsModel(apis kuskv1.APIList) []ApiItem {
toReturn := []ApiItem{}
for _, api := range apis.Items {
Expand Down Expand Up @@ -158,7 +143,9 @@ func (s *ApisApiService) DeployApi(ctx context.Context, payload InlineObject) (I

func getApiVersion(apiSpec string) string {
var yml map[string]interface{}
yaml.Unmarshal([]byte(apiSpec), &yml)
if err := yaml.Unmarshal([]byte(apiSpec), &yml); err != nil {
return ""
}

for k, v := range yml {
if k == "info" {
Expand Down
6 changes: 3 additions & 3 deletions server/go/api_create_new_fleet_service_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,13 @@ func (s *CreateNewFleetApiService) CreateFleet(ctx context.Context, serviceItem
}

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

if f, err := s.kuskClient.CreateFleet(fleet); err != nil {
Expand Down
1 change: 0 additions & 1 deletion server/go/model_service_item.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ type ServiceItem struct {
func AssertServiceItemRequired(obj ServiceItem) error {
elements := map[string]interface{}{
"name": obj.Name,
"status": obj.Status,
"namespace": obj.Namespace,
"serviceType": obj.ServiceType,
"ports": obj.Ports,
Expand Down
2 changes: 0 additions & 2 deletions server/go/model_service_port_item.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@ type ServicePortItem struct {
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 {
Expand Down
4 changes: 3 additions & 1 deletion server/go/routers.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,9 @@ func readFileHeaderToTempFile(fileHeader *multipart.FileHeader) (*os.File, error

defer file.Close()

file.Write(fileBytes)
if _, err := file.Write(fileBytes); err != nil {
return nil, err
}

return file, nil
}
8 changes: 6 additions & 2 deletions server/kusk/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -267,8 +267,12 @@ func getFakeClient() client.Client {

func getClient() (client.Client, error) {
scheme := runtime.NewScheme()
kuskv1.AddToScheme(scheme)
corev1.AddToScheme(scheme)
if err := kuskv1.AddToScheme(scheme); err != nil {
return nil, err
}
if err := corev1.AddToScheme(scheme); err != nil {
return nil, err
}
config, err := getConfig()
if err != nil {
return nil, err
Expand Down
75 changes: 0 additions & 75 deletions server/util/util.go

This file was deleted.

0 comments on commit 0191745

Please sign in to comment.