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

fix(api-server): avoid panic when there no insight for entity #8068

Merged
merged 1 commit into from
Oct 19, 2023
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
15 changes: 14 additions & 1 deletion UPGRADE.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ does not have any particular instructions.

## Upgrade to `2.5.x`

#### More strict validation rules for resource names
### More strict validation rules for resource names

In order to be compatible with Kubernetes naming policy we updated the validation rules. Old rule:

Expand All @@ -20,6 +20,19 @@ New rule:

New rule is applied for CREATE operations. The old rule is still applied for UPDATE, but this is going to change in Kuma 2.7.x or later.

### API

#### overview API coherency

These endpoints are getting replaced to achieve more coherency on the API:

- `/meshes/{mesh}/zoneegressoverviews` moves to `/meshes/{mesh}/zoneegresses/-overview`
- `/meshes/{mesh}/zoneingresses+insights` moves to `/meshes/{mesh}/zone-ingresses/-overview`
- `/meshes/{mesh}/dataplanes+insights` moves to `/meshes/{mesh}/dataplanes/-overview`
- `/zones+insights` moves to `/zones/-overview`

While you can use the old API they will be removed in a future version

## Upgrade to `2.4.x`

### Configuration change
Expand Down
34 changes: 31 additions & 3 deletions pkg/api-server/dataplane_overview_endpoints_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"io"
"net/http"
"strings"
"time"

. "github.com/onsi/ginkgo/v2"
Expand All @@ -14,8 +15,10 @@ import (
api_server "github.com/kumahq/kuma/pkg/api-server"
core_mesh "github.com/kumahq/kuma/pkg/core/resources/apis/mesh"
"github.com/kumahq/kuma/pkg/core/resources/model"
"github.com/kumahq/kuma/pkg/core/resources/model/rest"
"github.com/kumahq/kuma/pkg/core/resources/store"
"github.com/kumahq/kuma/pkg/plugins/resources/memory"
"github.com/kumahq/kuma/pkg/test/matchers"
"github.com/kumahq/kuma/pkg/util/proto"
)

Expand Down Expand Up @@ -101,6 +104,26 @@ var _ = Describe("Dataplane Overview Endpoints", func() {
},
},
})

dpResource := core_mesh.DataplaneResource{
Spec: &v1alpha1.Dataplane{
Networking: &v1alpha1.Dataplane_Networking{
Address: "127.0.0.1",
Inbound: []*v1alpha1.Dataplane_Networking_Inbound{
{
Port: 1234,
Tags: map[string]string{
"service": "backend",
"version": "v1",
"tagcolumn": "tag:v",
},
},
},
},
},
}
err := resourceStore.Create(context.Background(), &dpResource, store.CreateByKey("dp-no-insights", "mesh1"), store.CreatedAt(t1))
Expect(err).ToNot(HaveOccurred())
})

