|
14 | 14 |
|
15 | 15 | SPILO_CURRENT = "registry.opensource.zalan.do/acid/spilo-16-e2e:0.1" |
16 | 16 | SPILO_LAZY = "registry.opensource.zalan.do/acid/spilo-16-e2e:0.2" |
| 17 | +SPILO_FULL_IMAGE = "ghcr.io/zalando/spilo-16:3.2-p3" |
17 | 18 |
|
18 | 19 |
|
19 | 20 | def to_selector(labels): |
@@ -115,6 +116,7 @@ def setUpClass(cls): |
115 | 116 | configmap = yaml.safe_load(f) |
116 | 117 | configmap["data"]["workers"] = "1" |
117 | 118 | configmap["data"]["docker_image"] = SPILO_CURRENT |
| 119 | + configmap["data"]["major_version_upgrade_mode"] = "full" |
118 | 120 |
|
119 | 121 | with open("manifests/configmap.yaml", 'w') as f: |
120 | 122 | yaml.dump(configmap, f, Dumper=yaml.Dumper) |
@@ -1181,31 +1183,94 @@ def get_docker_image(): |
1181 | 1183 | self.eventuallyEqual(lambda: len(k8s.get_patroni_running_members("acid-minimal-cluster-0")), 2, "Postgres status did not enter running") |
1182 | 1184 |
|
1183 | 1185 | @timeout_decorator.timeout(TEST_TIMEOUT_SEC) |
1184 | | - @unittest.skip("Skipping this test until fixed") |
1185 | 1186 | def test_major_version_upgrade(self): |
| 1187 | + """ |
| 1188 | + Test major version upgrade |
| 1189 | + """ |
| 1190 | + def check_version(): |
| 1191 | + p = k8s.patroni_rest("acid-upgrade-test-0", "") |
| 1192 | + version = p.get("server_version", 0) // 10000 |
| 1193 | + return version |
| 1194 | + |
1186 | 1195 | k8s = self.k8s |
1187 | | - result = k8s.create_with_kubectl("manifests/minimal-postgres-manifest-12.yaml") |
1188 | | - self.eventuallyEqual(lambda: k8s.count_running_pods(labels="application=spilo,cluster-name=acid-upgrade-test"), 2, "No 2 pods running") |
| 1196 | + cluster_label = 'application=spilo,cluster-name=acid-upgrade-test' |
| 1197 | + |
| 1198 | + with open("manifests/minimal-postgres-manifest-12.yaml", 'r+') as f: |
| 1199 | + upgrade_manifest = yaml.safe_load(f) |
| 1200 | + upgrade_manifest["spec"]["dockerImage"] = SPILO_FULL_IMAGE |
| 1201 | + |
| 1202 | + with open("manifests/minimal-postgres-manifest-12.yaml", 'w') as f: |
| 1203 | + yaml.dump(upgrade_manifest, f, Dumper=yaml.Dumper) |
| 1204 | + |
| 1205 | + k8s.create_with_kubectl("manifests/minimal-postgres-manifest-12.yaml") |
| 1206 | + self.eventuallyEqual(lambda: k8s.count_running_pods(labels=cluster_label), 2, "No 2 pods running") |
1189 | 1207 | self.eventuallyEqual(lambda: k8s.get_operator_state(), {"0": "idle"}, "Operator does not get in sync") |
| 1208 | + self.eventuallyEqual(check_version, 12, "Version is not correct") |
1190 | 1209 |
|
1191 | | - pg_patch_version = { |
| 1210 | + master_nodes, _ = k8s.get_cluster_nodes(cluster_labels=cluster_label) |
| 1211 | + # should upgrade immediately |
| 1212 | + pg_patch_version_14 = { |
1192 | 1213 | "spec": { |
1193 | | - "postgres": { |
| 1214 | + "postgresql": { |
1194 | 1215 | "version": "14" |
1195 | 1216 | } |
1196 | 1217 | } |
1197 | 1218 | } |
1198 | 1219 | k8s.api.custom_objects_api.patch_namespaced_custom_object( |
1199 | | - "acid.zalan.do", "v1", "default", "postgresqls", "acid-upgrade-test", pg_patch_version) |
| 1220 | + "acid.zalan.do", "v1", "default", "postgresqls", "acid-upgrade-test", pg_patch_version_14) |
| 1221 | + self.eventuallyEqual(lambda: k8s.get_operator_state(), {"0": "idle"}, "Operator does not get in sync") |
| 1222 | + |
| 1223 | + # should have finish failover |
| 1224 | + k8s.wait_for_pod_failover(master_nodes, 'spilo-role=replica,' + cluster_label) |
| 1225 | + k8s.wait_for_pod_start('spilo-role=master,' + cluster_label) |
| 1226 | + k8s.wait_for_pod_start('spilo-role=replica,' + cluster_label) |
| 1227 | + self.eventuallyEqual(check_version, 14, "Version should be upgraded from 12 to 14") |
1200 | 1228 |
|
| 1229 | + # should not upgrade because current time is not in maintenanceWindow |
| 1230 | + current_time = datetime.now() |
| 1231 | + maintenance_window_future = f"{(current_time+timedelta(minutes=60)).strftime('%H:%M')}-{(current_time+timedelta(minutes=120)).strftime('%H:%M')}" |
| 1232 | + pg_patch_version_15 = { |
| 1233 | + "spec": { |
| 1234 | + "postgresql": { |
| 1235 | + "version": "15" |
| 1236 | + }, |
| 1237 | + "maintenanceWindows": [ |
| 1238 | + maintenance_window_future |
| 1239 | + ] |
| 1240 | + } |
| 1241 | + } |
| 1242 | + k8s.api.custom_objects_api.patch_namespaced_custom_object( |
| 1243 | + "acid.zalan.do", "v1", "default", "postgresqls", "acid-upgrade-test", pg_patch_version_15) |
1201 | 1244 | self.eventuallyEqual(lambda: k8s.get_operator_state(), {"0": "idle"}, "Operator does not get in sync") |
1202 | 1245 |
|
1203 | | - def check_version_14(): |
1204 | | - p = k8s.get_patroni_state("acid-upgrade-test-0") |
1205 | | - version = p["server_version"][0:2] |
1206 | | - return version |
| 1246 | + # should have finish failover |
| 1247 | + k8s.wait_for_pod_failover(master_nodes, 'spilo-role=master,' + cluster_label) |
| 1248 | + k8s.wait_for_pod_start('spilo-role=master,' + cluster_label) |
| 1249 | + k8s.wait_for_pod_start('spilo-role=replica,' + cluster_label) |
| 1250 | + self.eventuallyEqual(check_version, 14, "Version should not be upgraded") |
| 1251 | + |
| 1252 | + # change the version again to trigger operator sync |
| 1253 | + maintenance_window_current = f"{(current_time-timedelta(minutes=30)).strftime('%H:%M')}-{(current_time+timedelta(minutes=30)).strftime('%H:%M')}" |
| 1254 | + pg_patch_version_16 = { |
| 1255 | + "spec": { |
| 1256 | + "postgresql": { |
| 1257 | + "version": "16" |
| 1258 | + }, |
| 1259 | + "maintenanceWindows": [ |
| 1260 | + maintenance_window_current |
| 1261 | + ] |
| 1262 | + } |
| 1263 | + } |
1207 | 1264 |
|
1208 | | - self.eventuallyEqual(check_version_14, "14", "Version was not upgrade to 14") |
| 1265 | + k8s.api.custom_objects_api.patch_namespaced_custom_object( |
| 1266 | + "acid.zalan.do", "v1", "default", "postgresqls", "acid-upgrade-test", pg_patch_version_16) |
| 1267 | + self.eventuallyEqual(lambda: k8s.get_operator_state(), {"0": "idle"}, "Operator does not get in sync") |
| 1268 | + |
| 1269 | + # should have finish failover |
| 1270 | + k8s.wait_for_pod_failover(master_nodes, 'spilo-role=replica,' + cluster_label) |
| 1271 | + k8s.wait_for_pod_start('spilo-role=master,' + cluster_label) |
| 1272 | + k8s.wait_for_pod_start('spilo-role=replica,' + cluster_label) |
| 1273 | + self.eventuallyEqual(check_version, 16, "Version should be upgraded from 14 to 16") |
1209 | 1274 |
|
1210 | 1275 | @timeout_decorator.timeout(TEST_TIMEOUT_SEC) |
1211 | 1276 | def test_persistent_volume_claim_retention_policy(self): |
|
0 commit comments