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

Update github.com/kubeshop/kusk-gateway to v1.5.0 #84

Merged
merged 3 commits into from
Dec 7, 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
9 changes: 8 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
FAKE ?= true

.PHONY: all
all: format test build

.PHONY: build
build:
docker buildx build -t kubeshop/kusk-gateway-api -f build/api-server/Dockerfile .
docker tag kubeshop/kusk-gateway-api ttl.sh/kubeshop/kusk-gateway-api:latest
docker tag kubeshop/kusk-gateway-api ttl.sh/kubeshop/kusk-gateway-api:$(shell git describe --tags $(shell git rev-list --tags --max-count=1))
@echo
docker buildx build -t kubeshop/kusk-gateway-api-websocket -f build/websocket/Dockerfile .
docker tag kubeshop/kusk-gateway-api-websocket ttl.sh/kubeshop/kusk-gateway-api-websocket:latest
docker tag kubeshop/kusk-gateway-api-websocket ttl.sh/kubeshop/kusk-gateway-api-websocket:$(shell git describe --tags $(shell git rev-list --tags --max-count=1))

server-generate:
openapi-generator-cli generate -i api/openapi.yaml -g go-server -o server/ --additional-properties=featureCORS=true
Expand All @@ -16,7 +23,7 @@ run-minikube:
docker-compose -f docker-compose.yaml -f docker-compose-minikube.yaml up --build --force-recreate

test:
cd ./server && FAKE=true go test -v -count=1 ./...
cd ./server && FAKE=${FAKE} go test -v -count=1 ./...

.PHONY: format
format:
Expand Down
15 changes: 9 additions & 6 deletions server/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,35 @@
This is the Kusk Gateway Management API

