-
Notifications
You must be signed in to change notification settings - Fork 1k
check resize mode on update events #1194
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
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
b4ba102
check resize mode on update events
FxKu 705785e
Merge branch 'master' into storage-resize-fixes
FxKu eacb11a
add unit test for PVC resizing
FxKu 58984ca
set resize mode to pvc in charts and manifests
FxKu 84b3063
add test for quantityToGigabyte
FxKu fe12184
just one debug line for syncing volumes
FxKu abe7b39
Merge branch 'master' into storage-resize-fixes
FxKu 8d67c78
extend test and update log msg
FxKu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,171 @@ | ||
package cluster | ||
|
||
import ( | ||
"testing" | ||
|
||
"context" | ||
|
||
v1 "k8s.io/api/core/v1" | ||
"k8s.io/apimachinery/pkg/api/resource" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"k8s.io/apimachinery/pkg/labels" | ||
|
||
"github.com/stretchr/testify/assert" | ||
acidv1 "github.com/zalando/postgres-operator/pkg/apis/acid.zalan.do/v1" | ||
"github.com/zalando/postgres-operator/pkg/util/config" | ||
"github.com/zalando/postgres-operator/pkg/util/constants" | ||
"github.com/zalando/postgres-operator/pkg/util/k8sutil" | ||
"k8s.io/client-go/kubernetes/fake" | ||
) | ||
|
||
func NewFakeKubernetesClient() (k8sutil.KubernetesClient, *fake.Clientset) { | ||
clientSet := fake.NewSimpleClientset() | ||
|
||
return k8sutil.KubernetesClient{ | ||
PersistentVolumeClaimsGetter: clientSet.CoreV1(), | ||
}, clientSet | ||
} | ||
|
||
func TestResizeVolumeClaim(t *testing.T) { | ||
testName := "test resizing of persistent volume claims" | ||
client, _ := NewFakeKubernetesClient() | ||
clusterName := "acid-test-cluster" | ||
namespace := "default" | ||
newVolumeSize := "2Gi" | ||
|
||
// new cluster with pvc storage resize mode and configured labels | ||
var cluster = New( | ||
Config{ | ||
OpConfig: config.Config{ | ||
Resources: config.Resources{ | ||
ClusterLabels: map[string]string{"application": "spilo"}, | ||
ClusterNameLabel: "cluster-name", | ||
}, | ||
StorageResizeMode: "pvc", | ||
}, | ||
}, client, acidv1.Postgresql{}, logger, eventRecorder) | ||
|
||
// set metadata, so that labels will get correct values | ||
cluster.Name = clusterName | ||
cluster.Namespace = namespace | ||
filterLabels := cluster.labelsSet(false) | ||
|
||
// define and create PVCs for 1Gi volumes | ||
storage1Gi, err := resource.ParseQuantity("1Gi") | ||
assert.NoError(t, err) | ||
|
||
pvcList := &v1.PersistentVolumeClaimList{ | ||
Items: []v1.PersistentVolumeClaim{ | ||
{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: constants.DataVolumeName + "-" + clusterName + "-0", | ||
Namespace: namespace, | ||
Labels: filterLabels, | ||
}, | ||
Spec: v1.PersistentVolumeClaimSpec{ | ||
Resources: v1.ResourceRequirements{ | ||
Requests: v1.ResourceList{ | ||
v1.ResourceStorage: storage1Gi, | ||
}, | ||
}, | ||
}, | ||
}, | ||
{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: constants.DataVolumeName + "-" + clusterName + "-1", | ||
Namespace: namespace, | ||
Labels: filterLabels, | ||
}, | ||
Spec: v1.PersistentVolumeClaimSpec{ | ||
Resources: v1.ResourceRequirements{ | ||
Requests: v1.ResourceList{ | ||
v1.ResourceStorage: storage1Gi, | ||
}, | ||
}, | ||
}, | ||
}, | ||
{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: constants.DataVolumeName + "-" + clusterName + "-2-0", | ||
Namespace: namespace, | ||
Labels: labels.Set{}, | ||
}, | ||
Spec: v1.PersistentVolumeClaimSpec{ | ||
Resources: v1.ResourceRequirements{ | ||
Requests: v1.ResourceList{ | ||
v1.ResourceStorage: storage1Gi, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
for _, pvc := range pvcList.Items { | ||
cluster.KubeClient.PersistentVolumeClaims(namespace).Create(context.TODO(), &pvc, metav1.CreateOptions{}) | ||
} | ||
|
||
// test resizing | ||
cluster.resizeVolumeClaims(acidv1.Volume{Size: newVolumeSize}) | ||
|
||
pvcs, err := cluster.listPersistentVolumeClaims() | ||
assert.NoError(t, err) | ||
|
||
// check if listPersistentVolumeClaims returns only the PVCs matching the filter | ||
if len(pvcs) != len(pvcList.Items)-1 { | ||
t.Errorf("%s: could not find all PVCs, got %v, expected %v", testName, len(pvcs), len(pvcList.Items)-1) | ||
} | ||
|
||
// check if PVCs were correctly resized | ||
for _, pvc := range pvcs { | ||
newStorageSize := quantityToGigabyte(pvc.Spec.Resources.Requests[v1.ResourceStorage]) | ||
expectedQuantity, err := resource.ParseQuantity(newVolumeSize) | ||
assert.NoError(t, err) | ||
expectedSize := quantityToGigabyte(expectedQuantity) | ||
if newStorageSize != expectedSize { | ||
t.Errorf("%s: resizing failed, got %v, expected %v", testName, newStorageSize, expectedSize) | ||
} | ||
} | ||
|
||
// check if other PVC was not resized | ||
pvc2, err := cluster.KubeClient.PersistentVolumeClaims(namespace).Get(context.TODO(), constants.DataVolumeName+"-"+clusterName+"-2-0", metav1.GetOptions{}) | ||
assert.NoError(t, err) | ||
unchangedSize := quantityToGigabyte(pvc2.Spec.Resources.Requests[v1.ResourceStorage]) | ||
expectedSize := quantityToGigabyte(storage1Gi) | ||
if unchangedSize != expectedSize { | ||
t.Errorf("%s: volume size changed, got %v, expected %v", testName, unchangedSize, expectedSize) | ||
} | ||
} | ||
|
||
func TestQuantityToGigabyte(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
quantityStr string | ||
expected int64 | ||
}{ | ||
{ | ||
"test with 1Gi", | ||
"1Gi", | ||
1, | ||
}, | ||
{ | ||
"test with float", | ||
"1.5Gi", | ||
int64(1), | ||
}, | ||
{ | ||
"test with 1000Mi", | ||
"1000Mi", | ||
int64(0), | ||
}, | ||
} | ||
|
||
for _, tt := range tests { | ||
quantity, err := resource.ParseQuantity(tt.quantityStr) | ||
assert.NoError(t, err) | ||
gigabyte := quantityToGigabyte(quantity) | ||
if gigabyte != tt.expected { | ||
t.Errorf("%s: got %v, expected %v", tt.name, gigabyte, tt.expected) | ||
} | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.