Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Support to add a default executor at the organization level as global variable #1708

Merged
merged 2 commits into from
Jan 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}
Loading