Skip to content

Commit fe44df0

Browse files
committed
fix: set Bootstrapped when upgrading
1 parent 2eda475 commit fe44df0

1 file changed

Lines changed: 65 additions & 0 deletions

File tree

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/*
2+
* Copyright (C) 2019 OnGres, Inc.
3+
* SPDX-License-Identifier: AGPL-3.0-or-later
4+
*/
5+
6+
package io.stackgres.operator.mutation.cluster;
7+
8+
import java.util.List;
9+
import java.util.Optional;
10+
11+
import io.stackgres.common.StackGresVersion;
12+
import io.stackgres.common.crd.Condition;
13+
import io.stackgres.common.crd.sgcluster.ClusterStatusCondition;
14+
import io.stackgres.common.crd.sgcluster.StackGresCluster;
15+
import io.stackgres.common.crd.sgcluster.StackGresClusterStatus;
16+
import io.stackgres.operator.common.StackGresClusterReview;
17+
import io.stackgres.operatorframework.admissionwebhook.Operation;
18+
import io.stackgres.operatorframework.resource.ConditionUpdater;
19+
import jakarta.enterprise.context.ApplicationScoped;
20+
21+
@ApplicationScoped
22+
public class DefaultBootstrappedConditionMutator
23+
extends ConditionUpdater<StackGresCluster, Condition>
24+
implements ClusterMutator {
25+
26+
@Override
27+
public StackGresCluster mutate(StackGresClusterReview review, StackGresCluster resource) {
28+
if (review.getRequest().getOperation() != Operation.CREATE
29+
&& review.getRequest().getOperation() != Operation.UPDATE) {
30+
return resource;
31+
}
32+
if (StackGresVersion.getStackGresVersionAsNumber(resource) <= StackGresVersion.V_1_17.getVersionAsNumber()) {
33+
boolean isPlatformSet = resource.getStatus() != null
34+
&& resource.getStatus().getArch() != null
35+
&& resource.getStatus().getOs() != null;
36+
if (isPlatformSet) {
37+
updateCondition(getClusterBootstrapped(), resource);
38+
}
39+
}
40+
return resource;
41+
}
42+
43+
private Condition getClusterBootstrapped() {
44+
return ClusterStatusCondition.CLUSTER_BOOTSTRAPPED.getCondition();
45+
}
46+
47+
@Override
48+
protected List<Condition> getConditions(
49+
StackGresCluster source) {
50+
return Optional.ofNullable(source.getStatus())
51+
.map(StackGresClusterStatus::getConditions)
52+
.orElse(List.of());
53+
}
54+
55+
@Override
56+
protected void setConditions(
57+
StackGresCluster source,
58+
List<Condition> conditions) {
59+
if (source.getStatus() == null) {
60+
source.setStatus(new StackGresClusterStatus());
61+
}
62+
source.getStatus().setConditions(conditions);
63+
}
64+
65+
}

0 commit comments

Comments
 (0)