## Overview
This server was generated by the [openapi-generator]
(https://openapi-generator.tech) project.

This server was generated by the [openapi-generator](https://openapi-generator.tech) project.
By using the [OpenAPI-Spec](https://github.com/OAI/OpenAPI-Specification) from a remote server, you can easily generate a server stub.
-

To see how to make this your own, look here:

[README](https://openapi-generator.tech)
[OpenAPITools/openapi-generator](https://github.com/OpenAPITools/openapi-generator)

- API version: 1.0.0
- Build date: 2022-04-04T20:47:47.857Z[Etc/UTC]


### Running the server

To run the server, follow these simple steps:

```
```sh
go run main.go
```

To run the server in a docker container
```

```sh
docker build --network=host -t openapi .
```

Once image is built use
```

```sh
make build
```
2 changes: 1 addition & 1 deletion server/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ require (
github.com/gorilla/handlers v1.5.1
github.com/gorilla/mux v1.8.0
github.com/gorilla/websocket v1.5.0
github.com/kubeshop/kusk-gateway v1.3.12
github.com/kubeshop/kusk-gateway v1.5.0
github.com/stretchr/testify v1.8.0
gopkg.in/yaml.v3 v3.0.1
k8s.io/api v0.25.2
Expand Down
6 changes: 3 additions & 3 deletions server/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -214,13 +214,13 @@ github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxv
github.com/konsorten/go-windows-terminal-sequences v1.0.3/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pretty v0.2.0 h1:s5hAObm+yFO5uHYt5dYjxi2rXrsnmRpJx4OYvIWUaQs=
github.com/kr/pretty v0.2.0/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
github.com/kr/pretty v0.2.1 h1:Fmg33tUaq4/8ym9TJN1x7sLJnHVwhP33CNkpYV/7rwI=
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/kubeshop/kusk-gateway v1.3.12 h1:3EwcueWJkqZdO+7CIRitFBNsl/iT/XG9ii87sQjupAU=
github.com/kubeshop/kusk-gateway v1.3.12/go.mod h1:qQ9twNe4K9eAdTNV5gPzwqX7TVaxhesmzxCf1HGDGh0=
github.com/kubeshop/kusk-gateway v1.5.0 h1:EyKXloDkkxW01JqTCySl9Q9D00Qe+xw8Ciu0va7Q2C8=
github.com/kubeshop/kusk-gateway v1.5.0/go.mod h1:DMeiclKYfrP5P7EYWTfIxzd4m0hzPIVgFPdWBml3xlg=
github.com/mailru/easyjson v0.0.0-20190614124828-94de47d64c63/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc=
github.com/mailru/easyjson v0.0.0-20190626092158-b2ccc519800e/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc=
github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0=
Expand Down
15 changes: 8 additions & 7 deletions server/kusk/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import (
"errors"
"fmt"

"github.com/kubeshop/kusk-gateway/api/v1alpha1"
kuskv1 "github.com/kubeshop/kusk-gateway/api/v1alpha1"
"gopkg.in/yaml.v3"
corev1 "k8s.io/api/core/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
Expand All @@ -15,6 +13,9 @@ import (
"k8s.io/apimachinery/pkg/selection"
"k8s.io/client-go/util/retry"
"sigs.k8s.io/controller-runtime/pkg/client"

"github.com/kubeshop/kusk-gateway/api/v1alpha1"
kuskv1 "github.com/kubeshop/kusk-gateway/api/v1alpha1"
)

var ErrNotFound = errors.New("error not found")
Expand Down Expand Up @@ -276,11 +277,11 @@ func (k *kuskClient) CreateStaticRoute(namespace, name, fleetName, fleetNamespac

err := yaml.Unmarshal([]byte(specs), tmp)
if err != nil {
fmt.Println(err)
fmt.Println(fmt.Errorf("CreateStaticRoute - yaml.Unmarshal failed: specs=%v, %w", specs, err))
}

staticRoute.Spec.Paths = tmp.Spec.Paths
staticRoute.Spec.Hosts = tmp.Spec.Hosts
staticRoute.Spec.Upstream = tmp.Spec.Upstream

if err := k.client.Create(context.TODO(), staticRoute, &client.CreateOptions{}); err != nil {
return nil, err
Expand All @@ -297,7 +298,7 @@ func (k *kuskClient) UpdateStaticRoute(namespace, name, fleetName, fleetNamespac
tmp := &kuskv1.StaticRoute{}
err := yaml.Unmarshal([]byte(specs), tmp)
if err != nil {
fmt.Println(err)
fmt.Println(fmt.Errorf("UpdateStaticRoute - yaml.Unmarshal failed: specs=%v, %w", specs, err))
}

retryErr := retry.RetryOnConflict(retry.DefaultRetry, func() error {
Expand All @@ -310,8 +311,8 @@ func (k *kuskClient) UpdateStaticRoute(namespace, name, fleetName, fleetNamespac
Name: fleetName,
Namespace: fleetNamespace,
},
Paths: tmp.Spec.Paths,
Hosts: tmp.Spec.Hosts,
Hosts: tmp.Spec.Hosts,
Upstream: tmp.Spec.Upstream,
}

return k.client.Update(context.TODO(), staticRoute, &client.UpdateOptions{})
Expand Down
30 changes: 20 additions & 10 deletions server/kusk/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ import (
"strings"
"testing"

"github.com/kubeshop/kusk-gateway/api/v1alpha1"
kuskv1 "github.com/kubeshop/kusk-gateway/api/v1alpha1"
"github.com/stretchr/testify/require"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand All @@ -17,19 +15,23 @@ import (
"k8s.io/client-go/tools/clientcmd"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/client/fake"

"github.com/kubeshop/kusk-gateway/api/v1alpha1"
kuskv1 "github.com/kubeshop/kusk-gateway/api/v1alpha1"
)

var testClient Client

func setup(tb testing.TB) {
if _, fakeIt := os.LookupEnv("FAKE"); fakeIt {
func setup(t *testing.T) {
if fake, isFakeDefined := os.LookupEnv("FAKE"); isFakeDefined && (fake == "true" || fake == "TRUE" || fake == "1") {
testClient = NewClient(getFakeClient())
return
}

k8sclient, err := getClient()
if err != nil {
tb.Error(err)
tb.Fail()
t.Error(err)
t.Fail()
return
}

Expand Down Expand Up @@ -179,11 +181,19 @@ func TestCreateStaticRoute(t *testing.T) {

setup(t)

namespace := "static-route-2"
name := "default"
namespace := "default"
name := "static-route-example-1-top-level-upstream"
fleetNamespace := "default"
fleetName := "/static-route-2"
staticRoute, err := testClient.CreateStaticRoute(namespace, name, fleetNamespace, fleetName, "")
fleetName := "default"
specs := `
spec:
upstream:
service:
name: static-route-example-1-top-level-upstream
namespace: default
port: 80
`
staticRoute, err := testClient.CreateStaticRoute(namespace, name, fleetNamespace, fleetName, specs)

require.NoError(err)
require.NotNil(staticRoute)
Expand Down