Skip to content
Open
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
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
24 changes: 24 additions & 0 deletions java/operator/.idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,14 @@ public enum BandwidthLimiter {
"--oAuth2ProxyVersion" }, description = "The version to use of the quay.io/oauth2-proxy/oauth2-proxy image.", required = false, defaultValue = "latest")
private String oAuth2ProxyVersion;

@Option(names = {
"--enableCaching" }, description = "Whether to enable caching of Theia application containers.", required = false)
private boolean enableCaching = true;

@Option(names = {
"--cacheUrl" }, description = "The URL of the remote cache server.", required = false, defaultValue = "http://theia-cloud-combined-cache:8080/cache/")
private String cacheUrl;

public boolean isUseKeycloak() {
return useKeycloak;
}
Expand Down Expand Up @@ -222,6 +230,14 @@ public String getOAuth2ProxyVersion() {
return oAuth2ProxyVersion;
}

public boolean isEnableCaching() {
return enableCaching;
}

public String getCacheUrl() {
return cacheUrl;
}

@Override
public int hashCode() {
final int prime = 31;
Expand Down Expand Up @@ -251,6 +267,8 @@ public int hashCode() {
result = prime * result + (usePaths ? 1231 : 1237);
result = prime * result + ((wondershaperImage == null) ? 0 : wondershaperImage.hashCode());
result = prime * result + ((oAuth2ProxyVersion == null) ? 0 : oAuth2ProxyVersion.hashCode());
result = prime * result + (enableCaching ? 1231 : 1237);
result = prime * result + ((cacheUrl == null) ? 0 : cacheUrl.hashCode());
return result;
}

Expand Down Expand Up @@ -352,6 +370,13 @@ public boolean equals(Object obj) {
return false;
} else if (!oAuth2ProxyVersion.equals(other.oAuth2ProxyVersion))
return false;
if (enableCaching != other.enableCaching)
return false;
if (cacheUrl == null) {
if (other.cacheUrl != null)
return false;
} else if (!cacheUrl.equals(other.cacheUrl))
return false;
return true;
}

