function yml

This commit is contained in:
Torma Kristóf 2019-10-04 19:50:50 +02:00
parent a6b0055d9c
commit 67be6e7873
Signed by: tormakris
GPG Key ID: DC83C4F2C41B1047
12 changed files with 13 additions and 222 deletions

View File

@ -1,5 +0,0 @@
ignored = ["github.com/kubeless/kubeless/pkg/functions"]
[[constraint]]
name = "github.com/sirupsen/logrus"
branch = "master"

View File

@ -1,11 +0,0 @@
#!/bin/bash
#$1=runtime
#$2=filename
#$3=function name
#$4=handler
kubeless function deploy $3 --runtime $1 --from-file $2 --handler $4
kubeless trigger http create $3 --function-name $3 --path $3 --hostname $3.kubeless
#kubeless autoscale create $3 --max 32 --metric "cpu" --min 3 --value "50"
#Test with curl --data '{"Another": "Echo"}' --header "Host: get-python.192.168.99.100.nip.io" --header "Content-Type:application/json" 192.168.99.100/echo

View File

@ -1,11 +0,0 @@
#!/bin/bash
#$1=runtime
#$2=filename
#$3=function name
#$4=handler
kubeless function deploy $3 --runtime $1 --from-file $2 --handler $4
kubeless trigger kafka create $3 --function-selector created-by=kubeless,function=$3 --trigger-topic "$3-topic"
#Test from within cluster
#kubeless topic publish --topic "$3-topic" --data "Hello World!"

View File

@ -1,42 +0,0 @@
#!/bin/bash
#TODO python3 kornyezetet hozzaadni es szukseg szerint mas kornyezeteket
# a function mappaban levo fajlokra meghivja a deploy_function.sh scriptet ugy,
# hogy a fuggveny neve a fajl neve kiterjesztes nelkul, es a handle neve a fajlban levo fuggveny neve
#TODO lehetne majd irni hozzairni hogy ha tobb func van egy fajlban akkor egy alapertelmezetett ad meg handle-kent
for x in *; do
if [ $x = 'deploy_function.sh' ]; then
continue
fi
if [ $x = 'get_functions.sh' ]; then
continue
fi
echo "Deploying $x"
ispython=$(echo $x | grep .py)
#ispython3=$(cat $x | grep python3)
isgolang=$(echo $x | grep .go)
if [ ! $ispython = "" ]; then
handle=$( cat $x | grep def | sed 's/def \(.*\)(.*/\1/' )
funcname=$( echo $x | sed 's/\(.*\)\.py/\1/')
sh deploy_function.sh python2.7 $x $funcname $handle
echo "file name: $x"
echo "function name: $funcname"
echo "handle name: $handle"
elif [ ! $isgolang = "" ]; then
echo "goo handle elott: $x"
handle=$( cat $x | grep 'func ' | sed 's/func \(.*\)(.*(.*/\1/' )
funcname=$( echo $x | sed 's/\(.*\)\.go/\1/')
sh deploy_function.sh go1.10 $x $funcname $handle
echo "file name: $x"
echo "function name: $funcname"
echo "handle name: $handle"
fi
done

View File

@ -1,10 +0,0 @@
package kubeless
import (
"github.com/kubeless/kubeless/pkg/functions"
)
// Foo sample function
func Foo(event functions.Event, context functions.Context) (string, error) {
return "Hello world!", nil
}

View File

@ -1,5 +0,0 @@
module.exports = {
foo: function (event, context) {
return 'hello world!';
}
}

View File

@ -1,2 +0,0 @@
def foo(event, context):
return "hello world"

13
functions/helloworld.yml Normal file
View File

@ -0,0 +1,13 @@
apiVersion: serving.knative.dev/v1alpha1
kind: Service
metadata:
name: helloworld-go
namespace: default
spec:
template:
spec:
containers:
- image: docker.pkg.github.com/tormachris/knative-report-functions/hello-world
env:
- name: TARGET
value: "Go"

View File

@ -1,27 +0,0 @@
package kubeless
import (
"fmt"
"math"
"strconv"
"github.com/kubeless/kubeless/pkg/functions"
"github.com/sirupsen/logrus"
)
func IsPrime(event functions.Event, context functions.Context) (string, error) {
num, err := strconv.Atoi(event.Data)
if err != nil {
return "", fmt.Errorf("Failed to parse %s as int! %v", event.Data, err)
}
logrus.Infof("Checking if %s is prime", event.Data)
if num <= 1 {
return fmt.Sprintf("%d is not prime", num), nil
}
for i := 2; i <= int(math.Floor(float64(num)/2)); i++ {
if num%i == 0 {
return fmt.Sprintf("%d is not prime", num), nil
}
}
return fmt.Sprintf("%d is prime", num), nil
}

View File

@ -1,26 +0,0 @@
module.exports = {
handler: (event, context) => {
num=event.data;
if (num == 1) return "Not Prime";
num += 2;
var upper = Math.sqrt(num);
var sieve = new Array(num)
.join(',').split(',') // get values for map to work
.map(function(){ return "Prime" });
for (var i = 2; i <= num; i++) {
if (sieve[i]) {
for (var j = i * i; j < num; j += i) {
sieve[j] = false;
};
};
};
if (sieve[num-2]) {
return "Prime";
};
else {
return "Not Prime";
};
},
};

View File

@ -1,13 +0,0 @@
def isprime(event,context):
n= event['data']
if n == 2 or n == 3: return "Prime"
if n < 2 or n%2 == 0: return "Not Prime"
if n < 9: return "Prime"
if n%3 == 0: return "Not Prime"
r = int(n**0.5)
f = 5
while f <= r:
if n%f == 0: return "Not Prime"
if n%(f+2) == 0: return "Not Prime"
f +=6
return "Prime"

View File

@ -1,70 +0,0 @@
package kubeless
import (
"fmt"
"github.com/kubeless/kubeless/pkg/functions"
)
func main() {
//Defining 2D matrices
m1 := [3][3]int{
[3]int{1, 1, 1},
[3]int{1, 1, 1},
[3]int{1, 1, 1},
}
m2 := [3][3]int{
[3]int{1, 1, 1},
[3]int{1, 1, 1},
[3]int{1, 1, 1},
}
//Declaring a matrix variable for holding the multiplication results
var m3 [3][3]int
for i := 0; i < 3; i++ {
for j := 0; j < 3; j++ {
m3[i][j] = 0
for k := 0; k < 3; k++ {
m3[i][j] = m3[i][j] + (m1[i][k] * m2[k][j])
}
}
}
twoDimensionalMatrices := [3][3][3]int{m1, m2, m3}
matrixNames := []string{"MATRIX1", "MATRIX2", "MATRIX3 = MATRIX1*MATRIX2"}
for index, m := range twoDimensionalMatrices {
fmt.Println(matrixNames[index],":")
showMatrixElements(m)
fmt.Println()
}
}
//A function that displays matix elements
func showMatrixElements(m [3][3]int) {
for i := 0; i < 3; i++ {
for j := 0; j < 3; j++ {
fmt.Printf("%d\t", m[i][j])
}
fmt.Println()
}
}
/*
MATRIX1 1 :
1 1 1
1 1 1
1 1 1
MATRIX2 2 :
1 1 1
1 1 1
1 1 1
MATRIX3 = MATRIX1*MATRIX2 3 :
3 3 3
3 3 3
3 3 3
*/