|
14 | 14 | import java.util.function.Predicate; |
15 | 15 | import java.util.function.Supplier; |
16 | 16 |
|
| 17 | +import io.fabric8.kubernetes.api.model.Container; |
17 | 18 | import io.fabric8.kubernetes.api.model.Endpoints; |
18 | 19 | import io.fabric8.kubernetes.api.model.HasMetadata; |
19 | 20 | import io.fabric8.kubernetes.api.model.ObjectMeta; |
20 | 21 | import io.fabric8.kubernetes.api.model.Pod; |
| 22 | +import io.fabric8.kubernetes.api.model.PodSpec; |
21 | 23 | import io.fabric8.kubernetes.api.model.apps.StatefulSet; |
22 | 24 | import io.fabric8.kubernetes.api.model.apps.StatefulSetStatus; |
23 | 25 | import io.fabric8.kubernetes.api.model.batch.v1.Job; |
24 | 26 | import io.fabric8.kubernetes.api.model.batch.v1.JobStatus; |
25 | 27 | import io.stackgres.common.PatroniUtil; |
26 | 28 | import io.stackgres.common.StackGresContext; |
| 29 | +import io.stackgres.common.StackGresProperty; |
| 30 | +import io.stackgres.common.StackGresUtil; |
27 | 31 | import io.stackgres.common.crd.Condition; |
28 | 32 | import io.stackgres.common.crd.sgcluster.ClusterDbOpsRestartStatus; |
29 | 33 | import io.stackgres.common.crd.sgcluster.StackGresCluster; |
30 | 34 | import io.stackgres.common.crd.sgcluster.StackGresClusterDbOpsStatus; |
31 | 35 | import io.stackgres.common.crd.sgcluster.StackGresClusterStatus; |
32 | 36 | import io.stackgres.common.crd.sgdbops.DbOpsMethodType; |
| 37 | +import io.stackgres.common.crd.sgdbops.DbOpsOperation; |
33 | 38 | import io.stackgres.common.crd.sgdbops.DbOpsRestartStatus; |
34 | 39 | import io.stackgres.common.crd.sgdbops.DbOpsStatusCondition; |
35 | 40 | import io.stackgres.common.crd.sgdbops.StackGresDbOps; |
@@ -163,10 +168,49 @@ private void updateRolloutBasedDbOps(StackGresDbOps source) { |
163 | 168 | .filter(pod -> !ClusterRolloutUtil.getRestartReasons( |
164 | 169 | cluster, statefulSet, pod, patroniMembers).requiresRestart()) |
165 | 170 | .toList(); |
| 171 | + final boolean securityUpgradeWasApplied; |
| 172 | + if (Objects.equals( |
| 173 | + DbOpsOperation.SECURITY_UPGRADE.toString(), |
| 174 | + source.getSpec().getOp())) { |
| 175 | + securityUpgradeWasApplied = podsReadyAndUpdated |
| 176 | + .stream() |
| 177 | + .allMatch(pod -> Optional.of(pod) |
| 178 | + .map(Pod::getMetadata) |
| 179 | + .map(ObjectMeta::getAnnotations) |
| 180 | + .map(Map::entrySet) |
| 181 | + .stream() |
| 182 | + .flatMap(Set::stream) |
| 183 | + .anyMatch(Map.entry( |
| 184 | + StackGresContext.VERSION_KEY, |
| 185 | + StackGresProperty.OPERATOR_VERSION.getString())::equals)); |
| 186 | + } else { |
| 187 | + securityUpgradeWasApplied = true; |
| 188 | + } |
| 189 | + final boolean minorVersionUpgradeWasApplied; |
| 190 | + if (Objects.equals( |
| 191 | + DbOpsOperation.MINOR_VERSION_UPGRADE.toString(), |
| 192 | + source.getSpec().getOp())) { |
| 193 | + final String targetPatroniImage = StackGresUtil.getPatroniImageName( |
| 194 | + cluster, |
| 195 | + source.getSpec().getMinorVersionUpgrade().getPostgresVersion()); |
| 196 | + minorVersionUpgradeWasApplied = podsReadyAndUpdated |
| 197 | + .stream() |
| 198 | + .allMatch(pod -> Optional.of(pod) |
| 199 | + .map(Pod::getSpec) |
| 200 | + .map(PodSpec::getContainers) |
| 201 | + .stream() |
| 202 | + .flatMap(List::stream) |
| 203 | + .map(Container::getImage) |
| 204 | + .anyMatch(targetPatroniImage::equals)); |
| 205 | + } else { |
| 206 | + minorVersionUpgradeWasApplied = true; |
| 207 | + } |
166 | 208 | if (source.getStatus() == null) { |
167 | 209 | source.setStatus(new StackGresDbOpsStatus()); |
168 | 210 | } |
169 | 211 | if ((primaryIsReadyAndUpdated || primaryIsExternal) |
| 212 | + && securityUpgradeWasApplied |
| 213 | + && minorVersionUpgradeWasApplied |
170 | 214 | && pods.size() == podsReadyAndUpdated.size()) { |
171 | 215 | updateCondition(getRolloutCompleted(), source); |
172 | 216 | if (Optional.ofNullable(cluster.getMetadata().getAnnotations()) |
|
0 commit comments