-
Notifications
You must be signed in to change notification settings - Fork 0
Add feature flag to enable shared cache #39
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
base: main
Are you sure you want to change the base?
Add feature flag to enable shared cache #39
Conversation
📝 WalkthroughWalkthroughThe changes add caching configuration support to the Theia Cloud operator. Two new command-line arguments (enableCaching and cacheUrl) are introduced alongside corresponding getters, hashCode/equals updates, and environment variable placeholders that conditionally populate deployment templates based on caching settings. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 2
🤖 Fix all issues with AI agents
In
`@java/operator/org.eclipse.theia.cloud.operator/src/main/java/org/eclipse/theia/cloud/operator/handler/AddedHandlerUtil.java`:
- Around line 57-61: Remove the unused imports in AddedHandlerUtil: delete the
import lines for ConfigMapVolumeSource, ObjectMeta, OwnerReference, Volume, and
VolumeMount since they are not referenced anywhere in the AddedHandlerUtil
class; update the import block accordingly so only used classes remain and run a
quick compile or IDE organize-imports to ensure no other unused imports remain.
In
`@java/operator/org.eclipse.theia.cloud.operator/src/main/java/org/eclipse/theia/cloud/operator/handler/session/EagerSessionHandler.java`:
- Around line 165-175: The comment and warning in EagerSessionHandler around the
try block misleadingly state that a per-session gradle.properties/init config is
created and mounted, but AddedHandlerUtil.configureGradleCaching only injects
environment variables; update the comment and the LOGGER.warn message to
accurately state that configureGradleCaching injects env vars into the
deployment (refer to AddedHandlerUtil.configureGradleCaching and
deploymentName), or if mounting gradle.properties was intended implement the
mount logic instead of calling configureGradleCaching; adjust the text in the
try-block comment and the formatLogMessage call so logs reflect the actual
behavior.
🧹 Nitpick comments (3)
java/operator/.idea/workspace.xml (1)
1-24: IDE configuration file should not be committed.The
.idea/workspace.xmlfile contains user-specific and machine-specific IntelliJ IDEA settings that should not be tracked in version control. These files can cause merge conflicts and clutter the repository.♻️ Recommended fix
Remove this file from the PR:
git rm --cached java/operator/.idea/workspace.xmlEnsure
.idea/workspace.xmlis in your.gitignore:+**/workspace.xmlNote: Project-level
.ideafiles (likecodeStyles,runConfigurations) can be shared, butworkspace.xmlcontains user-specific settings and should always be excluded.java/operator/org.eclipse.theia.cloud.operator/src/main/java/org/eclipse/theia/cloud/operator/TheiaCloudOperatorArguments.java (1)
125-131: Consider defaultingenableCachingtofalsefor safer rollout.Enabling caching by default (
enableCaching = true) changes behavior for all existing deployments upon upgrade. This could cause unexpected issues if the cache service isn't deployed. A safer approach would be to default tofalseand require explicit opt-in.Additionally, the default
cacheUrluses HTTP. While this may be acceptable for internal cluster communication, the PR description mentions "switching the default cache URL to use TLS." If HTTPS is intended, update the default accordingly.Suggested changes
`@Option`(names = { "--enableCaching" }, description = "Whether to enable caching of Theia application containers.", required = false) -private boolean enableCaching = true; +private boolean enableCaching = false; `@Option`(names = { - "--cacheUrl" }, description = "The URL of the remote cache server.", required = false, defaultValue = "http://theia-cloud-combined-cache:8080/cache/") + "--cacheUrl" }, description = "The URL of the remote cache server.", required = false, defaultValue = "https://theia-cloud-combined-cache:8080/cache/") private String cacheUrl;java/operator/org.eclipse.theia.cloud.operator/src/main/java/org/eclipse/theia/cloud/operator/handler/AddedHandlerUtil.java (1)
260-317: Implementation looks correct, with a few considerations.The method properly configures Gradle caching environment variables. A few observations:
Duplicate env vars risk: If this method is called multiple times on the same deployment (e.g., during retries), it will add duplicate environment variables. Consider checking for existing env vars before adding or clearing them first.
Hardcoded push permission:
GRADLE_REMOTE_CACHE_PUSHis hardcoded to"true". The comment at line 306 acknowledges this could be made configurable. For a read-only cache scenario, this would need to befalse.Optional: Prevent duplicate env vars
+ private static void setOrReplaceEnvVar(Container container, String name, String value) { + container.getEnv().removeIf(env -> name.equals(env.getName())); + EnvVar envVar = new EnvVar(); + envVar.setName(name); + envVar.setValue(value); + container.getEnv().add(envVar); + } + public static void configureGradleCaching(String correlationId, Deployment deployment, AppDefinition appDefinition, TheiaCloudOperatorArguments arguments) { // ... existing code to find container and init env list ... - // 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); + setOrReplaceEnvVar(container, "GRADLE_REMOTE_CACHE_ENABLED", String.valueOf(cachingEnabled)); 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); + setOrReplaceEnvVar(container, "GRADLE_REMOTE_CACHE_URL", arguments.getCacheUrl().trim()); + setOrReplaceEnvVar(container, "GRADLE_REMOTE_CACHE_PUSH", "true"); // ... } }
....cloud.operator/src/main/java/org/eclipse/theia/cloud/operator/handler/AddedHandlerUtil.java
Outdated
Show resolved
Hide resolved
...ator/src/main/java/org/eclipse/theia/cloud/operator/handler/session/EagerSessionHandler.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In
`@java/operator/org.eclipse.theia.cloud.operator/src/main/java/org/eclipse/theia/cloud/operator/handler/AddedHandlerUtil.java`:
- Around line 253-295: The configureRemoteCaching method currently always
appends REMOTE_CACHE_* EnvVar entries causing duplicates and leaving stale
REMOTE_CACHE_URL/REMOTE_CACHE_PUSH when caching is turned off; update
configureRemoteCaching to upsert env vars by name in the container's env list
(use findContainerIdxInDeployment to locate the container and container.getEnv()
to operate on the list), i.e. if an EnvVar with name
"REMOTE_CACHE_ENABLED"/"REMOTE_CACHE_URL"/"REMOTE_CACHE_PUSH" exists update its
value, otherwise add it; when cachingEnabled is false ensure you remove any
existing "REMOTE_CACHE_URL" and "REMOTE_CACHE_PUSH" entries (and only
set/override "REMOTE_CACHE_ENABLED" to "false"), avoiding duplicate entries on
redeploys.
🧹 Nitpick comments (1)
java/operator/org.eclipse.theia.cloud.operator/src/main/java/org/eclipse/theia/cloud/operator/handler/session/LazySessionHandler.java (1)
472-476: Fix indentation to match the surrounding lambda body.The new code has inconsistent indentation compared to the rest of the lambda body (lines 459-470 and 478-481). This should be aligned to match the existing code style within the lambda.
Additionally, the comment on line 475 is slightly misleading—
configureRemoteCachingis called unconditionally and always setsREMOTE_CACHE_ENABLED(to either"true"or"false"). Consider rewording to clarify that configuration is always applied:Suggested fix for indentation and comment
- AddedHandlerUtil.addCustomEnvVarsToDeploymentFromSession(correlationId, deployment, session, - appDefinition); - - // If caching is enabled, configure remote build cache via environment variables - AddedHandlerUtil.configureRemoteCaching(correlationId, deployment, appDefinition, arguments); + AddedHandlerUtil.addCustomEnvVarsToDeploymentFromSession(correlationId, deployment, session, + appDefinition); + + // Configure remote build cache environment variables (enabled/disabled based on arguments) + AddedHandlerUtil.configureRemoteCaching(correlationId, deployment, appDefinition, arguments);
....cloud.operator/src/main/java/org/eclipse/theia/cloud/operator/handler/AddedHandlerUtil.java
Outdated
Show resolved
Hide resolved
lukaskratzel
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you could handle this in a simpler way by setting the environment variables directly in the deployment template, which I have done so far for all my changes touching on environment variables. You can find the relevant template file here: java/operator/org.eclipse.theia.cloud.operator/src/main/resources/templateDeployment.yaml
The replacements for the templates are handled through this file: java/operator/org.eclipse.theia.cloud.operator/src/main/java/org/eclipse/theia/cloud/operator/util/TheiaCloudHandlerUtil.java.
But if that doesn't work for you we can also try this approach.
In this PR a feature flag is added to the Theia Cloud Operator, to mount a gradle configureation file into the Thea IDEs to enable them to access the remote cache.
At the moment, no authorization is configured. Which means that the Remote Gradle Cache needs to allow anonymouse access
Summary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings.