Skip to content

Commit

Permalink
use MaxUnavailable in PDB (#30)
Browse files Browse the repository at this point in the history
If user set both of MinAvailable and MaxUnavailable in PDP - it's a critical error, on validation step will use only MaxUnavailable value

Signed-off-by: Maksim Paskal <[email protected]>
  • Loading branch information
maksim-paskal authored Jul 8, 2024
1 parent 3340421 commit 75b45ed
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 2 deletions.
13 changes: 12 additions & 1 deletion pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,7 @@ type Type struct {
Metadata map[string]string
}

func (t *Type) Normalize() {
func (t *Type) Normalize() { //nolint:cyclop
setBudgetInSeconds := func(a []*PromQLMetric) {
localDefaultBudgetInSeconds := defaultBudgetInSeconds

Expand All @@ -498,6 +498,11 @@ func (t *Type) Normalize() {
setBudgetInSeconds(t.Canary.Phase2.QualityGate.BadSamplesMetrics)
setBudgetInSeconds(t.Canary.Phase2.QualityGate.TotalSamplesMetrics)

// if user set both values, we need to use only one
if t.Pdb.MinAvailable > 0 && t.Pdb.MaxUnavailable > 0 {
t.Pdb.MinAvailable = 0
}

for _, deployment := range t.Deployments {
if deployment.MinReplicas == 0 {
deployment.MinReplicas = t.MinReplicas
Expand All @@ -512,6 +517,12 @@ func (t *Type) Normalize() {
deployment.Hpa.AverageUtilization = defaultAverageUtilization
}
}

if deployment.Pdb != nil {
if deployment.Pdb.MinAvailable > 0 && deployment.Pdb.MaxUnavailable > 0 {
deployment.Pdb.MinAvailable = 0
}
}
}
}

Expand Down
20 changes: 19 additions & 1 deletion pkg/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
"github.com/maksim-paskal/helm-blue-green/pkg/types"
)

func TestConfig(t *testing.T) {
func TestConfig(t *testing.T) { //nolint:cyclop
ctx := context.Background()

t.Setenv("NAMESPACE", "default")
Expand Down Expand Up @@ -63,6 +63,24 @@ func TestConfig(t *testing.T) {
if want := int32(22); want != config.Get().Deployments[1].MinReplicas {
t.Fatalf("MinReplicas for 0 is not %d", want)
}

if !(config.Get().Pdb.MinAvailable == 0 && config.Get().Pdb.MaxUnavailable == 2) {
t.Fatal("Pdb is not 0/2")
}

d := config.Get().Deployments

if len(d) != 2 {
t.Fatal("Deployments length is not 2")
}

if !(d[0].Pdb.MinAvailable == 0 && d[0].Pdb.MaxUnavailable == 2) {
t.Fatal("Pdb is not 0/2")
}

if !(d[1].Pdb.MinAvailable == 3 && d[1].Pdb.MaxUnavailable == 0) {
t.Fatal("Pdb is not 3/0")
}
}

func TestHasPhases(t *testing.T) {
Expand Down
7 changes: 7 additions & 0 deletions pkg/config/testdata/test_config.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
name: testName

pdb:
minAvailable: 1
maxUnavailable: 2

deployments:
- name: test01
- name: test02
pdb:
minAvailable: 3
maxUnavailable: 0

services:
- name: test01
Expand Down

0 comments on commit 75b45ed

Please sign in to comment.