Service type ClusterIP - Controller port forward through CLI (#431)
setting serviceType to ClusterIP as default for fission controller and corresponding changes in fission cli to be able to port-forward the controller pod.
This commit is contained in:
committed by
smruthi2187
parent
1428c64b4f
commit
b9a559af2f
@@ -9,19 +9,36 @@ Linux:
|
||||
Windows:
|
||||
For Windows, you can use the linux binary on WSL. Or you can download this windows executable: https://github.com/fission/fission/releases/download/0.5.0/fission-cli-windows.exe
|
||||
|
||||
2. Set the FISSION_URL and FISSION_ROUTER environment variables.
|
||||
2. Set the FISSION environment variables.
|
||||
|
||||
{{- if contains "NodePort" .Values.serviceType }}
|
||||
$ export FISSION_URL=http://$(minikube ip):{{ .Values.controllerPort }}
|
||||
$ export FISSION_ROUTER=$(minikube ip):{{ .Values.routerPort }}
|
||||
|
||||
{{- else if contains "LoadBalancer" .Values.serviceType }}
|
||||
NOTE: It may take a few minutes for the LoadBalancer IP to be available.
|
||||
You can watch the status of by running 'kubectl --namespace fission get -w svc' and 'kubectl --namespace fission get svc -w router'
|
||||
You can watch the status of by running 'kubectl --namespace fission get -w svc' and 'kubectl --namespace fission get svc -w controller'
|
||||
|
||||
$ export FISSION_URL=http://$(kubectl --namespace fission get svc controller -o=jsonpath='{..ip}')
|
||||
|
||||
{{- else if contains "ClusterIP" .Values.serviceType }}
|
||||
$ export FISSION_NAMESPACE={{ .Release.Namespace }}
|
||||
$ export KUBECONFIG=${HOME}/.kube/config
|
||||
|
||||
{{- end }}
|
||||
|
||||
{{- if contains "NodePort" .Values.routerServiceType }}
|
||||
$ export FISSION_ROUTER=$(minikube ip):{{ .Values.routerPort }}
|
||||
|
||||
{{- else if contains "LoadBalancer" .Values.routerServiceType }}
|
||||
NOTE: It may take a few minutes for the LoadBalancer IP to be available.
|
||||
You can watch the status by running 'kubectl --namespace fission get -w svc' and 'kubectl --namespace fission get svc -w router'
|
||||
$ export FISSION_ROUTER=$(kubectl --namespace fission get svc router -o=jsonpath='{..ip}')
|
||||
|
||||
{{- else if contains "ClusterIP" .Values.routerServiceType }}
|
||||
$ export KUBECONFIG=${HOME}/.kube/config
|
||||
$ curl -Lo port-forward-router.sh https://github.com/fission/fission/port-forward-router.sh && chmod +x port-forward-router.sh && ./port-forward-router.sh {{ .Release.Namespace }} router 9999
|
||||
$ export FISSION_ROUTER=127.0.0.1:9999
|
||||
|
||||
{{- end }}
|
||||
|
||||
3. Finally, you're ready to use Fission!
|
||||
|
||||
@@ -122,6 +122,7 @@ spec:
|
||||
metadata:
|
||||
labels:
|
||||
svc: controller
|
||||
application: fission-api
|
||||
spec:
|
||||
containers:
|
||||
- name: controller
|
||||
|
||||
@@ -6,11 +6,11 @@ metadata:
|
||||
svc: router
|
||||
chart: "{{ .Chart.Name }}-{{ .Chart.Version }}"
|
||||
spec:
|
||||
type: {{ .Values.serviceType }}
|
||||
type: {{ .Values.routerServiceType }}
|
||||
ports:
|
||||
- port: 80
|
||||
targetPort: 8888
|
||||
{{ if eq .Values.serviceType "NodePort" }}
|
||||
{{ if eq .Values.routerServiceType "NodePort" }}
|
||||
nodePort: {{ .Values.routerPort }}
|
||||
{{ end }}
|
||||
selector:
|
||||
|
||||
@@ -3,8 +3,11 @@
|
||||
#
|
||||
|
||||
## Kubernetes configuration
|
||||
## For minikube, set this to NodePort, elsewhere use LoadBalancer.
|
||||
serviceType: LoadBalancer
|
||||
## For minikube, set this to NodePort, elsewhere use LoadBalancer or ClusterIP.
|
||||
serviceType: ClusterIP
|
||||
|
||||
## For minikube, set this to NodePort, elsewhere use LoadBalancer or ClusterIP.
|
||||
routerServiceType: LoadBalancer
|
||||
|
||||
## Fission image repository
|
||||
image: fission/fission-bundle
|
||||
|
||||
@@ -13,15 +13,32 @@ Windows:
|
||||
|
||||
{{- if contains "NodePort" .Values.serviceType }}
|
||||
$ export FISSION_URL=http://$(minikube ip):{{ .Values.controllerPort }}
|
||||
$ export FISSION_ROUTER=$(minikube ip):{{ .Values.routerPort }}
|
||||
|
||||
{{- else if contains "LoadBalancer" .Values.serviceType }}
|
||||
NOTE: It may take a few minutes for the LoadBalancer IP to be available.
|
||||
You can watch the status of by running 'kubectl --namespace fission get -w svc' and 'kubectl --namespace fission get svc -w router'
|
||||
You can watch the status of by running 'kubectl --namespace fission get -w svc' and 'kubectl --namespace fission get svc -w controller'
|
||||
|
||||
$ export FISSION_URL=http://$(kubectl --namespace fission get svc controller -o=jsonpath='{..ip}')
|
||||
|
||||
{{- else if contains "ClusterIP" .Values.serviceType }}
|
||||
$ export FISSION_NAMESPACE={{ .Release.Namespace }}
|
||||
$ export KUBECONFIG=${HOME}/.kube/config
|
||||
|
||||
{{- end }}
|
||||
|
||||
{{- if contains "NodePort" .Values.routerServiceType }}
|
||||
$ export FISSION_ROUTER=$(minikube ip):{{ .Values.routerPort }}
|
||||
|
||||
{{- else if contains "LoadBalancer" .Values.routerServiceType }}
|
||||
NOTE: It may take a few minutes for the LoadBalancer IP to be available.
|
||||
You can watch the status by running 'kubectl --namespace fission get -w svc' and 'kubectl --namespace fission get svc -w router'
|
||||
$ export FISSION_ROUTER=$(kubectl --namespace fission get svc router -o=jsonpath='{..ip}')
|
||||
|
||||
{{- else if contains "ClusterIP" .Values.routerServiceType }}
|
||||
$ export KUBECONFIG=${HOME}/.kube/config
|
||||
$ curl -Lo port-forward-router.sh https://github.com/fission/fission/port-forward-router.sh && chmod +x port-forward-router.sh && ./port-forward-router.sh {{ .Release.Namespace }} router 9999
|
||||
$ export FISSION_ROUTER=127.0.0.1:9999
|
||||
|
||||
{{- end }}
|
||||
|
||||
3. Finally, you're ready to use Fission!
|
||||
|
||||
@@ -122,6 +122,7 @@ spec:
|
||||
metadata:
|
||||
labels:
|
||||
svc: controller
|
||||
application: fission-api
|
||||
spec:
|
||||
containers:
|
||||
- name: controller
|
||||
|
||||
@@ -6,11 +6,11 @@ metadata:
|
||||
svc: router
|
||||
chart: "{{ .Chart.Name }}-{{ .Chart.Version }}"
|
||||
spec:
|
||||
type: {{ .Values.serviceType }}
|
||||
type: {{ .Values.routerServiceType }}
|
||||
ports:
|
||||
- port: 80
|
||||
targetPort: 8888
|
||||
{{ if eq .Values.serviceType "NodePort" }}
|
||||
{{ if eq .Values.routerServiceType "NodePort" }}
|
||||
nodePort: {{ .Values.routerPort }}
|
||||
{{ end }}
|
||||
selector:
|
||||
|
||||
@@ -3,8 +3,11 @@
|
||||
#
|
||||
|
||||
## Kubernetes configuration
|
||||
## For minikube, set this to NodePort, elsewhere use LoadBalancer.
|
||||
serviceType: LoadBalancer
|
||||
## For minikube, set this to NodePort, elsewhere use LoadBalancer or ClusterIP.
|
||||
serviceType: ClusterIP
|
||||
|
||||
## For minikube, set this to NodePort, elsewhere use LoadBalancer or ClusterIP.
|
||||
routerServiceType: LoadBalancer
|
||||
|
||||
## Fission image repository
|
||||
image: fission/fission-bundle
|
||||
|
||||
+18
-1
@@ -157,6 +157,20 @@ func createArchive(client *client.Client, fileName string, specFile string) *fis
|
||||
archive.Type = fission.ArchiveTypeLiteral
|
||||
archive.Literal = contents
|
||||
} else {
|
||||
// make a kubernetes client
|
||||
_, kubeClient, _, err := crd.GetKubernetesClient()
|
||||
if err != nil {
|
||||
fatal(err.Error())
|
||||
}
|
||||
|
||||
fissionNamespace := os.Getenv("FISSION_NAMESPACE")
|
||||
|
||||
// get svc end point for storagesvc
|
||||
service, err := kubeClient.CoreV1().Services(fissionNamespace).Get("storagesvc", metav1.GetOptions{})
|
||||
if err != nil {
|
||||
fatal(fmt.Sprintf("Error getting storage service object from kubernetes :%v", err.Error()))
|
||||
}
|
||||
|
||||
u := strings.TrimSuffix(client.Url, "/") + "/proxy/storage"
|
||||
ssClient := storageSvcClient.MakeClient(u)
|
||||
|
||||
@@ -164,7 +178,10 @@ func createArchive(client *client.Client, fileName string, specFile string) *fis
|
||||
id, err := ssClient.Upload(fileName, nil)
|
||||
checkErr(err, fmt.Sprintf("upload file %v", fileName))
|
||||
|
||||
archiveUrl := ssClient.GetUrl(id)
|
||||
// this needs to be storagesvc.fission
|
||||
storageSvcEndpoint := fmt.Sprintf("http://%s.%s/", service.Name, service.Namespace)
|
||||
storageServiceClient := storageSvcClient.MakeClient(storageSvcEndpoint)
|
||||
archiveUrl := storageServiceClient.GetUrl(id)
|
||||
|
||||
archive.Type = fission.ArchiveTypeUrl
|
||||
archive.URL = archiveUrl
|
||||
|
||||
+28
-2
@@ -21,6 +21,7 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"os"
|
||||
@@ -602,10 +603,35 @@ func fnPods(c *cli.Context) error {
|
||||
}
|
||||
|
||||
func fnTest(c *cli.Context) error {
|
||||
//we can port-forward the router specifically for this method
|
||||
fnName := c.String("name")
|
||||
if len(fnName) == 0 {
|
||||
fatal("Need function name to be specified with --name")
|
||||
}
|
||||
|
||||
routerURL := os.Getenv("FISSION_ROUTER")
|
||||
if len(routerURL) == 0 {
|
||||
fatal("Need FISSION_ROUTER set to your fission router.")
|
||||
localRouterPort, err := findFreePort()
|
||||
if err != nil {
|
||||
fatal(fmt.Sprintf("Error finding unused port for router :%s", err.Error()))
|
||||
}
|
||||
|
||||
fissionNamespace := os.Getenv("FISSION_NAMESPACE")
|
||||
go func() {
|
||||
err := runportForward("router", localRouterPort, fissionNamespace)
|
||||
if err != nil {
|
||||
fatal(err.Error())
|
||||
}
|
||||
}()
|
||||
|
||||
for {
|
||||
conn, _ := net.DialTimeout("tcp", net.JoinHostPort("", localRouterPort), time.Second)
|
||||
if conn != nil {
|
||||
conn.Close()
|
||||
break
|
||||
}
|
||||
}
|
||||
routerURL = "127.0.0.1:" + localRouterPort
|
||||
}
|
||||
|
||||
url := fmt.Sprintf("http://%s/fission-function/%s", routerURL, fnName)
|
||||
@@ -621,7 +647,7 @@ func fnTest(c *cli.Context) error {
|
||||
|
||||
body, err := ioutil.ReadAll(resp.Body)
|
||||
checkErr(err, "read log response from pod")
|
||||
fmt.Printf("Error calling function %v: %v %v", fnName, resp.StatusCode, string(body))
|
||||
fmt.Printf("Error calling function %s: %d %s", fnName, resp.StatusCode, string(body))
|
||||
defer resp.Body.Close()
|
||||
err = printPodLogs(c)
|
||||
if err != nil {
|
||||
|
||||
+17
-1
@@ -28,8 +28,24 @@ func main() {
|
||||
app.Usage = "Serverless functions for Kubernetes"
|
||||
app.Version = "0.5.0"
|
||||
|
||||
// fetch the FISSION_URL env variable. If not set, port-forward to controller.
|
||||
var value string
|
||||
fissionUrl := os.Getenv("FISSION_URL")
|
||||
if len(fissionUrl) == 0 {
|
||||
// check here to specify env var for KUBECONFIG and FISSION_NAMESPACE
|
||||
fissionNamespace := os.Getenv("FISSION_NAMESPACE")
|
||||
kubeConfig := os.Getenv("KUBECONFIG")
|
||||
if len(kubeConfig) == 0 || len(fissionNamespace) == 0 {
|
||||
fatal("Environment variables KUBECONFIG and FISSION_NAMESPACE are mandatory if the serviceType is ClusterIP")
|
||||
}
|
||||
localPort := controllerPodPortForward(fissionNamespace)
|
||||
value = "http://127.0.0.1:" + localPort
|
||||
} else {
|
||||
value = fissionUrl
|
||||
}
|
||||
|
||||
app.Flags = []cli.Flag{
|
||||
cli.StringFlag{Name: "server", Usage: "Fission server URL", EnvVar: "FISSION_URL"},
|
||||
cli.StringFlag{Name: "server", Value: value, Usage: "Fission server URL"},
|
||||
}
|
||||
|
||||
// trigger method and url flags (used in function and route CLIs)
|
||||
|
||||
+3
-1
@@ -53,9 +53,11 @@ func downloadStoragesvcURL(client *client.Client, fileUrl string) io.ReadCloser
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
// replace in-cluster storage service host with controller server url
|
||||
fileDownloadUrl := strings.TrimSuffix(client.Url, "/") + "/proxy/storage" + u.RequestURI()
|
||||
fileDownloadUrl := strings.TrimSuffix(client.Url, "/") + "/proxy/storage/" + u.RequestURI()
|
||||
reader, err := downloadURL(fileDownloadUrl)
|
||||
|
||||
checkErr(err, fmt.Sprintf("download from storage service url: %v", fileUrl))
|
||||
return reader
|
||||
}
|
||||
|
||||
@@ -0,0 +1,136 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net"
|
||||
"os"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
meta_v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/client-go/tools/portforward"
|
||||
"k8s.io/client-go/tools/remotecommand"
|
||||
|
||||
"github.com/fission/fission/crd"
|
||||
)
|
||||
|
||||
func findFreePort() (string, error) {
|
||||
listener, err := net.Listen("tcp", ":0")
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
port := strconv.Itoa(listener.Addr().(*net.TCPAddr).Port)
|
||||
file, err := listener.(*net.TCPListener).File()
|
||||
if err != nil {
|
||||
return "", nil
|
||||
}
|
||||
|
||||
err = listener.Close()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
err = file.Close()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
return port, nil
|
||||
}
|
||||
|
||||
func runportForward(serviceName string, localPort string, fissionNamespace string) error {
|
||||
//KUBECONFIG needs to be set to the correct path i.e ~/.kube/config
|
||||
config, podClient, _, err := crd.GetKubernetesClient()
|
||||
if err != nil {
|
||||
fatal(err.Error())
|
||||
}
|
||||
|
||||
//get the podname for the controller
|
||||
podList, err := podClient.CoreV1().Pods(fissionNamespace).List(meta_v1.ListOptions{LabelSelector: "application=fission-api"})
|
||||
if err != nil || len(podList.Items) == 0 {
|
||||
fatal("Error getting controller pod for port-forwarding")
|
||||
}
|
||||
|
||||
// if there are more than one pods, always port-forward to the first pod returned
|
||||
podName := podList.Items[0].Name
|
||||
podNameSpace := podList.Items[0].Namespace
|
||||
|
||||
//get the ControllerPort
|
||||
service, err := podClient.CoreV1().Services(podNameSpace).Get(serviceName, meta_v1.GetOptions{})
|
||||
if err != nil {
|
||||
fatal(fmt.Sprintf("Error getting %v service :%v", serviceName, err.Error()))
|
||||
}
|
||||
|
||||
var targetPort string
|
||||
for _, servicePort := range service.Spec.Ports {
|
||||
targetPort = servicePort.TargetPort.String()
|
||||
}
|
||||
|
||||
stopChannel := make(chan struct{}, 1)
|
||||
readyChannel := make(chan struct{})
|
||||
|
||||
//create request URL
|
||||
req := podClient.CoreV1Client.RESTClient().Post().Resource("pods").Namespace(podNameSpace).Name(podName).SubResource("portforward")
|
||||
url := req.URL()
|
||||
|
||||
//create ports slice
|
||||
portCombo := localPort + ":" + targetPort
|
||||
ports := []string{portCombo}
|
||||
|
||||
//actually start the port-forwarding process here
|
||||
dialer, err := remotecommand.NewExecutor(config, "POST", url)
|
||||
if err != nil {
|
||||
msg := fmt.Sprintf("newexecutor errored out :%v", err.Error())
|
||||
fatal(msg)
|
||||
}
|
||||
|
||||
fw, err := portforward.New(dialer, ports, stopChannel, readyChannel, nil, os.Stderr)
|
||||
if err != nil {
|
||||
msg := fmt.Sprintf("portforward.new errored out :%v", err.Error())
|
||||
fatal(msg)
|
||||
}
|
||||
|
||||
return fw.ForwardPorts()
|
||||
}
|
||||
|
||||
func controllerPodPortForward(fissionNamespace string) string {
|
||||
localControllerPort, err := findFreePort()
|
||||
if err != nil {
|
||||
fatal(fmt.Sprintf("Error finding unused port :%v", err.Error()))
|
||||
}
|
||||
|
||||
timeBefore := time.Now()
|
||||
for {
|
||||
conn, _ := net.DialTimeout("tcp", net.JoinHostPort("", localControllerPort), time.Millisecond)
|
||||
if conn != nil {
|
||||
conn.Close()
|
||||
} else {
|
||||
break
|
||||
}
|
||||
time.Sleep(time.Millisecond * 50)
|
||||
}
|
||||
|
||||
timeAfter := time.Since(timeBefore)
|
||||
if timeAfter.Seconds()/1000 >= 100 {
|
||||
fatal(fmt.Sprintln("Lag in connecting to a free port on the localhost"))
|
||||
}
|
||||
|
||||
go func() {
|
||||
err := runportForward("controller", localControllerPort, fissionNamespace)
|
||||
if err != nil {
|
||||
fatal(err.Error())
|
||||
}
|
||||
}()
|
||||
|
||||
for {
|
||||
conn, _ := net.DialTimeout("tcp", net.JoinHostPort("", localControllerPort), time.Millisecond)
|
||||
if conn != nil {
|
||||
conn.Close()
|
||||
break
|
||||
}
|
||||
time.Sleep(time.Millisecond * 50)
|
||||
}
|
||||
|
||||
return localControllerPort
|
||||
}
|
||||
Generated
+11
-1
@@ -34,6 +34,10 @@ imports:
|
||||
subpackages:
|
||||
- digest
|
||||
- reference
|
||||
- name: github.com/docker/spdystream
|
||||
version: 449fdfce4d962303d702fec724ef0ad181c92528
|
||||
subpackages:
|
||||
- spdy
|
||||
- name: github.com/docopt/docopt-go
|
||||
version: 784ddc588536785e7299f7272f39101f7faccc3f
|
||||
- name: github.com/dsnet/compress
|
||||
@@ -284,6 +288,10 @@ imports:
|
||||
- pkg/util/validation/field
|
||||
- pkg/util/wait
|
||||
- pkg/util/yaml
|
||||
- pkg/util/httpstream
|
||||
- pkg/util/httpstream/spdy
|
||||
- pkg/util/remotecommand
|
||||
- third_party/forked/golang/netutil
|
||||
- pkg/version
|
||||
- pkg/watch
|
||||
- third_party/forked/golang/reflect
|
||||
@@ -366,6 +374,8 @@ imports:
|
||||
- tools/clientcmd/api
|
||||
- tools/clientcmd/api/latest
|
||||
- tools/clientcmd/api/v1
|
||||
- tools/portforward
|
||||
- tools/remotecommand
|
||||
- tools/metrics
|
||||
- transport
|
||||
- util/cert
|
||||
@@ -379,4 +389,4 @@ testImports:
|
||||
subpackages:
|
||||
- difflib
|
||||
- name: github.com/stretchr/objx
|
||||
version: 8a3f7159479fbc75b30357fbc48f380b7320f08e
|
||||
version: 8a3f7159479fbc75b30357fbc48f380b7320f08e
|
||||
Executable
+23
@@ -0,0 +1,23 @@
|
||||
#!/bin/bash
|
||||
|
||||
namespace=$1
|
||||
if [ -z "$namespace" ]
|
||||
then
|
||||
namespace=fission
|
||||
fi
|
||||
|
||||
svc=$1
|
||||
if [ -z "$svc" ]
|
||||
then
|
||||
svc=nats-streaming
|
||||
fi
|
||||
|
||||
port=$2
|
||||
if [ -z "$port" ]
|
||||
then
|
||||
port=8888
|
||||
fi
|
||||
|
||||
kubectl get pods -l svc=$svc -o name --namespace $namespace | \
|
||||
sed 's/^.*\///' | \
|
||||
xargs -I{} kubectl port-forward {} $port:$port -n $namespace &
|
||||
Executable
+24
@@ -0,0 +1,24 @@
|
||||
#!/bin/bash
|
||||
|
||||
namespace=$1
|
||||
if [ -z "$namespace" ]
|
||||
then
|
||||
namespace=fission
|
||||
fi
|
||||
|
||||
svc=$2
|
||||
if [ -z "$svc" ]
|
||||
then
|
||||
svc=router
|
||||
fi
|
||||
|
||||
port=$3
|
||||
if [ -z "$port" ]
|
||||
then
|
||||
port=8888
|
||||
fi
|
||||
|
||||
|
||||
kubectl get pods -l svc=$svc -o name --namespace $namespace | \
|
||||
sed 's/^.*\///' | \
|
||||
xargs -I{} kubectl port-forward {} $port:8888 -n $namespace &
|
||||
@@ -17,6 +17,7 @@ FLUENTD_IMAGE=gcr.io/fission-ci/fluentd
|
||||
BUILDER_IMAGE=$REPO/builder
|
||||
TAG=test
|
||||
PRUNE_INTERVAL=1 # this variable controls the interval to run archivePruner. The unit is in minutes.
|
||||
ROUTER_SERVICE_TYPE=ClusterIP
|
||||
|
||||
dump_system_info
|
||||
|
||||
@@ -36,4 +37,4 @@ build_and_push_fluentd $FLUENTD_IMAGE:$TAG
|
||||
|
||||
build_fission_cli
|
||||
|
||||
install_and_test $IMAGE $TAG $FETCHER_IMAGE $TAG $FLUENTD_IMAGE $TAG $PRUNE_INTERVAL
|
||||
install_and_test $IMAGE $TAG $FETCHER_IMAGE $TAG $FLUENTD_IMAGE $TAG $PRUNE_INTERVAL $ROUTER_SERVICE_TYPE
|
||||
|
||||
+18
-54
@@ -163,11 +163,12 @@ helm_install_fission() {
|
||||
fluentdImage=$8
|
||||
fluentdImageTag=$9
|
||||
pruneInterval="${10}"
|
||||
routerServiceType=${11}
|
||||
|
||||
ns=f-$id
|
||||
fns=f-func-$id
|
||||
|
||||
helmVars=image=$image,imageTag=$imageTag,fetcherImage=$fetcherImage,fetcherImageTag=$fetcherImageTag,functionNamespace=$fns,controllerPort=$controllerNodeport,routerPort=$routerNodeport,pullPolicy=Always,analytics=false,logger.fluentdImage=$fluentdImage,logger.fluentdImageTag=$fluentdImageTag,pruneInterval=$pruneInterval
|
||||
helmVars=image=$image,imageTag=$imageTag,fetcherImage=$fetcherImage,fetcherImageTag=$fetcherImageTag,functionNamespace=$fns,controllerPort=$controllerNodeport,routerPort=$routerNodeport,pullPolicy=Always,analytics=false,logger.fluentdImage=$fluentdImage,logger.fluentdImageTag=$fluentdImageTag,pruneInterval=$pruneInterval,routerServiceType=$routerServiceType
|
||||
|
||||
timeout 30 bash -c "helm_setup"
|
||||
|
||||
@@ -175,7 +176,7 @@ helm_install_fission() {
|
||||
helm list -q|xargs -I@ bash -c "helm_uninstall_fission @"
|
||||
|
||||
# deleting ns does take a while after command is issued
|
||||
while `kubectl get ns| grep fission-builder`
|
||||
while `kubectl get ns| grep "fission-builder"`
|
||||
do
|
||||
sleep 5
|
||||
done
|
||||
@@ -192,45 +193,6 @@ helm_install_fission() {
|
||||
helm list
|
||||
}
|
||||
|
||||
wait_for_service() {
|
||||
id=$1
|
||||
svc=$2
|
||||
health_endpoint=$3
|
||||
|
||||
ns=f-$id
|
||||
retry=0
|
||||
max_retries=5
|
||||
while true
|
||||
do
|
||||
retry=$((retry+1))
|
||||
if ((retry == max_retries)); then
|
||||
echo "Waiting for $svc to be routable exceeded max retries. Quitting.."
|
||||
exit 1
|
||||
fi
|
||||
ip=$(kubectl -n $ns get svc $svc -o jsonpath='{...ip}')
|
||||
if [ -z $ip ]; then
|
||||
continue
|
||||
fi
|
||||
http_status=`curl -sw "%{http_code}" "http://$ip/$health_endpoint"`
|
||||
echo "http_status for svc $svc : $http_status"
|
||||
if [ "$http_status" -ne "200" ]; then
|
||||
echo "Service $svc returned response other than 200. waiting for 200 after backing off for 1 second"
|
||||
sleep 1
|
||||
else
|
||||
break
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
wait_for_services() {
|
||||
id=$1
|
||||
|
||||
echo "\n--- wait for controller and router services to be routable ---"
|
||||
wait_for_service $id controller "healthz"
|
||||
wait_for_service $id router "router-healthz"
|
||||
echo "\n--- end wait for controller and router services to be routable ---"
|
||||
}
|
||||
|
||||
dump_kubernetes_events() {
|
||||
id=$1
|
||||
ns=f-$id
|
||||
@@ -269,14 +231,17 @@ helm_uninstall_fission() {(set +e
|
||||
)}
|
||||
export -f helm_uninstall_fission
|
||||
|
||||
set_environment() {
|
||||
port_forward_services() {
|
||||
id=$1
|
||||
ns=f-$id
|
||||
port=8888
|
||||
|
||||
export FISSION_URL=http://$(kubectl -n $ns get svc controller -o jsonpath='{...ip}')
|
||||
export FISSION_ROUTER=$(kubectl -n $ns get svc router -o jsonpath='{...ip}')
|
||||
kubectl get pods -l svc="router" -o name --namespace $ns | \
|
||||
sed 's/^.*\///' | \
|
||||
xargs -I{} kubectl port-forward {} $port:$port -n $ns &
|
||||
|
||||
# set path to include cli
|
||||
export FISSION_ROUTER="127.0.0.1:"
|
||||
FISSION_ROUTER+="$port"
|
||||
export PATH=$ROOT/fission:$PATH
|
||||
}
|
||||
|
||||
@@ -296,7 +261,6 @@ dump_builder_pod_logs() {
|
||||
done
|
||||
echo "--- end builder pod logs $p ---"
|
||||
done
|
||||
|
||||
}
|
||||
|
||||
dump_function_pod_logs() {
|
||||
@@ -457,6 +421,7 @@ install_and_test() {
|
||||
fluentdImage=$5
|
||||
fluentdImageTag=$6
|
||||
pruneInterval=$7
|
||||
routerServiceType=$8
|
||||
|
||||
controllerPort=31234
|
||||
routerPort=31235
|
||||
@@ -465,17 +430,16 @@ install_and_test() {
|
||||
|
||||
id=$(generate_test_id)
|
||||
trap "helm_uninstall_fission $id" EXIT
|
||||
if ! helm_install_fission $id $image $imageTag $fetcherImage $fetcherImageTag $controllerPort $routerPort $fluentdImage $fluentdImageTag $pruneInterval
|
||||
then
|
||||
helm_install_fission $id $image $imageTag $fetcherImage $fetcherImageTag $controllerPort $routerPort $fluentdImage $fluentdImageTag $pruneInterval $routerServiceType
|
||||
helm status $id | grep STATUS | grep -i deployed
|
||||
if [ $? -ne 0 ]; then
|
||||
describe_all_pods $id
|
||||
dump_kubernetes_events $id
|
||||
dump_tiller_logs
|
||||
exit 1
|
||||
exit 1
|
||||
fi
|
||||
|
||||
wait_for_services $id
|
||||
set_environment $id
|
||||
|
||||
port_forward_services $id $routerPort
|
||||
run_all_tests $id
|
||||
|
||||
dump_logs $id
|
||||
@@ -486,7 +450,7 @@ install_and_test() {
|
||||
then
|
||||
# describe each pod in fission ns and function namespace
|
||||
describe_all_pods $id
|
||||
exit 1
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
@@ -496,4 +460,4 @@ install_and_test() {
|
||||
# echo "Usage: test.sh [image] [imageTag]"
|
||||
# exit 1
|
||||
# fi
|
||||
# install_and_test $1 $2
|
||||
# install_and_test $1 $2
|
||||
@@ -6,6 +6,7 @@ pkg=""
|
||||
http_status=""
|
||||
url=""
|
||||
|
||||
|
||||
cleanup() {
|
||||
if [ -e "test-deploy-pkg.zip" ]; then
|
||||
rm -rf test-deploy-pkg.zip test_dir
|
||||
@@ -13,6 +14,7 @@ cleanup() {
|
||||
if [ -e "/tmp/file" ]; then
|
||||
rm -rf /tmp/file
|
||||
fi
|
||||
ps aux | grep -i "kubectl port-forward controller" | awk {'print $2'} | xargs kill -9 || true
|
||||
}
|
||||
|
||||
create_archive() {
|
||||
@@ -38,8 +40,21 @@ get_archive_url_from_package() {
|
||||
url=`kubectl get package $1 -ojsonpath='{.spec.deployment.url}'`
|
||||
}
|
||||
|
||||
port_forward_controller_pod() {
|
||||
log "Trying to port forward controller pod"
|
||||
controller_pod=`kubectl get pods -n $FISSION_NAMESPACE| grep controller| tr -s " "| cut -d" " -f1`
|
||||
controller_port=`kubectl get svc controller -n $FISSION_NAMESPACE -ojsonpath='{.spec.ports[0].targetPort}'`
|
||||
log "controller pod: $controller_pod, controller port : $controller_port"
|
||||
kubectl port-forward $controller_pod 9999:8888 -n $FISSION_NAMESPACE &
|
||||
sleep 4
|
||||
}
|
||||
|
||||
get_archive_from_storage() {
|
||||
http_status=`curl -sw "%{http_code}" $1 -o /tmp/file`
|
||||
storage_service_url=$1
|
||||
controller_proxy_url=`echo $storage_service_url | sed -e "s/storagesvc.$FISSION_NAMESPACE/127.0.0.1:9999\/proxy\/storage/"`
|
||||
log "controller_proxy_url=$controller_proxy_url"
|
||||
http_status=`curl -sw "%{http_code}" $controller_proxy_url -o /tmp/file`
|
||||
echo "http_status: $http_status"
|
||||
}
|
||||
|
||||
#1. declare trap to cleanup for EXIT
|
||||
@@ -75,6 +90,9 @@ main() {
|
||||
delete_package $pkg_2
|
||||
log "deleted packages : $pkg_1 $pkg_2"
|
||||
|
||||
# port forward controller pod
|
||||
port_forward_controller_pod
|
||||
|
||||
# curl on the archive url
|
||||
get_archive_from_storage $url_1
|
||||
log "http_status for $url_1 : $http_status"
|
||||
@@ -111,6 +129,7 @@ main() {
|
||||
exit 1
|
||||
fi
|
||||
|
||||
|
||||
log "Test archive pruner PASSED"
|
||||
}
|
||||
|
||||
|
||||
@@ -6,7 +6,5 @@ set -euo pipefail
|
||||
# have the right environment, that's all.
|
||||
|
||||
log "Test test, please ignore."
|
||||
|
||||
log $FISSION_URL
|
||||
log $FISSION_ROUTER
|
||||
which fission
|
||||
|
||||
Reference in New Issue
Block a user