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

PWX-36258 : Do not allow pdb annotation lesser than px quorum #1457

Merged
merged 1 commit into from
Feb 27, 2024
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
6 changes: 4 additions & 2 deletions drivers/storage/portworx/component/disruption_budget.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package component

import (
"math"
"strconv"

"github.com/hashicorp/go-version"
Expand Down Expand Up @@ -119,9 +120,10 @@ func (c *disruptionBudget) createPortworxPodDisruptionBudget(
}

// Set minAvailable value to storagenodes-1 if no value is provided,
// or if the user provided value is lesser than 0
// or if the user provided value is lesser storageNodes/2 +1 (px quorum)
// or greater than or equal to the number of storage nodes.
if userProvidedMinValue < 0 || userProvidedMinValue >= storageNodesCount {
quorumValue := math.Floor(float64(storageNodesCount)/2) + 1
if userProvidedMinValue < int(quorumValue) || userProvidedMinValue >= storageNodesCount {
logrus.Warnf("Value for px-storage pod disruption budget not provided or is invalid, using default calculated value %d: ", storageNodesCount-1)
minAvailable = storageNodesCount - 1
} else {
Expand Down
16 changes: 15 additions & 1 deletion drivers/storage/portworx/components_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ import (
"context"
"encoding/json"
"fmt"
routev1 "github.com/openshift/api/route/v1"
"math/rand"
"strconv"
"strings"
"testing"
"time"

routev1 "github.com/openshift/api/route/v1"

"github.com/golang-jwt/jwt/v4"
"github.com/golang/mock/gomock"
ocpconfig "github.com/openshift/api/config/v1"
Expand Down Expand Up @@ -12518,6 +12519,19 @@ func TestPodDisruptionBudgetEnabled(t *testing.T) {

require.Equal(t, 4, storagePDB.Spec.MinAvailable.IntValue())

// TestCase: When annotation to override PDB value is lesser than num(storagenodes)/2 +1
// Ignore annotation and use default PDB calculation
cluster.Annotations[pxutil.AnnotationStoragePodDisruptionBudget] = "2"

err = driver.PreInstall(cluster)
require.NoError(t, err)

storagePDB = &policyv1.PodDisruptionBudget{}
err = testutil.Get(k8sClient, storagePDB, component.StoragePodDisruptionBudgetName, cluster.Namespace)
require.NoError(t, err)

require.Equal(t, 4, storagePDB.Spec.MinAvailable.IntValue())

// TestCase: Use NonQuorumMember flag to determine storage node count
cluster.Annotations[pxutil.AnnotationStoragePodDisruptionBudget] = ""
expectedNodeEnumerateResp.Nodes = []*osdapi.StorageNode{
Expand Down
Loading