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(script): allow setting file extension #13555

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

andrzejressel
Copy link
Contributor

Motivation

Currently script file has no extension. Some intepreters however require specific extension - namely Java (at least in some situations) and Scala.

Modifications

New option in script object: extension

Verification

 ./dist/argo submit --watch test/e2e/functional/scripts-java.yml 
 ./dist/argo submit --watch test/e2e/functional/scripts-scala.yml 

@agilgur5 agilgur5 self-assigned this Sep 4, 2024
@agilgur5 agilgur5 changed the title feat(executor): allow setting extension for script file feat(script): allow setting file extension Sep 5, 2024
Copy link

@agilgur5 agilgur5 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for adding this feature to support interpreters that require it!

I've left some comments below, mostly on the docs, but one on the code too

docs/walk-through/scripts-and-results.md Outdated Show resolved Hide resolved
docs/walk-through/scripts-and-results.md Outdated Show resolved Hide resolved
docs/walk-through/scripts-and-results.md Outdated Show resolved Hide resolved
pkg/apis/workflow/v1alpha1/workflow_types.go Outdated Show resolved Hide resolved
@@ -3088,7 +3088,8 @@ func (woc *wfOperationCtx) executeScript(ctx context.Context, nodeName string, t
if len(tmpl.Script.Source) == 0 {
woc.log.Warn("'script.source' is empty, suggest change template into 'container'")
} else {
mainCtr.Args = append(mainCtr.Args, common.ExecutorScriptSourcePath)
scriptSourcePath := common.GetExecutorScriptSourcePath(tmpl.Script.Extension)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm thinking this makes more sense as a receiver function on the template struct

Suggested change
scriptSourcePath := common.GetExecutorScriptSourcePath(tmpl.Script.Extension)
scriptSourcePath := tmpl.GetScriptSourcePath()

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and this variable could just be in-lined instead then

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed, but I had to move these 2 constants to Template - I don't know If it looks good ...

Copy link

@agilgur5 agilgur5 Sep 14, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't need to move the 2 constants, you can leave them in common and just import them from there. See further comments below

docs/walk-through/scripts-and-results.md Outdated Show resolved Hide resolved
examples/scripts-java.yml Outdated Show resolved Hide resolved
docs/walk-through/scripts-and-results.md Outdated Show resolved Hide resolved
examples/scripts-scala.yml Outdated Show resolved Hide resolved
workflow/controller/operator.go Outdated Show resolved Hide resolved
@@ -3088,7 +3088,8 @@ func (woc *wfOperationCtx) executeScript(ctx context.Context, nodeName string, t
if len(tmpl.Script.Source) == 0 {
woc.log.Warn("'script.source' is empty, suggest change template into 'container'")
} else {
mainCtr.Args = append(mainCtr.Args, common.ExecutorScriptSourcePath)
scriptSourcePath := common.GetExecutorScriptSourcePath(tmpl.Script.Extension)
Copy link

@agilgur5 agilgur5 Sep 14, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't need to move the 2 constants, you can leave them in common and just import them from there. See further comments below

@@ -1184,7 +1184,7 @@ func addScriptStagingVolume(pod *apiv1.Pod) {
if initCtr.Name == common.InitContainerName {
volMount := apiv1.VolumeMount{
Name: volName,
MountPath: common.ExecutorStagingEmptyDir,
MountPath: wfv1.ExecutorStagingEmptyDir,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think these make more sense to be in common if they're also used here

ExecutorStagingEmptyDir = "/argo/staging"
// ExecutorScriptSourcePath is the path which init will write the script source file to for script templates
executorScriptSourcePath = "/argo/staging/script"
)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can just leave these in common and import them here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There seems to be cyclic import

diff --git a/pkg/apis/workflow/v1alpha1/workflow_types.go b/pkg/apis/workflow/v1alpha1/workflow_types.go
index da02c87bd..55648ca8c 100644
--- a/pkg/apis/workflow/v1alpha1/workflow_types.go
+++ b/pkg/apis/workflow/v1alpha1/workflow_types.go
@@ -26,6 +26,7 @@ import (
 
 	argoerrs "github.com/argoproj/argo-workflows/v3/errors"
 	"github.com/argoproj/argo-workflows/v3/util/slice"
+	"github.com/argoproj/argo-workflows/v3/workflow/common"
 )
 
 // TemplateType is the type of a template
@@ -815,19 +816,12 @@ func (tmpl *Template) GetOutputs() *Outputs {
 	return nil
 }
 
-const (
-	// ExecutorStagingEmptyDir is the path of the emptydir which is used as a staging area to transfer a file between init/main container for script/resource templates
-	ExecutorStagingEmptyDir = "/argo/staging"
-	// ExecutorScriptSourcePath is the path which init will write the script source file to for script templates
-	executorScriptSourcePath = "/argo/staging/script"
-)
-
 func (tmpl *Template) GetScriptSourcePath() string {
 	extension := tmpl.Script.Extension
 	if len(extension) != 0 {
-		return executorScriptSourcePath + "." + tmpl.Script.Extension
+		return common.ExecutorScriptSourcePath + "." + tmpl.Script.Extension
 	} else {
-		return executorScriptSourcePath
+		return common.ExecutorScriptSourcePath
 	}
 }
 
diff --git a/workflow/common/common.go b/workflow/common/common.go
index 55011c099..b4f174263 100644
--- a/workflow/common/common.go
+++ b/workflow/common/common.go
@@ -114,6 +114,10 @@ const (
 	// as well as artifact collection by the wait container.
 	ExecutorMainFilesystemDir = "/mainctrfs"
 
+	// ExecutorStagingEmptyDir is the path of the emptydir which is used as a staging area to transfer a file between init/main container for script/resource templates
+	ExecutorStagingEmptyDir = "/argo/staging"
+	// ExecutorScriptSourcePath is the path which init will write the script source file to for script templates
+	ExecutorScriptSourcePath = "/argo/staging/script"
 	// ExecutorResourceManifestPath is the path which init will write the manifest file to for resource templates
 	ExecutorResourceManifestPath = "/tmp/manifest.yaml"
package github.com/argoproj/argo-workflows/v3/config
        imports github.com/argoproj/argo-workflows/v3/pkg/apis/workflow/v1alpha1
        imports github.com/argoproj/argo-workflows/v3/workflow/common
        imports github.com/argoproj/argo-workflows/v3/pkg/apis/workflow/v1alpha1: import cycle not allowed

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought there might be, although I couldn't find one myself by visual inspection; it seems to import the workflow package (workflow/common.go) but not v1alpha1 🤔 Maybe I was on a stale branch

Ideally constant files shouldn't import anything so they're a single source of truth.

Copy link

@agilgur5 agilgur5 Oct 1, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, other files in the common package do import v1alpha1 (ancestry.go, convert.go, parse.go, and util.go). It's potentially worth splitting off a constants package

pkg/apis/workflow/v1alpha1/workflow_types.go Outdated Show resolved Hide resolved
test/e2e/functional/scripts-java.yml Outdated Show resolved Hide resolved
@agilgur5 agilgur5 added this to the v3.6.0 milestone Sep 26, 2024
@agilgur5 agilgur5 removed their assignment Nov 15, 2024
@Joibel Joibel modified the milestones: v3.6.x patches, v3.7.0 Nov 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants