Capture context from cobra CLI and pass forward (#2551)
Signed-off-by: Sanket Sudake <sanketsudake@gmail.com>
This commit is contained in:
@@ -43,7 +43,7 @@ const maxDuration time.Duration = 2000
|
||||
// is found by looking for a service in the same namespace and using
|
||||
// its targetPort. Once the port forward is started, wait for it to
|
||||
// start accepting connections before returning.
|
||||
func SetupPortForward(namespace, labelSelector string, kubeContext string) (string, error) {
|
||||
func SetupPortForward(ctx context.Context, namespace, labelSelector string, kubeContext string) (string, error) {
|
||||
console.Verbose(2, "Setting up port forward to %s in namespace %s",
|
||||
labelSelector, namespace)
|
||||
|
||||
@@ -71,7 +71,7 @@ func SetupPortForward(namespace, labelSelector string, kubeContext string) (stri
|
||||
|
||||
console.Verbose(2, "Starting port forward from local port %v", localPort)
|
||||
|
||||
readyC, _, err := runPortForward(context.Background(), labelSelector, localPort, namespace, kubeContext)
|
||||
readyC, _, err := runPortForward(ctx, labelSelector, localPort, namespace, kubeContext)
|
||||
if err != nil {
|
||||
fmt.Printf("Error forwarding to port %v: %s", localPort, err.Error())
|
||||
return "", err
|
||||
|
||||
@@ -17,6 +17,7 @@ limitations under the License.
|
||||
package util
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net/url"
|
||||
"os"
|
||||
@@ -53,13 +54,13 @@ func GetFissionNamespace() string {
|
||||
return fissionNamespace
|
||||
}
|
||||
|
||||
func GetApplicationUrl(selector string, kubeContext string) (string, error) {
|
||||
func GetApplicationUrl(ctx context.Context, selector string, kubeContext string) (string, error) {
|
||||
var serverUrl string
|
||||
// Use FISSION_URL env variable if set; otherwise, port-forward to controller.
|
||||
fissionUrl := os.Getenv("FISSION_URL")
|
||||
if len(fissionUrl) == 0 {
|
||||
fissionNamespace := GetFissionNamespace()
|
||||
localPort, err := SetupPortForward(fissionNamespace, selector, kubeContext)
|
||||
localPort, err := SetupPortForward(ctx, fissionNamespace, selector, kubeContext)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
@@ -213,7 +214,7 @@ func GetServerURL(input cli.Input) (serverUrl string, err error) {
|
||||
kubeContext := input.String(flagkey.KubeContext)
|
||||
if len(serverUrl) == 0 {
|
||||
// starts local portforwarder etc.
|
||||
serverUrl, err = GetApplicationUrl("application=fission-api", kubeContext)
|
||||
serverUrl, err = GetApplicationUrl(input.Context(), "application=fission-api", kubeContext)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
@@ -445,8 +446,8 @@ func ApplyLabelsAndAnnotations(input cli.Input, objectMeta *metav1.ObjectMeta) e
|
||||
return nil
|
||||
}
|
||||
|
||||
func GetStorageURL(kubeContext string) (*url.URL, error) {
|
||||
storageLocalPort, err := SetupPortForward(GetFissionNamespace(), "application=fission-storage", kubeContext)
|
||||
func GetStorageURL(ctx context.Context, kubeContext string) (*url.URL, error) {
|
||||
storageLocalPort, err := SetupPortForward(ctx, GetFissionNamespace(), "application=fission-storage", kubeContext)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user