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(kumactl) gateway status was always reporting offline #1946

Merged
merged 2 commits into from
May 6, 2021
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
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",
},
}),
)
})
})