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

Escape $ inside the task name #283

Merged
merged 2 commits into from
Feb 2, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -28,6 +28,8 @@
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Maps;
import com.google.common.escape.Escaper;
import com.google.common.escape.Escapers;
import com.google.protobuf.ByteString;
import java.io.File;
import java.io.IOException;
Expand Down Expand Up @@ -92,6 +94,8 @@ public abstract class ProjectClosure {

public abstract Map<LaunchPlanIdentifier, LaunchPlan> launchPlans();

private static final Escaper ESCAPER = Escapers.builder().addEscape('$', "\\$").build();

ProjectClosure applyCustom(JFlyteCustom custom) {
Map<TaskIdentifier, TaskSpec> rewrittenTaskSpecs =
mapValues(taskSpecs(), x -> applyCustom(x, custom));
Expand Down Expand Up @@ -483,7 +487,7 @@ static TaskTemplate createTaskTemplateForRunnableTask(RunnableTask task, String
"jflyte",
"execute",
"--task",
task.getName(),
ESCAPER.escape(task.getName()),
"--inputs",
"{{.input}}",
"--outputPrefix",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;

import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
Expand Down Expand Up @@ -441,6 +442,21 @@ public void testCreateTaskTemplateForRunnableTask() {
assertThat(result.type(), equalTo("java-task"));
}

@Test
public void testCreateTaskTemplateForRunnableTaskWith$Name() {
// given
RunnableTask task = createRunnableTask("NameWith$AsTaskName", null, List.of());
String image = "my-image";
Resources expectedResources = Resources.builder().build();

// when
TaskTemplate result = ProjectClosure.createTaskTemplateForRunnableTask(task, image);

// then
assertTrue(
result.container().args().stream().anyMatch(s -> s.contains("NameWith\\$AsTaskName")));
}

@Test
public void testCreateTaskTemplateForRunnableTaskWithResources() {
// given
Expand Down Expand Up @@ -758,10 +774,15 @@ void testCollectDynamicWorkflowTasks() {

private RunnableTask createRunnableTask(
Resources expectedResources, List<String> customJavaToolOptions) {
return createRunnableTask("my-test-task", expectedResources, customJavaToolOptions);
}

private RunnableTask createRunnableTask(
String name, Resources expectedResources, List<String> customJavaToolOptions) {
return new RunnableTask() {
@Override
public String getName() {
return "my-test-task";
return name;
}

@Override
Expand Down
Loading