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(kuma-cp): make zone insight context independent from parent #6909

Merged
merged 3 commits into from
Jun 2, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
11 changes: 10 additions & 1 deletion pkg/kds/server/status_sink.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
core_model "github.com/kumahq/kuma/pkg/core/resources/model"
"github.com/kumahq/kuma/pkg/core/resources/store"
"github.com/kumahq/kuma/pkg/core/user"
"github.com/kumahq/kuma/pkg/multitenant"
)

type ZoneInsightSink interface {
Expand Down Expand Up @@ -55,6 +56,13 @@ func (s *zoneInsightSink) Start(ctx context.Context, stop <-chan struct{}) {
var lastStoredState *system_proto.KDSSubscription
var generation uint32

gracefulCtx, cancel := context.WithCancel(context.Background())
defer cancel()
tenantId, ok := multitenant.TenantFromCtx(ctx)
if ok {
gracefulCtx = multitenant.WithTenant(gracefulCtx, tenantId)
}

flush := func() {
zone, currentState := s.accessor.GetStatus()
select {
Expand All @@ -67,7 +75,7 @@ func (s *zoneInsightSink) Start(ctx context.Context, stop <-chan struct{}) {
return
}

if err := s.store.Upsert(ctx, zone, currentState); err != nil {
if err := s.store.Upsert(gracefulCtx, zone, currentState); err != nil {
if store.IsResourceConflict(err) {
s.log.V(1).Info("failed to flush ZoneInsight because it was updated in other place. Will retry in the next tick", "zone", zone)
} else {
Expand All @@ -85,6 +93,7 @@ func (s *zoneInsightSink) Start(ctx context.Context, stop <-chan struct{}) {
flush()
case <-stop:
flush()
cancel()
lukidzi marked this conversation as resolved.
Show resolved Hide resolved
return
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,4 +160,20 @@ func ResilienceMultizoneUniversalPostgres() {
return zoneUniversal.GetKumactlOptions().RunKumactlAndGetOutput("inspect", "zone-ingresses")
}, "40s", "1s").Should(ContainSubstring("Offline"))
})

It("should mark zone as offline when zone control-plane is down", func() {
// given zone connected to global
Eventually(func() (string, error) {
return global.GetKumactlOptions().RunKumactlAndGetOutput("inspect", "zones")
}, "30s", "1s").Should(ContainSubstring("Online"))

// when Zone CP is killed
_, _, err := zoneUniversal.Exec("", "", AppModeCP, "pkill", "-9", "kuma-cp")
Expect(err).ToNot(HaveOccurred())

// then zone is offline immediately
Eventually(func() (string, error) {
return global.GetKumactlOptions().RunKumactlAndGetOutput("inspect", "zones")
}, "10s", "1s").Should(ContainSubstring("Offline"))
})
}