@@ -155,7 +155,7 @@ func AssertSwitchover(namespace string, clusterName string, env *testsUtils.Test
155
155
156
156
// AssertCreateCluster tests that the pods that should have been created by the sample
157
157
// exist and are in ready state
158
- func AssertCreateCluster (namespace string , clusterName string , sample string , env * testsUtils.TestingEnvironment ) {
158
+ func AssertCreateCluster (namespace string , clusterName string , sampleFile string , env * testsUtils.TestingEnvironment ) {
159
159
By (fmt .Sprintf ("having a %v namespace" , namespace ), func () {
160
160
// Creating a namespace should be quick
161
161
timeout := 20
@@ -172,8 +172,7 @@ func AssertCreateCluster(namespace string, clusterName string, sample string, en
172
172
})
173
173
174
174
By (fmt .Sprintf ("creating a Cluster in the %v namespace" , namespace ), func () {
175
- _ , _ , err := testsUtils .Run ("kubectl create -n " + namespace + " -f " + sample )
176
- Expect (err ).ToNot (HaveOccurred ())
175
+ CreateResourceFromFile (namespace , sampleFile )
177
176
})
178
177
// Setting up a cluster with three pods is slow, usually 200-600s
179
178
AssertClusterIsReady (namespace , clusterName , 600 , env )
@@ -582,11 +581,7 @@ func AssertArchiveWalOnMinio(namespace, clusterName string) {
582
581
}
583
582
584
583
func AssertScheduledBackupsAreScheduled (namespace string , backupYAMLPath string , timeout int ) {
585
- _ , _ , err := testsUtils .Run (fmt .Sprintf (
586
- "kubectl apply -n %v -f %v" ,
587
- namespace , backupYAMLPath ))
588
- Expect (err ).NotTo (HaveOccurred ())
589
-
584
+ CreateResourceFromFile (namespace , backupYAMLPath )
590
585
scheduledBackupName , err := env .GetResourceNameFromYAML (backupYAMLPath )
591
586
Expect (err ).NotTo (HaveOccurred ())
592
587
@@ -801,11 +796,8 @@ func AssertFastFailOver(
801
796
}, timeout ).Should (BeEquivalentTo (namespace ))
802
797
})
803
798
804
- By (fmt .Sprintf ("creating a Cluster in the %v namespace" ,
805
- namespace ), func () {
806
- _ , _ , err = testsUtils .Run (
807
- "kubectl create -n " + namespace + " -f " + sampleFile )
808
- Expect (err ).ToNot (HaveOccurred ())
799
+ By (fmt .Sprintf ("creating a Cluster in the %v namespace" , namespace ), func () {
800
+ CreateResourceFromFile (namespace , sampleFile )
809
801
})
810
802
811
803
By ("having a Cluster with three instances ready" , func () {
@@ -1132,11 +1124,7 @@ func AssertClusterAsyncReplica(namespace, sourceClusterFile, restoreClusterFile,
1132
1124
By ("Async Replication into external cluster" , func () {
1133
1125
restoredClusterName , err := env .GetResourceNameFromYAML (restoreClusterFile )
1134
1126
Expect (err ).ToNot (HaveOccurred ())
1135
- _ , _ , err = testsUtils .Run (fmt .Sprintf (
1136
- "kubectl apply -n %v -f %v" ,
1137
- namespace , restoreClusterFile ))
1138
- Expect (err ).ToNot (HaveOccurred ())
1139
-
1127
+ CreateResourceFromFile (namespace , restoreClusterFile )
1140
1128
// We give more time than the usual 600s, since the recovery is slower
1141
1129
AssertClusterIsReady (namespace , restoredClusterName , 800 , env )
1142
1130
@@ -1179,10 +1167,7 @@ func AssertClusterRestore(namespace, restoreClusterFile, tableName string) {
1179
1167
By ("Restoring a backup in a new cluster" , func () {
1180
1168
restoredClusterName , err := env .GetResourceNameFromYAML (restoreClusterFile )
1181
1169
Expect (err ).ToNot (HaveOccurred ())
1182
- _ , _ , err = testsUtils .Run (fmt .Sprintf (
1183
- "kubectl apply -n %v -f %v" ,
1184
- namespace , restoreClusterFile ))
1185
- Expect (err ).ToNot (HaveOccurred ())
1170
+ CreateResourceFromFile (namespace , restoreClusterFile )
1186
1171
1187
1172
// We give more time than the usual 600s, since the recovery is slower
1188
1173
AssertClusterIsReady (namespace , restoredClusterName , 800 , env )
@@ -1209,10 +1194,7 @@ func AssertScheduledBackupsImmediate(namespace, backupYAMLPath, scheduledBackupN
1209
1194
By ("scheduling immediate backups" , func () {
1210
1195
var err error
1211
1196
// Create the ScheduledBackup
1212
- _ , _ , err = testsUtils .Run (fmt .Sprintf (
1213
- "kubectl apply -n %v -f %v" ,
1214
- namespace , backupYAMLPath ))
1215
- Expect (err ).NotTo (HaveOccurred ())
1197
+ CreateResourceFromFile (namespace , backupYAMLPath )
1216
1198
1217
1199
// We expect the scheduled backup to be scheduled after creation
1218
1200
scheduledBackupNamespacedName := types.NamespacedName {
@@ -1243,10 +1225,15 @@ func AssertSuspendScheduleBackups(namespace, scheduledBackupName string) {
1243
1225
var err error
1244
1226
By ("suspending the scheduled backup" , func () {
1245
1227
// update suspend status to true
1246
- cmd := fmt .Sprintf ("kubectl patch ScheduledBackup %v -n %v -p '{\" spec\" :{\" suspend\" :true}}' " +
1247
- "--type='merge'" , scheduledBackupName , namespace )
1248
- _ , _ , err = testsUtils .Run (cmd )
1249
- Expect (err ).ToNot (HaveOccurred ())
1228
+ Eventually (func () error {
1229
+ cmd := fmt .Sprintf ("kubectl patch ScheduledBackup %v -n %v -p '{\" spec\" :{\" suspend\" :true}}' " +
1230
+ "--type='merge'" , scheduledBackupName , namespace )
1231
+ _ , _ , err = testsUtils .RunUnchecked (cmd )
1232
+ if err != nil {
1233
+ return err
1234
+ }
1235
+ return nil
1236
+ }, 60 , 5 ).Should (BeNil ())
1250
1237
scheduledBackupNamespacedName := types.NamespacedName {
1251
1238
Namespace : namespace ,
1252
1239
Name : scheduledBackupName ,
@@ -1286,11 +1273,15 @@ func AssertSuspendScheduleBackups(namespace, scheduledBackupName string) {
1286
1273
// take current backup count before suspend the schedule backup
1287
1274
completedBackupsCount , err = getScheduledBackupCompleteBackupsCount (namespace , scheduledBackupName )
1288
1275
Expect (err ).ToNot (HaveOccurred ())
1289
-
1290
- cmd := fmt .Sprintf ("kubectl patch ScheduledBackup %v -n %v -p '{\" spec\" :{\" suspend\" :false}}' " +
1291
- "--type='merge'" , scheduledBackupName , namespace )
1292
- _ , _ , err = testsUtils .Run (cmd )
1293
- Expect (err ).ToNot (HaveOccurred ())
1276
+ Eventually (func () error {
1277
+ cmd := fmt .Sprintf ("kubectl patch ScheduledBackup %v -n %v -p '{\" spec\" :{\" suspend\" :false}}' " +
1278
+ "--type='merge'" , scheduledBackupName , namespace )
1279
+ _ , _ , err = testsUtils .RunUnchecked (cmd )
1280
+ if err != nil {
1281
+ return err
1282
+ }
1283
+ return nil
1284
+ }, 60 , 5 ).Should (BeNil ())
1294
1285
})
1295
1286
By ("verifying backup has resumed" , func () {
1296
1287
Eventually (func () (int , error ) {
@@ -1585,9 +1576,7 @@ func installAzCli(namespace string) {
1585
1576
}
1586
1577
1587
1578
func createAndAssertPgBouncerPoolerIsSetUp (namespace , poolerYamlFilePath string , expectedInstanceCount int ) {
1588
- _ , _ , err := testsUtils .Run ("kubectl create -n " + namespace + " -f " + poolerYamlFilePath )
1589
- Expect (err ).ToNot (HaveOccurred ())
1590
-
1579
+ CreateResourceFromFile (namespace , poolerYamlFilePath )
1591
1580
Eventually (func () (int32 , error ) {
1592
1581
poolerName , err := env .GetResourceNameFromYAML (poolerYamlFilePath )
1593
1582
Expect (err ).ToNot (HaveOccurred ())
@@ -1837,9 +1826,14 @@ func OnlineResizePVC(namespace, clusterName string) {
1837
1826
})
1838
1827
By ("expanding Cluster storage" , func () {
1839
1828
// Patching cluster to expand storage size from 1Gi to 2Gi
1840
- _ , _ , err := testsUtils .Run ("kubectl patch cluster " + clusterName + " -n " + namespace +
1841
- " -p '{\" spec\" :{\" storage\" :{\" size\" :\" 2Gi\" }}}' --type=merge" )
1842
- Expect (err ).ToNot (HaveOccurred ())
1829
+ Eventually (func () error {
1830
+ _ , _ , err := testsUtils .RunUnchecked ("kubectl patch cluster " + clusterName + " -n " + namespace +
1831
+ " -p '{\" spec\" :{\" storage\" :{\" size\" :\" 2Gi\" }}}' --type=merge" )
1832
+ if err != nil {
1833
+ return err
1834
+ }
1835
+ return nil
1836
+ }, 60 , 5 ).Should (BeNil ())
1843
1837
})
1844
1838
By ("verifying Cluster storage is expanded" , func () {
1845
1839
// Gathering and verifying the new size of PVC after update on cluster
@@ -1874,9 +1868,14 @@ func OfflineResizePVC(namespace, clusterName string, timeout int) {
1874
1868
})
1875
1869
By ("expanding Cluster storage" , func () {
1876
1870
// Expanding cluster storage
1877
- _ , _ , err := testsUtils .Run ("kubectl patch cluster " + clusterName + " -n " + namespace +
1878
- " -p '{\" spec\" :{\" storage\" :{\" size\" :\" 2Gi\" }}}' --type=merge" )
1879
- Expect (err ).ToNot (HaveOccurred ())
1871
+ Eventually (func () error {
1872
+ _ , _ , err := testsUtils .RunUnchecked ("kubectl patch cluster " + clusterName + " -n " + namespace +
1873
+ " -p '{\" spec\" :{\" storage\" :{\" size\" :\" 2Gi\" }}}' --type=merge" )
1874
+ if err != nil {
1875
+ return err
1876
+ }
1877
+ return nil
1878
+ }, 60 , 5 ).Should (BeNil ())
1880
1879
})
1881
1880
By ("deleting Pod and pPVC" , func () {
1882
1881
// Gathering cluster primary
@@ -2005,3 +2004,13 @@ func collectAndAssertDefaultMetricsPresentOnEachPod(namespace, clusterName strin
2005
2004
}
2006
2005
})
2007
2006
}
2007
+
2008
+ func CreateResourceFromFile (namespace , sampleFilePath string ) {
2009
+ Eventually (func () error {
2010
+ _ , _ , err := testsUtils .RunUnchecked ("kubectl apply -n " + namespace + " -f " + sampleFilePath )
2011
+ if err != nil {
2012
+ return err
2013
+ }
2014
+ return nil
2015
+ }, 60 , 5 ).Should (BeNil ())
2016
+ }
0 commit comments