Expand All @@ -367,7 +392,8 @@ public String toString() {
+ ", keycloakClientId=" + keycloakClientId + ", leaderLeaseDuration=" + leaderLeaseDuration
+ ", leaderRenewDeadline=" + leaderRenewDeadline + ", leaderRetryPeriod=" + leaderRetryPeriod
+ ", maxWatchIdleTime=" + maxWatchIdleTime + ", continueOnException=" + continueOnException
+ ", oAuth2ProxyVersion=" + oAuth2ProxyVersion + "]";
+ ", oAuth2ProxyVersion=" + oAuth2ProxyVersion + ", enableCaching=" + enableCaching + ", cacheUrl="
+ cacheUrl + "]";
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@

import io.fabric8.kubernetes.api.model.ConfigMap;
import io.fabric8.kubernetes.api.model.ConfigMapEnvSource;
import io.fabric8.kubernetes.api.model.ConfigMapVolumeSource;
import io.fabric8.kubernetes.api.model.ObjectMeta;
import io.fabric8.kubernetes.api.model.OwnerReference;
import io.fabric8.kubernetes.api.model.Volume;
import io.fabric8.kubernetes.api.model.VolumeMount;
import io.fabric8.kubernetes.api.model.Container;
import io.fabric8.kubernetes.api.model.EnvFromSource;
import io.fabric8.kubernetes.api.model.EnvVar;
Expand All @@ -63,6 +68,9 @@
import io.fabric8.kubernetes.api.model.SecretEnvSource;
import io.fabric8.kubernetes.api.model.apps.Deployment;
import io.fabric8.kubernetes.client.NamespacedKubernetesClient;
import org.eclipse.theia.cloud.common.util.NamingUtil;
import org.eclipse.theia.cloud.operator.TheiaCloudOperatorArguments;
import org.eclipse.theia.cloud.operator.util.TheiaCloudHandlerUtil;

public final class AddedHandlerUtil {

Expand Down Expand Up @@ -249,6 +257,65 @@ public static void addImagePullSecret(Deployment deployment, String secret) {
imagePullSecrets.add(new LocalObjectReference(secret));
}

/**
* Configure Gradle remote build cache by setting environment variables.
* The Gradle init script baked into the image will pick these up automatically.
*
* Environment variables set:
* - GRADLE_REMOTE_CACHE_ENABLED: "true" or "false" (explicit toggle)
* - GRADLE_REMOTE_CACHE_URL: The cache server URL (only if enabled)
* - GRADLE_REMOTE_CACHE_PUSH: "true" or "false" (only if enabled)
*/
public static void configureGradleCaching(String correlationId, Deployment deployment,
AppDefinition appDefinition,
TheiaCloudOperatorArguments arguments) {
// Find the theia container
Optional<Integer> maybeIdx = findContainerIdxInDeployment(deployment, appDefinition.getSpec().getName());
if (maybeIdx.isEmpty()) {
LOGGER.warn(formatLogMessage(correlationId, "Could not find theia container to configure Gradle caching"));
return;
}

int idx = maybeIdx.get();
Container container = deployment.getSpec().getTemplate().getSpec().getContainers().get(idx);

// Initialize env list if null
if (container.getEnv() == null) {
container.setEnv(new ArrayList<>());
}

// Determine if caching should be enabled
boolean cachingEnabled = arguments != null
&& arguments.isEnableCaching()
&& arguments.getCacheUrl() != null
&& !arguments.getCacheUrl().trim().isEmpty();

// Always set the ENABLED variable for explicit control
EnvVar cacheEnabledEnv = new EnvVar();
cacheEnabledEnv.setName("GRADLE_REMOTE_CACHE_ENABLED");
cacheEnabledEnv.setValue(String.valueOf(cachingEnabled));
container.getEnv().add(cacheEnabledEnv);

if (cachingEnabled) {
// Set cache URL
EnvVar cacheUrlEnv = new EnvVar();
cacheUrlEnv.setName("GRADLE_REMOTE_CACHE_URL");
cacheUrlEnv.setValue(arguments.getCacheUrl().trim());
container.getEnv().add(cacheUrlEnv);

// Set push permission (default: true, could be made configurable)
EnvVar cachePushEnv = new EnvVar();
cachePushEnv.setName("GRADLE_REMOTE_CACHE_PUSH");
cachePushEnv.setValue("true");
container.getEnv().add(cachePushEnv);

LOGGER.info(formatLogMessage(correlationId,
"Gradle remote cache ENABLED. URL: " + arguments.getCacheUrl()));
} else {
LOGGER.info(formatLogMessage(correlationId, "Gradle remote cache DISABLED"));
}
}

/* ------------------- Addition of env vars to Deployments ------------------ */
public static void addCustomEnvVarsToDeploymentFromSession(String correlationId, Deployment deployment,
Session session, AppDefinition appDefinition) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,18 @@ public boolean sessionAdded(Session session, String correlationId) {
return false;
}

// If caching is enabled, ensure per-session gradle.properties is created and mounted into the deployment
try {

client.kubernetes().apps().deployments().withName(deploymentName).edit(deployment -> {
AddedHandlerUtil.configureGradleCaching(correlationId, deployment, appDefinition.get(), arguments);
return deployment;
});
} catch (KubernetesClientException e) {
LOGGER.warn(formatLogMessage(correlationId, "Could not add gradle init config to deployment " + deploymentName), e);
// non-fatal: continue
}

if (arguments.isUseKeycloak()) {
/* add user to allowed emails */
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -469,8 +469,11 @@ protected void createAndApplyDeployment(String correlationId, String sessionReso
appDefinition.getSpec().getUplinkLimit(), correlationId);
AddedHandlerUtil.removeEmptyResources(deployment);

AddedHandlerUtil.addCustomEnvVarsToDeploymentFromSession(correlationId, deployment, session,
appDefinition);
AddedHandlerUtil.addCustomEnvVarsToDeploymentFromSession(correlationId, deployment, session,
appDefinition);

// If operator caching is enabled and a cache URL is configured, add per-session gradle properties
AddedHandlerUtil.configureGradleCaching(correlationId, deployment, appDefinition, arguments);

if (appDefinition.getSpec().getPullSecret() != null
&& !appDefinition.getSpec().getPullSecret().isEmpty()) {
Expand Down
Loading