Skip to content

Commit

Permalink
Add --namespace to invoke command
Browse files Browse the repository at this point in the history
This appears to be a miss in the PR that added namespace support.

Signed-off-by: Alex Ellis (OpenFaaS Ltd) <[email protected]>
  • Loading branch information
alexellis committed Dec 17, 2019
1 parent 247ab62 commit 73004c2
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 11 deletions.
21 changes: 12 additions & 9 deletions commands/invoke.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,21 @@ import (
)

var (
contentType string
query []string
headers []string
invokeAsync bool
httpMethod string
sigHeader string
key string
contentType string
query []string
headers []string
invokeAsync bool
httpMethod string
sigHeader string
key string
functionInvokeNamespace string
)

func init() {
// Setup flags that are used by multiple commands (variables defined in faas.go)
invokeCmd.Flags().StringVar(&functionName, "name", "", "Name of the deployed function")
invokeCmd.Flags().StringVarP(&functionInvokeNamespace, "namespace", "n", "", "Namespace of the deployed function")

invokeCmd.Flags().StringVarP(&gateway, "gateway", "g", defaultGateway, "Gateway URL starting with http(s)://")

invokeCmd.Flags().StringVar(&contentType, "content-type", "text/plain", "The content-type HTTP header such as application/json")
Expand All @@ -54,7 +57,7 @@ var invokeCmd = &cobra.Command{
faas-cli invoke env --header X-Ping-Url=http://request.bin/etc
faas-cli invoke resize-img --async -H "X-Callback-Url=http://gateway:8080/function/send2slack" < image.png
faas-cli invoke env -H X-Ping-Url=http://request.bin/etc
faas-cli invoke flask --method GET
faas-cli invoke flask --method GET --namespace dev
faas-cli invoke env --sign X-GitHub-Event --key yoursecret`,
RunE: runInvoke,
}
Expand Down Expand Up @@ -105,7 +108,7 @@ func runInvoke(cmd *cobra.Command, args []string) error {
headers = append(headers, signedHeader)
}

response, err := proxy.InvokeFunction(gatewayAddress, functionName, &functionInput, contentType, query, headers, invokeAsync, httpMethod, tlsInsecure)
response, err := proxy.InvokeFunction(gatewayAddress, functionName, &functionInput, contentType, query, headers, invokeAsync, httpMethod, tlsInsecure, functionInvokeNamespace)
if err != nil {
return err
}
Expand Down
8 changes: 6 additions & 2 deletions proxy/invoke.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
)

// InvokeFunction a function
func InvokeFunction(gateway string, name string, bytesIn *[]byte, contentType string, query []string, headers []string, async bool, httpMethod string, tlsInsecure bool) (*[]byte, error) {
func InvokeFunction(gateway string, name string, bytesIn *[]byte, contentType string, query []string, headers []string, async bool, httpMethod string, tlsInsecure bool, namespace string) (*[]byte, error) {
var resBytes []byte

gateway = strings.TrimRight(gateway, "/")
Expand Down Expand Up @@ -45,7 +45,11 @@ func InvokeFunction(gateway string, name string, bytesIn *[]byte, contentType st
return nil, httpMethodErr
}

gatewayURL := gateway + functionEndpoint + name + qs
gatewayURL := gateway + functionEndpoint + name
if len(namespace) > 0 {
gatewayURL += "." + namespace
}
gatewayURL += qs

req, err := http.NewRequest(httpMethod, gatewayURL, reader)
if err != nil {
Expand Down
4 changes: 4 additions & 0 deletions proxy/invoke_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ func Test_InvokeFunction(t *testing.T) {
false,
http.MethodPost,
tlsNoVerify,
"",
)

if err != nil {
Expand All @@ -51,6 +52,7 @@ func Test_InvokeFunction_Async(t *testing.T) {
true,
http.MethodPost,
tlsNoVerify,
"",
)

if err != nil {
Expand All @@ -73,6 +75,7 @@ func Test_InvokeFunction_Not2xx(t *testing.T) {
false,
http.MethodPost,
tlsNoVerify,
"",
)

if err == nil {
Expand All @@ -98,6 +101,7 @@ func Test_InvokeFunction_MissingURLPrefix(t *testing.T) {
false,
http.MethodPost,
tlsNoVerify,
"",
)

if err == nil {
Expand Down

0 comments on commit 73004c2

Please sign in to comment.