Skip to content
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

fix: check for app.Name if is empty, and pick the args[0] if so #20474 #20475

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions cmd/util/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -605,6 +605,15 @@ 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 == "" {
// split the appname from the command line <ns>/<appname>
_, 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)
}
Expand Down
20 changes: 20 additions & 0 deletions cmd/util/common.go
Original file line number Diff line number Diff line change
@@ -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 <namespace>/<appname> or <appname>, got: '%s' ", key)
}
return ns, appName, nil
}