@@ -136,13 +136,45 @@ check_schema_privileges(){
136
136
echo_step_completed
137
137
}
138
138
139
+ setup_observe_only_database (){
140
+ echo_step " create pre-existing database for observe only"
141
+
142
+ local datname
143
+ datname=" $( PGPASSWORD=" ${postgres_root_pw} " psql -h localhost -p 5432 -U postgres -wtAc " CREATE DATABASE \" db-observe\" ;" ) "
144
+
145
+ echo_step_completed
146
+ }
147
+
148
+ check_observe_only_database (){
149
+ echo_step " check if observe only database is preserved after deletion"
150
+
151
+ # Delete the database kubernetes object, it should not delete the database
152
+ kubectl delete database.postgresql.sql.crossplane.io db-observe
153
+
154
+ local datname
155
+ datname=" $( PGPASSWORD=" ${postgres_root_pw} " psql -h localhost -p 5432 -U postgres -wtAc " SELECT datname FROM pg_database WHERE datname = 'db-observe';" ) "
156
+
157
+ if [[ " $datname " == " db-observe" ]]; then
158
+ echo " Database db-observe is still present"
159
+ echo_info " OK"
160
+ else
161
+ echo " Database db-observe was NOT preserved"
162
+ echo_error " Not OK"
163
+ fi
164
+
165
+ # Clean up
166
+ PGPASSWORD=" ${postgres_root_pw} " psql -h localhost -p 5432 -U postgres -wtAc " DROP DATABASE \" db-observe\" ;"
167
+
168
+ echo_step_completed
169
+ }
170
+
139
171
delete_postgresdb_resources (){
140
172
# uninstall
141
173
echo_step " uninstalling ${PROJECT_NAME} "
142
- " ${KUBECTL} " delete -f ${projectdir} /examples/postgresql/grant.yaml
143
- " ${KUBECTL} " delete -f ${projectdir} /examples/postgresql/database.yaml
144
- " ${KUBECTL} " delete -f ${projectdir} /examples/postgresql/role.yaml
145
- " ${KUBECTL} " delete -f ${projectdir} /examples/postgresql/schema.yaml
174
+ " ${KUBECTL} " delete -f " ${projectdir} /examples/postgresql/grant.yaml"
175
+ " ${KUBECTL} " delete --ignore-not-found=true -f " ${projectdir} /examples/postgresql/database.yaml"
176
+ " ${KUBECTL} " delete -f " ${projectdir} /examples/postgresql/role.yaml"
177
+ " ${KUBECTL} " delete -f " ${projectdir} /examples/postgresql/schema.yaml"
146
178
echo " ${PROVIDER_CONFIG_POSTGRES_YAML} " | " ${KUBECTL} " delete -f -
147
179
148
180
# ----------- cleaning postgres related resources
@@ -160,7 +192,9 @@ delete_postgresdb_resources(){
160
192
integration_tests_postgres () {
161
193
setup_postgresdb_no_tls
162
194
setup_provider_config_postgres_no_tls
195
+ setup_observe_only_database
163
196
setup_postgresdb_tests
197
+ check_observe_only_database
164
198
check_all_roles_privileges
165
199
check_schema_privileges
166
200
delete_postgresdb_resources
0 commit comments