You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kie.apache.org by wm...@apache.org on 2024/08/02 07:25:47 UTC

(incubator-kie-tools) branch main updated: kie-issues#1336: kn workflow quarkus deploy should have a namespace flag (#2481)

This is an automated email from the ASF dual-hosted git repository.

wmedvedeo 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 0ee56fb0ce3 kie-issues#1336: kn workflow quarkus deploy should have a namespace flag (#2481)
0ee56fb0ce3 is described below

commit 0ee56fb0ce3f24453b70a363b8353268da59cd0a
Author: Dmitrii Tikhomirov <tr...@users.noreply.github.com>
AuthorDate: Fri Aug 2 00:25:43 2024 -0700

    kie-issues#1336: kn workflow quarkus deploy should have a namespace flag (#2481)
---
 .../pkg/command/quarkus/deploy.go                  | 24 +++++++++++++++++-----
 1 file changed, 19 insertions(+), 5 deletions(-)

diff --git a/packages/kn-plugin-workflow/pkg/command/quarkus/deploy.go b/packages/kn-plugin-workflow/pkg/command/quarkus/deploy.go
index 5dfb324b1ac..faf07d2c272 100644
--- a/packages/kn-plugin-workflow/pkg/command/quarkus/deploy.go
+++ b/packages/kn-plugin-workflow/pkg/command/quarkus/deploy.go
@@ -27,7 +27,8 @@ import (
 )
 
 type DeployCmdConfig struct {
-	Path string // service name
+	Path      string // service name
+	Namespace string
 }
 
 func NewDeployCommand() *cobra.Command {
@@ -47,12 +48,15 @@ func NewDeployCommand() *cobra.Command {
 	# Deploy the workflow from the current directory's project. 
 	# Deploy as Knative service.
 	{{.Name}} deploy
+
+	# You can provide target namespace or use default
+	{{.Name}} deploy --namespace <your_namespace>
 	
 	# Specify the path of the directory containing the "knative.yml" 
 	{{.Name}} deploy --path ./kubernetes
 		`,
 		SuggestFor: []string{"delpoy", "deplyo"},
-		PreRunE:    common.BindEnv("path"),
+		PreRunE:    common.BindEnv("namespace", "path"),
 	}
 
 	cmd.RunE = func(cmd *cobra.Command, args []string) error {
@@ -60,6 +64,7 @@ func NewDeployCommand() *cobra.Command {
 	}
 
 	cmd.Flags().StringP("path", "p", "./target/kubernetes", fmt.Sprintf("%s path to knative deployment files", cmd.Name()))
+	cmd.Flags().StringP("namespace", "n", "", "Target namespace of your deployment.")
 
 	cmd.SetHelpFunc(common.DefaultTemplatedHelp)
 
@@ -89,7 +94,7 @@ func runDeploy(cmd *cobra.Command, args []string) error {
 
 func deployKnativeServiceAndEventingBindings(cfg DeployCmdConfig) (bool, error) {
 	isKnativeEventingBindingsCreated := false
-	createService := common.ExecCommand("kubectl", "apply", "-f", fmt.Sprintf("%s/knative.yml", cfg.Path))
+	createService := common.ExecCommand("kubectl", "apply", "-f", fmt.Sprintf("%s/knative.yml", cfg.Path), fmt.Sprintf("--namespace=%s", cfg.Namespace))
 	if err := common.RunCommand(
 		createService,
 		"deploy",
@@ -101,7 +106,15 @@ func deployKnativeServiceAndEventingBindings(cfg DeployCmdConfig) (bool, error)
 
 	// Check if kogito.yml file exists
 	if exists, err := checkIfKogitoFileExists(cfg); exists && err == nil {
-		deploy := common.ExecCommand("kubectl", "apply", "-f", fmt.Sprintf("%s/kogito.yml", cfg.Path))
+		if cfg.Namespace == "" {
+			if namespace, err := common.GetKubectlNamespace(); err == nil {
+				cfg.Namespace = namespace
+			} else {
+				fmt.Println("❌ ERROR: Failed to get current kubectl namespace")
+				return isKnativeEventingBindingsCreated, err
+			}
+		}
+		deploy := common.ExecCommand("kubectl", "apply", "-f", fmt.Sprintf("%s/kogito.yml", cfg.Path), fmt.Sprintf("--namespace=%s", cfg.Namespace))
 		if err := common.RunCommand(
 			deploy,
 			"deploy",
@@ -117,7 +130,8 @@ func deployKnativeServiceAndEventingBindings(cfg DeployCmdConfig) (bool, error)
 
 func runDeployCmdConfig(cmd *cobra.Command) (cfg DeployCmdConfig, err error) {
 	cfg = DeployCmdConfig{
-		Path: viper.GetString("path"),
+		Path:      viper.GetString("path"),
+		Namespace: viper.GetString("namespace"),
 	}
 	return
 }


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org
For additional commands, e-mail: commits-help@kie.apache.org