From e4e29d9e4b9e7c6a12bf974ea04032a02dafb98a Mon Sep 17 00:00:00 2001 From: Mostafa Negim Date: Mon, 21 Oct 2024 13:39:16 +0330 Subject: [PATCH 1/3] Fix: check for app.Name if is empty, and pick the args[0] if so #20474 Signed-off-by: Mostafa Negim Signed-off-by: Mostafa Negim --- cmd/util/app.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/cmd/util/app.go b/cmd/util/app.go index 025ef968097e5..1c170c737705b 100644 --- a/cmd/util/app.go +++ b/cmd/util/app.go @@ -605,6 +605,10 @@ func constructAppsFromFileUrl(fileURL, appName string, labels, annotations, args return nil, err } for _, app := range apps { + // if app.Name is empty, it should be picked from the command line + if len(args) == 1 && app.Name == "" { + app.Name = args[0] + } if len(args) == 1 && args[0] != app.Name { return nil, fmt.Errorf("app name '%s' does not match app spec metadata.name '%s'", args[0], app.Name) } From 0bd0f2c9030af7c67d821122b4c70377d41f50d8 Mon Sep 17 00:00:00 2001 From: Mostafa Negim Date: Mon, 21 Oct 2024 21:58:00 +0330 Subject: [PATCH 2/3] add: func GetNamespaceAndAppName to split ns/appname Signed-off-by: Mostafa Negim --- cmd/util/common.go | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/cmd/util/common.go b/cmd/util/common.go index 7c7b629ab4c98..974dd5f534101 100644 --- a/cmd/util/common.go +++ b/cmd/util/common.go @@ -1,6 +1,26 @@ package util +import ( + "fmt" + "strings" +) + var ( LogFormat string LogLevel string ) + +func GetNamespaceAndAppName(key string) (string, string, error) { + var ns, appName string + parts := strings.Split(key, "/") + + if len(parts) == 2 { + ns = parts[0] + appName = parts[1] + } else if len(parts) == 1 { + appName = parts[0] + } else { + return "", "", fmt.Errorf("APPNAME must be / or , got: '%s' ", key) + } + return ns, appName, nil +} From 8ebd96652c7dc15d65018985e02456dcf32a0531 Mon Sep 17 00:00:00 2001 From: Mostafa Negim Date: Mon, 21 Oct 2024 21:58:43 +0330 Subject: [PATCH 3/3] fix: handle the namespace/appname args[0] Signed-off-by: Mostafa Negim --- cmd/util/app.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/cmd/util/app.go b/cmd/util/app.go index 1c170c737705b..82ba49f4b71f9 100644 --- a/cmd/util/app.go +++ b/cmd/util/app.go @@ -607,7 +607,12 @@ func constructAppsFromFileUrl(fileURL, appName string, labels, annotations, args for _, app := range apps { // if app.Name is empty, it should be picked from the command line if len(args) == 1 && app.Name == "" { - app.Name = args[0] + // split the appname from the command line / + _, appNameFromCommand, err := GetNamespaceAndAppName(args[0]) + if err != nil { + return nil, err + } + app.Name = appNameFromCommand } if len(args) == 1 && args[0] != app.Name { return nil, fmt.Errorf("app name '%s' does not match app spec metadata.name '%s'", args[0], app.Name)