@@ -89,6 +89,34 @@ var _ = Describe("Tablespaces tests", Label(tests.LabelTablespaces,
8989 Expect (err ).ToNot (HaveOccurred ())
9090 }
9191
92+ // Verify that the tablespace exists on the primary pod of a cluster
93+ hasTablespaceAndOwner := func (cluster * apiv1.Cluster , tablespace , owner string ) (bool , error ) {
94+ namespace := cluster .ObjectMeta .Namespace
95+ clusterName := cluster .ObjectMeta .Name
96+ primaryPod , err := clusterutils .GetPrimary (env .Ctx , env .Client , namespace , clusterName )
97+ if err != nil {
98+ return false , err
99+ }
100+ result , stdErr , err := exec .QueryInInstancePod (
101+ env .Ctx , env .Client , env .Interface , env .RestClientConfig ,
102+ exec.PodLocator {
103+ Namespace : namespace ,
104+ PodName : primaryPod .Name ,
105+ }, postgres .AppDBName ,
106+ fmt .Sprintf ("SELECT 1 FROM pg_catalog.pg_tablespace WHERE spcname = '%s' " +
107+ "AND pg_catalog.pg_get_userbyid(spcowner) = '%s'" ,
108+ tablespace ,
109+ owner ),
110+ )
111+ if err != nil {
112+ return false , err
113+ }
114+ if stdErr != "" {
115+ return false , fmt .Errorf ("error while checking tablespaces: %s" , stdErr )
116+ }
117+ return result == "1\n " , nil
118+ }
119+
92120 Context ("on a new cluster with tablespaces" , Ordered , func () {
93121 var namespace , backupName string
94122 var err error
@@ -131,19 +159,20 @@ var _ = Describe("Tablespaces tests", Label(tests.LabelTablespaces,
131159 AssertDatabaseContainsTablespaces (cluster , testTimeouts [timeouts .Short ])
132160 AssertRoleReconciled (namespace , clusterName , "dante" , testTimeouts [timeouts .Short ])
133161 AssertRoleReconciled (namespace , clusterName , "alpha" , testTimeouts [timeouts .Short ])
134- AssertTablespaceAndOwnerExist ( cluster , "atablespace" , "app" )
135- AssertTablespaceAndOwnerExist ( cluster , "anothertablespace" , "dante" )
162+ Expect ( hasTablespaceAndOwner ( cluster , "atablespace" , "app" )). To ( BeTrue () )
163+ Expect ( hasTablespaceAndOwner ( cluster , "anothertablespace" , "dante" )). To ( BeTrue () )
136164 })
137165
138- It ("can update the cluster by change the owner of tablesapce " , func () {
166+ It ("can update the cluster by change the owner of tablespace " , func () {
139167 cluster , err := clusterutils .Get (env .Ctx , env .Client , namespace , clusterName )
140168 Expect (err ).ToNot (HaveOccurred ())
141169 updateTablespaceOwner (cluster , "anothertablespace" , "alpha" )
142170
143171 cluster , err = clusterutils .Get (env .Ctx , env .Client , namespace , clusterName )
144172 Expect (err ).ToNot (HaveOccurred ())
145- AssertTablespaceReconciled (namespace , clusterName , "anothertablespace" , testTimeouts [timeouts .Short ])
146- AssertTablespaceAndOwnerExist (cluster , "anothertablespace" , "alpha" )
173+ Eventually (func () (bool , error ) {
174+ return hasTablespaceAndOwner (cluster , "anothertablespace" , "alpha" )
175+ }).WithTimeout (30 * time .Second ).Should (BeTrue ())
147176 })
148177
149178 It ("can update the cluster to set a tablespace as temporary" , func () {
@@ -228,9 +257,9 @@ var _ = Describe("Tablespaces tests", Label(tests.LabelTablespaces,
228257 AssertClusterHasMountPointsAndVolumesForTablespaces (cluster , 3 , testTimeouts [timeouts .PodRollout ])
229258 AssertClusterHasPvcsAndDataDirsForTablespaces (cluster , testTimeouts [timeouts .PodRollout ])
230259 AssertDatabaseContainsTablespaces (cluster , testTimeouts [timeouts .PodRollout ])
231- AssertTablespaceAndOwnerExist ( cluster , "atablespace" , "app" )
232- AssertTablespaceAndOwnerExist ( cluster , "anothertablespace" , "alpha" )
233- AssertTablespaceAndOwnerExist ( cluster , "thirdtablespace" , "dante" )
260+ Expect ( hasTablespaceAndOwner ( cluster , "atablespace" , "app" )). To ( BeTrue () )
261+ Expect ( hasTablespaceAndOwner ( cluster , "anothertablespace" , "alpha" )). To ( BeTrue () )
262+ Expect ( hasTablespaceAndOwner ( cluster , "thirdtablespace" , "dante" )). To ( BeTrue () )
234263 })
235264
236265 By ("waiting for the cluster to be ready" , func () {
@@ -328,9 +357,9 @@ var _ = Describe("Tablespaces tests", Label(tests.LabelTablespaces,
328357 testTimeouts [timeouts .Short ])
329358 AssertClusterHasPvcsAndDataDirsForTablespaces (restoredCluster , testTimeouts [timeouts .Short ])
330359 AssertDatabaseContainsTablespaces (restoredCluster , testTimeouts [timeouts .Short ])
331- AssertTablespaceAndOwnerExist ( cluster , "atablespace" , "app" )
332- AssertTablespaceAndOwnerExist ( cluster , "anothertablespace" , "alpha" )
333- AssertTablespaceAndOwnerExist ( cluster , "thirdtablespace" , "dante" )
360+ Expect ( hasTablespaceAndOwner ( cluster , "atablespace" , "app" )). To ( BeTrue () )
361+ Expect ( hasTablespaceAndOwner ( cluster , "anothertablespace" , "alpha" )). To ( BeTrue () )
362+ Expect ( hasTablespaceAndOwner ( cluster , "thirdtablespace" , "dante" )). To ( BeTrue () )
334363 })
335364 })
336365 })
@@ -859,25 +888,6 @@ func updateTablespaceOwner(cluster *apiv1.Cluster, tablespaceName, newOwner stri
859888 Expect (err ).ToNot (HaveOccurred ())
860889}
861890
862- func AssertTablespaceReconciled (
863- namespace , clusterName ,
864- tablespaceName string ,
865- timeout int ,
866- ) {
867- By (fmt .Sprintf ("checking if tablespace %v is in reconciled status" , tablespaceName ), func () {
868- Eventually (func (g Gomega ) bool {
869- cluster , err := clusterutils .Get (env .Ctx , env .Client , namespace , clusterName )
870- g .Expect (err ).ToNot (HaveOccurred ())
871- for _ , state := range cluster .Status .TablespacesStatus {
872- if state .State == apiv1 .TablespaceStatusReconciled && state .Name == tablespaceName {
873- return true
874- }
875- }
876- return false
877- }, timeout ).Should (BeTrue ())
878- })
879- }
880-
881891func AssertRoleReconciled (
882892 namespace , clusterName ,
883893 roleName string ,
@@ -1121,28 +1131,6 @@ func AssertTempTablespaceBehavior(cluster *apiv1.Cluster, expectedTempTablespace
11211131 })
11221132}
11231133
1124- func AssertTablespaceAndOwnerExist (cluster * apiv1.Cluster , tablespace , owner string ) {
1125- namespace := cluster .ObjectMeta .Namespace
1126- clusterName := cluster .ObjectMeta .Name
1127- primaryPod , err := clusterutils .GetPrimary (env .Ctx , env .Client , namespace , clusterName )
1128- Expect (err ).ShouldNot (HaveOccurred ())
1129- result , stdErr , err := exec .QueryInInstancePod (
1130- env .Ctx , env .Client , env .Interface , env .RestClientConfig ,
1131- exec.PodLocator {
1132- Namespace : namespace ,
1133- PodName : primaryPod .Name ,
1134- }, postgres .AppDBName ,
1135- fmt .Sprintf ("SELECT 1 FROM pg_catalog.pg_tablespace WHERE spcname = '%s' " +
1136- "AND pg_catalog.pg_get_userbyid(spcowner) = '%s'" ,
1137- tablespace ,
1138- owner ),
1139- )
1140- Expect (stdErr ).To (BeEmpty ())
1141- Expect (err ).ShouldNot (HaveOccurred ())
1142- Expect (result ).To (Equal ("1\n " ))
1143- GinkgoWriter .Printf ("Found Tablespaces %s with owner %s" , tablespace , owner )
1144- }
1145-
11461134func assertCanHibernateClusterWithTablespaces (
11471135 namespace string ,
11481136 clusterName string ,
0 commit comments