Skip to content

Commit

Permalink
fix(kumactl) gateway status was always reporting offline (#1946)
Browse files Browse the repository at this point in the history
Signed-off-by: Jakub Dyszkiewicz <jakub.dyszkiewicz@gmail.com>
  • Loading branch information
jakubdyszkiewicz authored May 6, 2021
1 parent df98a5d commit 55b380a
Show file tree
Hide file tree
Showing 2 changed files with 190 additions and 0 deletions.
4 changes: 4 additions & 0 deletions pkg/core/resources/apis/mesh/dataplane_overview_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ func (t *DataplaneOverviewResource) GetStatus() (Status, []string) {

allInboundsOffline := len(errs) == len(t.Spec.Dataplane.Networking.Inbound)
allInboundsOnline := len(errs) == 0
if t.Spec.Dataplane.DpType() == mesh_proto.GatewayDpType {
allInboundsOffline = false
allInboundsOnline = true
}

if !proxyOnline || allInboundsOffline {
return Offline, errs
Expand Down
186 changes: 186 additions & 0 deletions pkg/core/resources/apis/mesh/dataplane_overview_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@ package mesh_test

import (
. "github.com/onsi/ginkgo"
. "github.com/onsi/ginkgo/extensions/table"
. "github.com/onsi/gomega"

mesh_proto "github.com/kumahq/kuma/api/mesh/v1alpha1"
"github.com/kumahq/kuma/pkg/core"
. "github.com/kumahq/kuma/pkg/core/resources/apis/mesh"
. "github.com/kumahq/kuma/pkg/test/matchers"
"github.com/kumahq/kuma/pkg/test/resources/model"
"github.com/kumahq/kuma/pkg/util/proto"
)

var _ = Describe("DataplaneOverview", func() {
Expand Down Expand Up @@ -49,4 +52,187 @@ var _ = Describe("DataplaneOverview", func() {
Expect(overviews.Items[1].Spec.DataplaneInsight).To(BeNil())
})
})

Context("GetStatus", func() {
type testCase struct {
overview *mesh_proto.DataplaneOverview
status Status
errReasons []string
}

DescribeTable("should compute status",
func(given testCase) {
// given
resource := NewDataplaneOverviewResource()
resource.Spec = given.overview

// when
status, errReasons := resource.GetStatus()

// then
Expect(status).To(Equal(given.status))
Expect(errReasons).To(Equal(given.errReasons))
},
Entry("online when proxy is connected and health is nil", testCase{
overview: &mesh_proto.DataplaneOverview{
Dataplane: &mesh_proto.Dataplane{
Networking: &mesh_proto.Dataplane_Networking{
Inbound: []*mesh_proto.Dataplane_Networking_Inbound{
{
Health: nil,
},
},
},
},
DataplaneInsight: &mesh_proto.DataplaneInsight{
Subscriptions: []*mesh_proto.DiscoverySubscription{
{
ConnectTime: proto.MustTimestampProto(core.Now()),
},
},
},
},
status: Online,
}),
Entry("online when proxy is connected and health is ready", testCase{
overview: &mesh_proto.DataplaneOverview{
Dataplane: &mesh_proto.Dataplane{
Networking: &mesh_proto.Dataplane_Networking{
Inbound: []*mesh_proto.Dataplane_Networking_Inbound{
{
Health: &mesh_proto.Dataplane_Networking_Inbound_Health{
Ready: true,
},
},
},
},
},
DataplaneInsight: &mesh_proto.DataplaneInsight{
Subscriptions: []*mesh_proto.DiscoverySubscription{
{
ConnectTime: proto.MustTimestampProto(core.Now()),
},
},
},
},
status: Online,
}),
Entry("online when proxy is connected and is gateway", testCase{
overview: &mesh_proto.DataplaneOverview{
Dataplane: &mesh_proto.Dataplane{
Networking: &mesh_proto.Dataplane_Networking{
Gateway: &mesh_proto.Dataplane_Networking_Gateway{},
},
},
DataplaneInsight: &mesh_proto.DataplaneInsight{
Subscriptions: []*mesh_proto.DiscoverySubscription{
{
ConnectTime: proto.MustTimestampProto(core.Now()),
},
},
},
},
status: Online,
}),
Entry("offline when proxy is not connected even that inbound is ready", testCase{
overview: &mesh_proto.DataplaneOverview{
Dataplane: &mesh_proto.Dataplane{
Networking: &mesh_proto.Dataplane_Networking{
Inbound: []*mesh_proto.Dataplane_Networking_Inbound{
{
Health: &mesh_proto.Dataplane_Networking_Inbound_Health{
Ready: true,
},
},
},
},
},
DataplaneInsight: &mesh_proto.DataplaneInsight{
Subscriptions: []*mesh_proto.DiscoverySubscription{
{
ConnectTime: proto.MustTimestampProto(core.Now()),
DisconnectTime: proto.MustTimestampProto(core.Now()),
},
},
},
},
status: Offline,
}),
Entry("offline when proxy is connected but all inbounds are not ready", testCase{
overview: &mesh_proto.DataplaneOverview{
Dataplane: &mesh_proto.Dataplane{
Networking: &mesh_proto.Dataplane_Networking{
Inbound: []*mesh_proto.Dataplane_Networking_Inbound{
{
Health: &mesh_proto.Dataplane_Networking_Inbound_Health{
Ready: false,
},
},
},
},
},
DataplaneInsight: &mesh_proto.DataplaneInsight{
Subscriptions: []*mesh_proto.DiscoverySubscription{
{
ConnectTime: proto.MustTimestampProto(core.Now()),
},
},
},
},
status: Offline,
errReasons: []string{
"inbound[port=0,svc=] is not ready",
},
}),
Entry("online when proxy is disconnected and is a gateway", testCase{
overview: &mesh_proto.DataplaneOverview{
Dataplane: &mesh_proto.Dataplane{
Networking: &mesh_proto.Dataplane_Networking{
Gateway: &mesh_proto.Dataplane_Networking_Gateway{},
},
},
DataplaneInsight: &mesh_proto.DataplaneInsight{
Subscriptions: []*mesh_proto.DiscoverySubscription{
{
ConnectTime: proto.MustTimestampProto(core.Now()),
DisconnectTime: proto.MustTimestampProto(core.Now()),
},
},
},
},
status: Offline,
}),
Entry("partially degraded when proxy is connected and one inbound is ready but other is not", testCase{
overview: &mesh_proto.DataplaneOverview{
Dataplane: &mesh_proto.Dataplane{
Networking: &mesh_proto.Dataplane_Networking{
Inbound: []*mesh_proto.Dataplane_Networking_Inbound{
{
Health: &mesh_proto.Dataplane_Networking_Inbound_Health{
Ready: true,
},
},
{
Health: &mesh_proto.Dataplane_Networking_Inbound_Health{
Ready: false,
},
},
},
},
},
DataplaneInsight: &mesh_proto.DataplaneInsight{
Subscriptions: []*mesh_proto.DiscoverySubscription{
{
ConnectTime: proto.MustTimestampProto(core.Now()),
},
},
},
},
status: PartiallyDegraded,
errReasons: []string{
"inbound[port=0,svc=] is not ready",
},
}),
)
})
})

0 comments on commit 55b380a

Please sign in to comment.