-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Template executor plugin. (#7256)
Signed-off-by: Alex Collins <alex_collins@intuit.com>
- Loading branch information
Showing
97 changed files
with
12,132 additions
and
764 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,7 @@ dist | |
docs | ||
examples | ||
manifests | ||
plugins | ||
sdks | ||
test/e2e | ||
ui/dist | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,6 +21,7 @@ run: | |
- executor | ||
- examples | ||
- functional | ||
- plugins | ||
linters: | ||
enable: | ||
- bodyclose | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
}, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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")) | ||
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package executorplugin | ||
|
||
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.