Skip to content

Commit

Permalink
Service type ClusterIP - Controller port forward through CLI (#431)
Browse files Browse the repository at this point in the history
setting serviceType to ClusterIP as default for fission controller and corresponding changes in fission cli to be able to port-forward the controller pod.
  • Loading branch information
prithviramesh authored and smruthi2187 committed Feb 27, 2018
1 parent 1428c64 commit b9a559a
Show file tree
Hide file tree
Showing 20 changed files with 355 additions and 77 deletions.
23 changes: 20 additions & 3 deletions charts/fission-all/templates/NOTES.txt
Expand Up @@ -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!
Expand Down
1 change: 1 addition & 0 deletions charts/fission-all/templates/deployment.yaml
Expand Up @@ -122,6 +122,7 @@ spec:
metadata:
labels:
svc: controller
application: fission-api
spec:
containers:
- name: controller
Expand Down
4 changes: 2 additions & 2 deletions charts/fission-all/templates/svc.yaml
Expand Up @@ -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:
Expand Down
7 changes: 5 additions & 2 deletions charts/fission-all/values.yaml
Expand Up @@ -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
Expand Down
21 changes: 19 additions & 2 deletions charts/fission-core/templates/NOTES.txt
Expand Up @@ -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!
Expand Down
1 change: 1 addition & 0 deletions charts/fission-core/templates/deployment.yaml
Expand Up @@ -122,6 +122,7 @@ spec:
metadata:
labels:
svc: controller
application: fission-api
spec:
containers:
- name: controller
Expand Down
4 changes: 2 additions & 2 deletions charts/fission-core/templates/svc.yaml
Expand Up @@ -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:
Expand Down
7 changes: 5 additions & 2 deletions charts/fission-core/values.yaml
Expand Up @@ -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
Expand Down
19 changes: 18 additions & 1 deletion fission/common.go
Expand Up @@ -157,14 +157,31 @@ 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)

// TODO add a progress bar
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
Expand Down
30 changes: 28 additions & 2 deletions fission/function.go
Expand Up @@ -21,6 +21,7 @@ import (
"errors"
"fmt"
"io/ioutil"
"net"
"net/http"
"net/url"
"os"
Expand Down Expand Up @@ -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)
Expand All @@ -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 {
Expand Down
18 changes: 17 additions & 1 deletion fission/main.go
Expand Up @@ -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)
Expand Down
4 changes: 3 additions & 1 deletion fission/package.go
Expand Up @@ -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
}
Expand Down

0 comments on commit b9a559a

Please sign in to comment.