Skip to content

Commit 9ab0cfb

Browse files
authored
Feat: Add support for redeployment of an existing environment (#62)
* Update: Add support for environment rebuild in upload API Modified the upload API to support updating an existing environment of a property and added functionality for triggering a redeployment of an existing environment. Introduced a new boolean attribute 'rebuild' in the form data. When set to true, it initiates a redeployment process while keeping all other form attributes and processes unchanged. This commit includes all related changes. * Refactor: Change `rebuildEnvironment` field type to String and add parsing logic * Fix: Address "spec is immutable" error for bound claims
1 parent 0fec611 commit 9ab0cfb

File tree

5 files changed

+22
-14
lines changed

5 files changed

+22
-14
lines changed

src/main/java/io/spaship/operator/api/SpaDeploymentController.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,9 @@ public String uploadSPA(@MultipartForm FormData formData) {
4545
var response = requestTagging(formData.website);
4646
//[0]file-path[1]unique-trace-id[2]website-name
4747
var fileUploadParams = new Triplet<>(formData.getfilePath(), response, formData.website);
48-
spaUploadHandlerService.handleFileUpload(fileUploadParams);
48+
boolean rebuild = Boolean.parseBoolean(formData.rebuildEnvironment);
49+
spaUploadHandlerService.handleFileUpload(fileUploadParams,rebuild);
50+
4951
JsonObject object = new JsonObject();
5052
object.put("description", response.getValue0());
5153
object.put("traceId", response.getValue1());

src/main/java/io/spaship/operator/business/SPAUploadHandler.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public SPAUploadHandler(Operator k8sOperator, SideCarOperations sideCarOperation
5050

5151

5252
//[0]file-store-path[1]ops-tracing-id[2]website-name
53-
public void handleFileUpload(Triplet<Path, Pair<String, UUID>, String> input) {
53+
public void handleFileUpload(Triplet<Path, Pair<String, UUID>, String> input, boolean rebuildEnvironment) {
5454
LOG.debug(" deployment process initiated with details {}", input);
5555

5656
Uni.createFrom()
@@ -59,7 +59,7 @@ public void handleFileUpload(Triplet<Path, Pair<String, UUID>, String> input) {
5959
.map(this::buildEnvironmentList)
6060
.onItem()
6161
.transformToMulti(envList -> Multi.createFrom().iterable(envList))
62-
.map(this::processEnvironment)
62+
.map((Environment env) -> processEnvironment(env, rebuildEnvironment))
6363
.map(this::createOrUpdateSPA)
6464
.onFailure()
6565
.recoverWithItem(throwable -> {
@@ -232,7 +232,7 @@ private void logOperationDetails(OperationResponse operationResponse) {
232232
}
233233
}
234234

235-
private OperationResponse processEnvironment(Environment env) {
235+
private OperationResponse processEnvironment(Environment env, boolean rebuildEnvironment) {
236236
if (env.isUpdateRestriction() && k8sOperator.environmentExists(env)) {
237237
LOG.debug("environment exists but update restriction enforced, " +
238238
"environment details are as follows {}", env);
@@ -253,7 +253,7 @@ private OperationResponse processEnvironment(Environment env) {
253253
.build();
254254
}
255255

256-
return k8sOperator.createOrUpdateEnvironment(env);
256+
return k8sOperator.createOrUpdateEnvironment(env, rebuildEnvironment);
257257
}
258258

259259
private OperationResponse appDeleteOps(Environment environment) {

src/main/java/io/spaship/operator/service/Operations.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
public interface Operations {
77

8-
OperationResponse createOrUpdateEnvironment(Environment environment);
8+
OperationResponse createOrUpdateEnvironment(Environment environment, boolean rebuildEnvironment);
99

1010

1111
}

src/main/java/io/spaship/operator/service/k8s/Operator.java

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -67,16 +67,18 @@ private String setAppInstanceValue() {
6767
return propertyValue;
6868
}
6969

70-
public OperationResponse createOrUpdateEnvironment(Environment environment) {
70+
71+
72+
public OperationResponse createOrUpdateEnvironment(Environment environment, boolean rebuildEnvironment) {
7173

7274
propertyValidation();
7375

7476
ReUsableItems.enforceOpsLocking(new Pair<>(environment.getIdentification(), environment.getTraceID()));
7577

7678
boolean envExists = environmentExists(environment);
7779
LOG.debug("envExists is {}", envExists);
78-
if (!envExists)
79-
createNewEnvironment(environment);
80+
if (!envExists || rebuildEnvironment)
81+
createNewEnvironment(environment, rebuildEnvironment);
8082
String sideCarSvcUrl = environmentSidecarUrl(environment);
8183
// todo mutability is not good, we should not change the state of the object
8284
environment.setOperationPerformed(true);
@@ -140,12 +142,13 @@ public Uni<OperationResponse> deleteEnvironment(Environment environment) {
140142

141143
}
142144

143-
void createNewEnvironment(Environment environment) {
144-
if (!nameSpaceExists(environment))
145+
void createNewEnvironment(Environment environment, boolean rebuildEnvironment) {
146+
if (!rebuildEnvironment && !nameSpaceExists(environment)) {
145147
createMpPlusProject(environment);
148+
}
146149
KubernetesList result = buildK8sResourceList(environment);
147150
LOG.debug("create environment is in progress");
148-
processK8sList(result, environment.getTraceID(), environment.getNameSpace());
151+
processK8sList(result, environment.getTraceID(), environment.getNameSpace(),rebuildEnvironment);
149152
}
150153

151154
// TODO: this implementation is mp+ specific, using inheritance
@@ -373,7 +376,7 @@ public boolean isEnvironmentAvailable(Environment environment) {
373376
}
374377

375378
// TODO remove if blocks
376-
private void processK8sList(KubernetesList result, UUID tracing, String nameSpace) {
379+
private void processK8sList(KubernetesList result, UUID tracing, String nameSpace, boolean rebuildEnvironment) {
377380

378381
var eb = EventStructure.builder().uuid(tracing.toString());
379382

@@ -400,7 +403,7 @@ private void processK8sList(KubernetesList result, UUID tracing, String nameSpac
400403
.state("StatefulSet created");
401404

402405
}
403-
if (item instanceof PersistentVolumeClaim pvc) {
406+
if (!rebuildEnvironment && item instanceof PersistentVolumeClaim pvc) {
404407
LOG.debug("creating new pvc in K8s, tracing = {}", tracing);
405408
ocClient.persistentVolumeClaims().inNamespace(nameSpace).resource(pvc).createOrReplace();
406409
eb.websiteName(item.getMetadata().getLabels().get(ApplicationConstants.WEBSITE))

src/main/java/io/spaship/operator/type/FormData.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ public class FormData {
2525
@RestForm("spa")
2626
public FileUpload file;
2727

28+
@RestForm("rebuild")
29+
public String rebuildEnvironment;
30+
2831
public String fileName() {
2932
validateFileUpload();
3033
return this.file.fileName();

0 commit comments

Comments
 (0)