-
Notifications
You must be signed in to change notification settings - Fork 335
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(kuma-cp) stop components on leader election lost (#2318)
Signed-off-by: Jakub Dyszkiewicz <jakub.dyszkiewicz@gmail.com> (cherry picked from commit 1c6a7c2)
- Loading branch information
1 parent
02f7644
commit 17459ab
Showing
12 changed files
with
192 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
package resilience | ||
|
||
import ( | ||
"github.com/kumahq/kuma/pkg/config/core" | ||
. "github.com/kumahq/kuma/test/framework" | ||
"github.com/kumahq/kuma/test/framework/deployments/postgres" | ||
|
||
. "github.com/onsi/ginkgo" | ||
. "github.com/onsi/gomega" | ||
) | ||
|
||
func LeaderElectionPostgres() { | ||
var standalone1, standalone2 Cluster | ||
var standalone1Opts, standalone2Opts []DeployOptionsFunc | ||
|
||
BeforeEach(func() { | ||
clusters, err := NewUniversalClusters( | ||
[]string{Kuma1, Kuma2}, | ||
Silent) | ||
Expect(err).ToNot(HaveOccurred()) | ||
standalone1 = clusters.GetCluster(Kuma1) | ||
standalone2 = clusters.GetCluster(Kuma2) | ||
|
||
err = NewClusterSetup(). | ||
Install(postgres.Install(Kuma1)). | ||
Setup(standalone1) | ||
Expect(err).ToNot(HaveOccurred()) | ||
postgresInstance := postgres.From(standalone1, Kuma1) | ||
|
||
// Standalone 1 | ||
standalone1Opts = KumaUniversalDeployOpts | ||
standalone1Opts = append(standalone1Opts, WithPostgres(postgresInstance.GetEnvVars())) | ||
|
||
err = NewClusterSetup(). | ||
Install(Kuma(core.Standalone, standalone1Opts...)). | ||
Setup(standalone1) | ||
|
||
Expect(err).ToNot(HaveOccurred()) | ||
Expect(standalone1.VerifyKuma()).To(Succeed()) | ||
|
||
// Standalone 2 | ||
standalone2Opts = KumaUniversalDeployOpts | ||
standalone2Opts = append(standalone2Opts, WithPostgres(postgresInstance.GetEnvVars())) | ||
|
||
err = NewClusterSetup(). | ||
Install(Kuma(core.Standalone, standalone2Opts...)). | ||
Setup(standalone2) | ||
|
||
Expect(err).ToNot(HaveOccurred()) | ||
Expect(standalone2.VerifyKuma()).To(Succeed()) | ||
}) | ||
|
||
E2EAfterEach(func() { | ||
err := standalone1.DeleteKuma(standalone1Opts...) | ||
Expect(err).ToNot(HaveOccurred()) | ||
err = standalone1.DismissCluster() | ||
Expect(err).ToNot(HaveOccurred()) | ||
|
||
err = standalone2.DeleteKuma(standalone2Opts...) | ||
Expect(err).ToNot(HaveOccurred()) | ||
err = standalone2.DismissCluster() | ||
Expect(err).ToNot(HaveOccurred()) | ||
}) | ||
|
||
It("should elect only one leader and drop the leader on DB disconnect", func() { | ||
// given two instances of the control plane connected to one postgres, only one is a leader | ||
Eventually(func() (string, error) { | ||
return standalone1.GetKuma().GetMetrics() | ||
}, "30s", "1s").Should(ContainSubstring(`leader{zone="Standalone"} 1`)) | ||
|
||
metrics, err := standalone2.GetKuma().GetMetrics() | ||
Expect(err).ToNot(HaveOccurred()) | ||
Expect(metrics).To(ContainSubstring(`leader{zone="Standalone"} 0`)) | ||
|
||
// when CP 1 is killed | ||
_, _, err = standalone1.Exec("", "", AppModeCP, "pkill", "-9", "kuma-cp") | ||
Expect(err).ToNot(HaveOccurred()) | ||
|
||
// then CP 2 is leader | ||
Eventually(func() (string, error) { | ||
return standalone2.GetKuma().GetMetrics() | ||
}, "30s", "1s").Should(ContainSubstring(`leader{zone="Standalone"} 1`)) | ||
|
||
// when postgres is down | ||
err = standalone1.DeleteDeployment(postgres.AppPostgres + Kuma1) | ||
Expect(err).ToNot(HaveOccurred()) | ||
|
||
// then CP 2 is not a leader anymore | ||
Eventually(func() (string, error) { | ||
return standalone2.GetKuma().GetMetrics() | ||
}, "30s", "1s").Should(ContainSubstring(`leader{zone="Standalone"} 0`)) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package resilience_test | ||
|
||
import ( | ||
"github.com/kumahq/kuma/test/e2e/resilience" | ||
|
||
. "github.com/onsi/ginkgo" | ||
) | ||
|
||
var _ = Describe("Test Leader Election with Postgres", resilience.LeaderElectionPostgres) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters