Skip to content

Commit

Permalink
Two replica failure support FTT=2 (pravega#464)
Browse files Browse the repository at this point in the history
Signed-off-by: Maxim Ferapontov <[email protected]>
  • Loading branch information
Maxim Ferapontov authored and Maxim Ferapontov committed Apr 18, 2022
1 parent 46bef88 commit 4cd62ad
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 25 deletions.
4 changes: 4 additions & 0 deletions pkg/zk/generators.go
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,10 @@ func makeService(name string, ports []v1.ServicePort, clusterIP bool, external b
// MakePodDisruptionBudget returns a pdb for the zookeeper cluster
func MakePodDisruptionBudget(z *v1beta1.ZookeeperCluster) *policyv1beta1.PodDisruptionBudget {
pdbCount := intstr.FromInt(1)
// Support FTT=2 with 5 or more replicas
if z.Spec.Replicas >= 5 {
pdbCount = intstr.FromInt(2)
}
return &policyv1beta1.PodDisruptionBudget{
TypeMeta: metav1.TypeMeta{
Kind: "PodDisruptionBudget",
Expand Down
104 changes: 79 additions & 25 deletions pkg/zk/generators_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -564,37 +564,91 @@ var _ = Describe("Generators Spec", func() {
var domainName string
var zkClusterName string

BeforeEach(func() {
domainName = "zk.com."
z := &v1beta1.ZookeeperCluster{
ObjectMeta: metav1.ObjectMeta{
Name: "example",
Namespace: "default",
},
Spec: v1beta1.ZookeeperClusterSpec{
DomainName: domainName,
Labels: map[string]string{
"exampleLabel": "exampleValue",
Context("general check", func() {
BeforeEach(func() {
domainName = "zk.com."
z := &v1beta1.ZookeeperCluster{
ObjectMeta: metav1.ObjectMeta{
Name: "example",
Namespace: "default",
},
},
}
z.WithDefaults()
pdb = zk.MakePodDisruptionBudget(z)
zkClusterName = z.GetName()
})
Spec: v1beta1.ZookeeperClusterSpec{
DomainName: domainName,
Labels: map[string]string{
"exampleLabel": "exampleValue",
},
},
}
z.WithDefaults()
pdb = zk.MakePodDisruptionBudget(z)
zkClusterName = z.GetName()
})

It("should have kind PodDisruptionBudget", func() {
Ω(pdb.GetObjectKind().GroupVersionKind().Kind).To(Equal("PodDisruptionBudget"))
})

It("should have selector is zookeeper cluster name", func() {
Ω(pdb.Spec.Selector.MatchLabels["app"]).To(BeEquivalentTo(zkClusterName))
})

It("should have kind PodDisruptionBudget", func() {
Ω(pdb.GetObjectKind().GroupVersionKind().Kind).To(Equal("PodDisruptionBudget"))
It("should have custom labels set", func() {
Ω(pdb.GetLabels()).To(HaveKeyWithValue(
"exampleLabel",
"exampleValue"))
})
})

It("should have selector is zookeeper cluster name", func() {
Ω(pdb.Spec.Selector.MatchLabels["app"]).To(BeEquivalentTo(zkClusterName))
Context("small cluster", func() {
BeforeEach(func() {
domainName = "zk.com."
z := &v1beta1.ZookeeperCluster{
ObjectMeta: metav1.ObjectMeta{
Name: "example",
Namespace: "default",
},
Spec: v1beta1.ZookeeperClusterSpec{
Replicas: 4,
DomainName: domainName,
Labels: map[string]string{
"exampleLabel": "exampleValue",
},
},
}
z.WithDefaults()
pdb = zk.MakePodDisruptionBudget(z)
zkClusterName = z.GetName()
})

It("should have kind PodDisruptionBudget", func() {
Ω(pdb.Spec.MaxUnavailable.IntVal).To(BeEquivalentTo(1))
})
})

It("should have custom labels set", func() {
Ω(pdb.GetLabels()).To(HaveKeyWithValue(
"exampleLabel",
"exampleValue"))
Context("large cluster", func() {
BeforeEach(func() {
domainName = "zk.com."
z := &v1beta1.ZookeeperCluster{
ObjectMeta: metav1.ObjectMeta{
Name: "example",
Namespace: "default",
},
Spec: v1beta1.ZookeeperClusterSpec{
Replicas: 5,
DomainName: domainName,
Labels: map[string]string{
"exampleLabel": "exampleValue",
},
},
}
z.WithDefaults()
pdb = zk.MakePodDisruptionBudget(z)
zkClusterName = z.GetName()
})

It("should have kind PodDisruptionBudget", func() {
Ω(pdb.Spec.MaxUnavailable.IntVal).To(BeEquivalentTo(2))
})
})
})
})

0 comments on commit 4cd62ad

Please sign in to comment.