Skip to content

Commit

Permalink
feat: Support to add a default executor at the organization level as …
Browse files Browse the repository at this point in the history
…global variable (#1708)

* feat: Adding support to define a default executor

* feat: Adding support to define a default executor
  • Loading branch information
alfespa17 authored Jan 17, 2025
1 parent 05056f6 commit 10b5fcf
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -173,11 +173,22 @@ public ExecutorContext execute(Job job, String stepId, Flow flow) {
private String getExecutorUrl(Job job) {
String agentUrl = job.getWorkspace().getAgent() != null
? job.getWorkspace().getAgent().getUrl() + "/api/v1/terraform-rs"
: this.executorUrl;
: validateDefaultExecutor(job);
log.info("Job {} Executor agent url: {}", job.getId(), agentUrl);
return agentUrl;
}

private String validateDefaultExecutor(Job job) {
Optional<Globalvar> defaultExecutor = globalVarRepository.findByOrganizationAndKey(job.getOrganization(), "TERRAKUBE_DEFAULT_EXECUTOR");
if (defaultExecutor.isPresent()) {
log.info("Found default executor url {}", defaultExecutor.get().getValue());
return defaultExecutor.get().getValue() + "/api/v1/terraform-rs";
} else {
log.info("No default executor found, using default executor url {}", this.executorUrl);
return this.executorUrl;
}
}

private boolean iacType(Job job) {
return job.getWorkspace().getIacType() != null && job.getWorkspace().getIacType().equals("terraform") ? false
: true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@
import org.terrakube.api.rs.workspace.parameters.Category;

import java.util.List;
import java.util.Optional;
import java.util.UUID;

public interface GlobalVarRepository extends JpaRepository<Globalvar, UUID> {

Globalvar getGlobalvarByOrganizationAndCategoryAndKey(Organization organization, Category category, String key);
List<Globalvar> findByOrganization(Organization organization);
Optional<Globalvar> findByOrganizationAndKey(Organization organization, String key);
}

0 comments on commit 10b5fcf

Please sign in to comment.