-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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: Template executor plugins. Fixes #5201 #7256
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,7 @@ dist | |
docs | ||
examples | ||
manifests | ||
plugins | ||
sdks | ||
test/e2e | ||
ui/dist | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,6 +21,7 @@ run: | |
- executor | ||
- examples | ||
- functional | ||
- plugins | ||
linters: | ||
enable: | ||
- bodyclose | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
controller: ./hack/free-port.sh 9090 && ARGO_REMOVE_PVC_PROTECTION_FINALIZER=true ARGO_PROGRESS_PATCH_TICK_DURATION=7s DEFAULT_REQUEUE_TIME=${DEFAULT_REQUEUE_TIME} LEADER_ELECTION_IDENTITY=local ALWAYS_OFFLOAD_NODE_STATUS=${ALWAYS_OFFLOAD_NODE_STATUS} OFFLOAD_NODE_STATUS_TTL=30s WORKFLOW_GC_PERIOD=30s UPPERIO_DB_DEBUG=${UPPERIO_DB_DEBUG} ARCHIVED_WORKFLOW_GC_PERIOD=30s ./dist/workflow-controller --executor-image ${IMAGE_NAMESPACE}/argoexec:${VERSION} --namespaced=${NAMESPACED} --namespace ${NAMESPACE} --managed-namespace=${MANAGED_NAMESPACE} --loglevel ${LOG_LEVEL} | ||
controller: ./hack/free-port.sh 9090 && ARGO_EXECUTOR_PLUGINS=${PLUGINS} ARGO_REMOVE_PVC_PROTECTION_FINALIZER=true ARGO_PROGRESS_PATCH_TICK_DURATION=7s DEFAULT_REQUEUE_TIME=${DEFAULT_REQUEUE_TIME} LEADER_ELECTION_IDENTITY=local ALWAYS_OFFLOAD_NODE_STATUS=${ALWAYS_OFFLOAD_NODE_STATUS} OFFLOAD_NODE_STATUS_TTL=30s WORKFLOW_GC_PERIOD=30s UPPERIO_DB_DEBUG=${UPPERIO_DB_DEBUG} ARCHIVED_WORKFLOW_GC_PERIOD=30s ./dist/workflow-controller --executor-image ${IMAGE_NAMESPACE}/argoexec:${VERSION} --namespaced=${NAMESPACED} --namespace ${NAMESPACE} --managed-namespace=${MANAGED_NAMESPACE} --loglevel ${LOG_LEVEL} | ||
argo-server: ./hack/free-port.sh 2746 && [ "$API" = "true" ] && UPPERIO_DB_DEBUG=${UPPERIO_DB_DEBUG} ./dist/argo --loglevel ${LOG_LEVEL} server --namespaced=${NAMESPACED} --namespace ${NAMESPACE} --auth-mode ${AUTH_MODE} --secure=$SECURE --x-frame-options=SAMEORIGIN | ||
ui: ./hack/free-port.sh 8080 && [ "$UI" = "true" ] && yarn --cwd ui install && yarn --cwd ui start | ||
logs: make logs |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package executorplugin | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
|
||
"github.com/spf13/cobra" | ||
|
||
plugin "github.com/argoproj/argo-workflows/v3/workflow/util/plugins" | ||
) | ||
|
||
func NewBuildCommand() *cobra.Command { | ||
return &cobra.Command{ | ||
Use: "build DIR", | ||
Short: "build an executor plugin", | ||
SilenceUsage: true, | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
if len(args) != 1 { | ||
cmd.HelpFunc()(cmd, args) | ||
os.Exit(1) | ||
} | ||
pluginDir := args[0] | ||
plug, err := loadPluginManifest(pluginDir) | ||
if err != nil { | ||
return err | ||
} | ||
cm, err := plugin.ToConfigMap(plug) | ||
if err != nil { | ||
return err | ||
} | ||
cmPath, err := saveConfigMap(cm, pluginDir) | ||
if err != nil { | ||
return err | ||
} | ||
fmt.Printf("%s created\n", cmPath) | ||
readmePath, err := saveReadme(pluginDir, plug) | ||
if err != nil { | ||
return err | ||
} | ||
fmt.Printf("%s created\n", readmePath) | ||
return nil | ||
}, | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
package executorplugin | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"path/filepath" | ||
"text/template" | ||
|
||
apiv1 "k8s.io/api/core/v1" | ||
"sigs.k8s.io/yaml" | ||
|
||
"github.com/argoproj/argo-workflows/v3/pkg/plugins/spec" | ||
) | ||
|
||
func loadPluginManifest(pluginDir string) (*spec.Plugin, error) { | ||
manifest, err := os.ReadFile(filepath.Join(pluginDir, "plugin.yaml")) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure if I'm a huge fan of hardwiring There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
if err != nil { | ||
return nil, err | ||
} | ||
p := &spec.Plugin{} | ||
err = yaml.UnmarshalStrict(manifest, p) | ||
if err != nil { | ||
return nil, err | ||
} | ||
files, err := filepath.Glob(filepath.Join(pluginDir, "server.*")) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
if len(files) > 1 { | ||
return nil, fmt.Errorf("plugin %s has more than one server.* file", p.Name) | ||
} | ||
if len(files) == 1 { | ||
code, err := os.ReadFile(files[0]) | ||
if err != nil { | ||
return nil, err | ||
} | ||
p.Spec.Sidecar.Container.Args = []string{string(code)} | ||
} | ||
return p, p.Validate() | ||
} | ||
|
||
func addHeader(x []byte, h string) []byte { | ||
return []byte(fmt.Sprintf("%s\n%s", h, string(x))) | ||
} | ||
|
||
func addCodegenHeader(x []byte) []byte { | ||
return addHeader(x, "# This is an auto-generated file. DO NOT EDIT") | ||
} | ||
|
||
func saveConfigMap(cm *apiv1.ConfigMap, pluginDir string) (string, error) { | ||
data, err := yaml.Marshal(cm) | ||
if err != nil { | ||
return "", err | ||
} | ||
cmPath := filepath.Join(pluginDir, fmt.Sprintf("%s-configmap.yaml", cm.Name)) | ||
err = os.WriteFile(cmPath, addCodegenHeader(data), 0666) | ||
return cmPath, err | ||
} | ||
|
||
func saveReadme(pluginDir string, plug *spec.Plugin) (string, error) { | ||
readmePath := filepath.Join(pluginDir, "README.md") | ||
f, err := os.Create(readmePath) | ||
if err != nil { | ||
return "", err | ||
} | ||
defer f.Close() | ||
tmpl, err := template.New("readme").Parse(`<!-- This is an auto-generated file. DO NOT EDIT --> | ||
# {{.Name}} | ||
|
||
* Needs: {{index .Annotations "workflows.argoproj.io/version"}} | ||
* Image: {{.Spec.Sidecar.Container.Image}} | ||
|
||
{{index .Annotations "workflows.argoproj.io/description"}} | ||
|
||
Install: | ||
|
||
kubectl apply -f {{.Name}}-executor-plugin-configmap.yaml | ||
|
||
Uninstall: | ||
|
||
kubectl delete cm {{.Name}}-executor-plugin | ||
`) | ||
if err != nil { | ||
return "", err | ||
} | ||
if err = tmpl.Execute(f, plug); err != nil { | ||
return "", err | ||
} | ||
return readmePath, nil | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package executorplugin | ||
alexec marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
import ( | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
func NewRootCommand() *cobra.Command { | ||
command := &cobra.Command{ | ||
Use: "executor-plugin", | ||
Short: "manage executor plugins", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
cmd.HelpFunc()(cmd, args) | ||
}, | ||
} | ||
|
||
command.AddCommand(NewBuildCommand()) | ||
|
||
return command | ||
} |
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.
will this command work for all languages like java, go, etc?