This is an automated email from the ASF dual-hosted git repository.
ricardozanini pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/incubator-kie-tools.git
The following commit(s) were added to refs/heads/main by this push:
new 2d14ea8be83 kie-issues#1799: [kn-workflow-plugin] Specify image on
'workflow deploy (#3043)
2d14ea8be83 is described below
commit 2d14ea8be83eaf929d3b986ed6c5c5cc71f66782
Author: Dmitrii Tikhomirov <[email protected]>
AuthorDate: Mon Apr 14 08:57:51 2025 -0700
kie-issues#1799: [kn-workflow-plugin] Specify image on 'workflow deploy
(#3043)
---
.../kn-plugin-workflow/e2e-tests/deploy_test.go | 79 +++++++++++++++++++++-
.../kn-plugin-workflow/e2e-tests/helper_test.go | 16 +++--
packages/kn-plugin-workflow/pkg/command/deploy.go | 11 ++-
3 files changed, 100 insertions(+), 6 deletions(-)
diff --git a/packages/kn-plugin-workflow/e2e-tests/deploy_test.go
b/packages/kn-plugin-workflow/e2e-tests/deploy_test.go
index c1540f5e13d..bb17674af54 100644
--- a/packages/kn-plugin-workflow/e2e-tests/deploy_test.go
+++ b/packages/kn-plugin-workflow/e2e-tests/deploy_test.go
@@ -23,6 +23,7 @@ package e2e_tests
import (
"fmt"
+ "io"
"os"
"path/filepath"
"testing"
@@ -30,16 +31,30 @@ import (
"github.com/apache/incubator-kie-tools/packages/kn-plugin-workflow/pkg/command"
"github.com/apache/incubator-kie-tools/packages/kn-plugin-workflow/pkg/common"
"github.com/stretchr/testify/require"
+ "gopkg.in/yaml.v2"
)
type cfgTestInputDeploy struct {
input command.DeployUndeployCmdConfig
}
+type Config struct {
+ Kind string `yaml:"kind"`
+ Spec struct {
+ PodTemplate struct {
+ Container struct {
+ Image string `yaml:"image"`
+ } `yaml:"container"`
+ } `yaml:"podTemplate"`
+ } `yaml:"spec"`
+}
+
var cfgTestInputDeploy_Success = []cfgTestInputDeploy{
{input: command.DeployUndeployCmdConfig{}},
}
+var my_test_image = "my_test_image"
+
func transformDeployCmdCfgToArgs(cfg command.DeployUndeployCmdConfig) []string
{
args := []string{"deploy"}
return args
@@ -67,7 +82,68 @@ func TestDeployProjectSuccess(t *testing.T) {
for testIndex := range cfgTestInputDeploy_Success {
t.Run(fmt.Sprintf("Test deploy project success index: %d",
testIndex), func(t *testing.T) {
RunCreateTest(t, CfgTestInputCreate_Success[testIndex])
- projectName := GetCreateProjectName(t,
CfgTestInputCreate_Success[0])
+ projectName := GetCreateProjectName(t,
CfgTestInputCreate_Success[testIndex])
+ projectDir := filepath.Join(TempTestsPath, projectName)
+ defer os.RemoveAll(projectDir)
+
+ err = os.Chdir(projectDir)
+ require.NoErrorf(t, err, "Expected nil error, got %v",
err)
+
+ cmd := command.NewDeployCommand()
+ err = cmd.Execute()
+ require.NoError(t, err)
+ })
+ }
+}
+
+func TestDeployProjectSuccessWithImageDefined(t *testing.T) {
+ dir, err := os.Getwd()
+ require.NoError(t, err)
+
+ var originalCheckCrds = command.CheckCRDs
+ defer func() { command.CheckCRDs = originalCheckCrds }()
+
+ command.CheckCRDs = func(crds []string, typeName string) error {
+ return nil
+ }
+
+ var executeApplyOriginal = common.ExecuteApply
+ defer func() { common.ExecuteApply = executeApplyOriginal }()
+
+ defer os.Chdir(dir)
+ for testIndex := range cfgTestInputDeploy_Success {
+ common.ExecuteApply = func(path, namespace string) error {
+ if cfgTestInputDeploy_Success[testIndex].input.Image !=
"" {
+ file, err := os.Open(path)
+ if err != nil {
+ return fmt.Errorf("❌ ERROR: Failed to
open file: %v", err)
+ }
+ defer file.Close()
+ data, err := io.ReadAll(file)
+ if err != nil {
+ t.Fatalf("❌ ERROR: Failed to read file:
%v", err)
+ }
+
+ var cfg Config
+ err = yaml.Unmarshal(data, &cfg)
+ if err != nil {
+ t.Fatalf("❌ ERROR: Failed to unmarshal
file: %v", err)
+ }
+
+ if cfg.Kind != "SonataFlow" {
+ return nil
+ }
+
+ if cfg.Spec.PodTemplate.Container.Image !=
my_test_image {
+ t.Fatalf("❌ ERROR: Expected image %s,
got %s", my_test_image, cfg.Spec.PodTemplate.Container.Image)
+ }
+ }
+ return nil
+ }
+
+ t.Run(fmt.Sprintf("Test deploy project success index: %d",
testIndex), func(t *testing.T) {
+ RunCreateTest(t, CfgTestInputCreate_Success[testIndex])
+ projectName := GetCreateProjectName(t,
CfgTestInputCreate_Success[testIndex])
projectDir := filepath.Join(TempTestsPath, projectName)
defer os.RemoveAll(projectDir)
@@ -75,6 +151,7 @@ func TestDeployProjectSuccess(t *testing.T) {
require.NoErrorf(t, err, "Expected nil error, got %v",
err)
cmd := command.NewDeployCommand()
+ cmd.SetArgs([]string{"--image", my_test_image})
err = cmd.Execute()
require.NoError(t, err)
})
diff --git a/packages/kn-plugin-workflow/e2e-tests/helper_test.go
b/packages/kn-plugin-workflow/e2e-tests/helper_test.go
index 880a7ae06c7..c2f3575fdcb 100644
--- a/packages/kn-plugin-workflow/e2e-tests/helper_test.go
+++ b/packages/kn-plugin-workflow/e2e-tests/helper_test.go
@@ -24,6 +24,8 @@ package e2e_tests
import (
"bufio"
"bytes"
+ "context"
+ "errors"
"fmt"
"io"
"os"
@@ -43,7 +45,6 @@ import (
// Holds quarkus dependencies populated from environment variables
var quarkusDependencies = metadata.ResolveQuarkusDependencies()
-
// ExecuteCommand executes a command with the given arguments and returns an
error if the command fails.
func ExecuteCommand(command string, args ...string) error {
cmd := exec.Command(command, args...)
@@ -218,12 +219,19 @@ func LookupFlagDefaultValue(flagName string, createCmd
*cobra.Command) (string,
// IsSignalInterrupt checks if the given error is caused by a signal interrupt.
func IsSignalInterrupt(err error) bool {
- if exitErr, ok := err.(*exec.ExitError); ok {
+ if err == nil {
+ return false
+ }
+ if errors.Is(err, context.Canceled) {
+ return true
+ }
+ var exitErr *exec.ExitError
+ if errors.As(err, &exitErr) {
if status, ok := exitErr.Sys().(syscall.WaitStatus); ok {
- return status.Signaled() && status.Signal() ==
os.Interrupt
+ return status.Signaled() && (status.Signal() ==
syscall.SIGINT || status.Signal() == syscall.SIGTERM)
}
}
- return false
+ return strings.Contains(err.Error(), "signal: interrupt") ||
strings.Contains(err.Error(), "signal: terminated")
}
// cleanUpFolder removes the folder at the given path and recreates it with
permissions set to 0750.
diff --git a/packages/kn-plugin-workflow/pkg/command/deploy.go
b/packages/kn-plugin-workflow/pkg/command/deploy.go
index b73c1a12552..92a7baa159f 100644
--- a/packages/kn-plugin-workflow/pkg/command/deploy.go
+++ b/packages/kn-plugin-workflow/pkg/command/deploy.go
@@ -72,9 +72,12 @@ func NewDeployCommand() *cobra.Command {
# Wait for the deployment to complete and open the browser to the
deployed workflow.
{{.Name}} deploy --wait
+ # Specify a custom container dev image to use for the deployment.
+ {{.Name}} deploy --image=<your_image>
+
`,
- PreRunE: common.BindEnv("namespace", "custom-manifests-dir",
"custom-generated-manifests-dir", "specs-dir", "schemas-dir", "subflows-dir",
"wait"),
+ PreRunE: common.BindEnv("namespace", "custom-manifests-dir",
"custom-generated-manifests-dir", "specs-dir", "schemas-dir", "subflows-dir",
"wait", "image"),
SuggestFor: []string{"delpoy", "deplyo"},
}
@@ -90,6 +93,7 @@ func NewDeployCommand() *cobra.Command {
cmd.Flags().StringP("schemas-dir", "t", "", "Specify a custom schemas
files directory")
cmd.Flags().BoolP("minify", "f", true, "Minify the OpenAPI specs files
before deploying")
cmd.Flags().BoolP("wait", "w", false, "Wait for the deployment to
complete and open the browser to the deployed workflow")
+ cmd.Flags().StringP("image", "i", "", "Specify a custom image to use
for the deployment")
if err := viper.BindPFlag("minify", cmd.Flags().Lookup("minify")); err
!= nil {
fmt.Println("❌ ERROR: failed to bind minify flag")
@@ -130,6 +134,10 @@ func runDeployUndeploy(cmd *cobra.Command, args []string)
error {
fmt.Printf("🛠 Using manifests located at %s\n",
cfg.CustomManifestsFileDir)
}
+ if cfg.Image != "" {
+ metadata.DevModeImage = cfg.Image
+ }
+
if err = deploy(&cfg); err != nil {
return fmt.Errorf("❌ ERROR: applying deploy: %w", err)
}
@@ -263,6 +271,7 @@ func runDeployCmdConfig(cmd *cobra.Command) (cfg
DeployUndeployCmdConfig, err er
SubflowsDir: viper.GetString("subflows-dir"),
Minify: viper.GetBool("minify"),
Wait: viper.GetBool("wait"),
+ Image: viper.GetString("image"),
}
if len(cfg.SubflowsDir) == 0 {
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]