gatewayDelegatedJson := `
Expand Down Expand Up @@ -242,8 +265,7 @@ var _ = Describe("Dataplane Overview Endpoints", func() {
Expect(response.StatusCode).To(Equal(200))
body, err := io.ReadAll(response.Body)
Expect(err).ToNot(HaveOccurred())

Expect(string(body)).To(MatchJSON(tc.expectedJson))
Expect(body).To(matchers.MatchGoldenJSON("testdata", strings.ReplaceAll(tc.url, "/", "_")+".json"))
},
Entry("should list all when no tag is provided", testCase{
url: "/meshes/mesh1/dataplanes+insights",
Expand Down Expand Up @@ -300,7 +322,13 @@ var _ = Describe("Dataplane Overview Endpoints", func() {
Expect(response.StatusCode).To(Equal(200))
body, err := io.ReadAll(response.Body)
Expect(err).ToNot(HaveOccurred())
Expect(string(body)).To(MatchJSON(fmt.Sprintf(`{"total": 3, "items": [%s], "next": "http://%s/meshes/mesh1/dataplanes+insights?offset=1&size=1"}`, dp1Json, apiServer.Address())))
overviewList := rest.ResourceListReceiver{
NewResource: func() model.Resource {
return core_mesh.NewDataplaneOverviewResource()
},
}
Expect(overviewList.UnmarshalJSON(body)).To(Succeed())
Expect(*overviewList.Next).To(Equal(fmt.Sprintf(`http://%s/meshes/mesh1/dataplanes+insights?offset=1&size=1`, apiServer.Address())))
})
})
})
133 changes: 133 additions & 0 deletions pkg/api-server/testdata/_meshes_mesh1_dataplanes+insights.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
{
"total": 4,
"items": [
{
"type": "DataplaneOverview",
"mesh": "mesh1",
"name": "dp-1",
"creationTime": "2018-07-17T16:05:36.995Z",
"modificationTime": "2018-07-17T16:05:36.995Z",
"dataplane": {
"networking": {
"address": "127.0.0.1",
"inbound": [
{
"port": 1234,
"tags": {
"service": "backend",
"tagcolumn": "tag:v",
"version": "v1"
}
}
]
}
},
"dataplaneInsight": {
"subscriptions": [
{
"id": "stream-id-1",
"controlPlaneInstanceId": "cp-1",
"connectTime": "2019-07-01T00:00:00Z",
"status": {
"total": {},
"cds": {},
"eds": {},
"lds": {},
"rds": {}
}
}
]
}
},
{
"type": "DataplaneOverview",
"mesh": "mesh1",
"name": "dp-no-insights",
"creationTime": "2018-07-17T16:05:36.995Z",
"modificationTime": "2018-07-17T16:05:36.995Z",
"dataplane": {
"networking": {
"address": "127.0.0.1",
"inbound": [
{
"port": 1234,
"tags": {
"service": "backend",
"tagcolumn": "tag:v",
"version": "v1"
}
}
]
}
}
},
{
"type": "DataplaneOverview",
"mesh": "mesh1",
"name": "gateway-builtin",
"creationTime": "2018-07-17T16:05:36.995Z",
"modificationTime": "2018-07-17T16:05:36.995Z",
"dataplane": {
"networking": {
"address": "127.0.0.1",
"gateway": {
"tags": {
"service": "gateway"
},
"type": "BUILTIN"
}
}
},
"dataplaneInsight": {
"subscriptions": [
{
"id": "stream-id-1",
"controlPlaneInstanceId": "cp-1",
"connectTime": "2019-07-01T00:00:00Z",
"status": {
"total": {},
"cds": {},
"eds": {},
"lds": {},
"rds": {}
}
}
]
}
},
{
"type": "DataplaneOverview",
"mesh": "mesh1",
"name": "gateway-delegated",
"creationTime": "2018-07-17T16:05:36.995Z",
"modificationTime": "2018-07-17T16:05:36.995Z",
"dataplane": {
"networking": {
"address": "127.0.0.1",
"gateway": {
"tags": {
"service": "gateway"
}
}
}
},
"dataplaneInsight": {
"subscriptions": [
{
"id": "stream-id-1",
"controlPlaneInstanceId": "cp-1",
"connectTime": "2019-07-01T00:00:00Z",
"status": {
"total": {},
"cds": {},
"eds": {},
"lds": {},
"rds": {}
}
}
]
}
}
],
"next": null
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{
"total": 1,
"items": [
{
"type": "DataplaneOverview",
"mesh": "mesh1",
"name": "gateway-builtin",
"creationTime": "2018-07-17T16:05:36.995Z",
"modificationTime": "2018-07-17T16:05:36.995Z",
"dataplane": {
"networking": {
"address": "127.0.0.1",
"gateway": {
"tags": {
"service": "gateway"
},
"type": "BUILTIN"
}
}
},
"dataplaneInsight": {
"subscriptions": [
{
"id": "stream-id-1",
"controlPlaneInstanceId": "cp-1",
"connectTime": "2019-07-01T00:00:00Z",
"status": {
"total": {},
"cds": {},
"eds": {},
"lds": {},
"rds": {}
}
}
]
}
}
],
"next": null
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"total": 1,
"items": [
{
"type": "DataplaneOverview",
"mesh": "mesh1",
"name": "gateway-delegated",
"creationTime": "2018-07-17T16:05:36.995Z",
"modificationTime": "2018-07-17T16:05:36.995Z",
"dataplane": {
"networking": {
"address": "127.0.0.1",
"gateway": {
"tags": {
"service": "gateway"
}
}
}
},
"dataplaneInsight": {
"subscriptions": [
{
"id": "stream-id-1",
"controlPlaneInstanceId": "cp-1",
"connectTime": "2019-07-01T00:00:00Z",
"status": {
"total": {},
"cds": {},
"eds": {},
"lds": {},
"rds": {}
}
}
]
}
}
],
"next": null
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
{
"total": 2,
"items": [
{
"type": "DataplaneOverview",
"mesh": "mesh1",
"name": "gateway-builtin",
"creationTime": "2018-07-17T16:05:36.995Z",
"modificationTime": "2018-07-17T16:05:36.995Z",
"dataplane": {
"networking": {
"address": "127.0.0.1",
"gateway": {
"tags": {
"service": "gateway"
},
"type": "BUILTIN"
}
}
},
"dataplaneInsight": {
"subscriptions": [
{
"id": "stream-id-1",
"controlPlaneInstanceId": "cp-1",
"connectTime": "2019-07-01T00:00:00Z",
"status": {
"total": {},
"cds": {},
"eds": {},
"lds": {},
"rds": {}
}
}
]
}
},
{
"type": "DataplaneOverview",
"mesh": "mesh1",
"name": "gateway-delegated",
"creationTime": "2018-07-17T16:05:36.995Z",
"modificationTime": "2018-07-17T16:05:36.995Z",
"dataplane": {
"networking": {
"address": "127.0.0.1",
"gateway": {
"tags": {
"service": "gateway"
}
}
}
},
"dataplaneInsight": {
"subscriptions": [
{
"id": "stream-id-1",
"controlPlaneInstanceId": "cp-1",
"connectTime": "2019-07-01T00:00:00Z",
"status": {
"total": {},
"cds": {},
"eds": {},
"lds": {},
"rds": {}
}
}
]
}
}
],
"next": null
}
Loading