Add kubernetes podSpec support in fission spec (#1106)

This commit is contained in:
Vishal
2019-05-29 03:31:14 +08:00
committed by Ta-Ching Chen
parent 49f9944b86
commit d578539391
19 changed files with 578 additions and 30 deletions
+2 -1
View File
@@ -477,7 +477,8 @@ run_all_tests() {
$ROOT/test/tests/test_pass.sh \
$ROOT/test/tests/test_router_cache_invalidation.sh \
$ROOT/test/tests/test_specs/test_spec.sh \
$ROOT/test/tests/test_specs/test_spec_multifile.sh
$ROOT/test/tests/test_specs/test_spec_multifile.sh \
$ROOT/test/tests/test_specs/test_spec_merge/test_spec_merge.sh
FAILURES=$?
# FIXME: run tests with newdeploy one by one.
@@ -0,0 +1,7 @@
module.exports = async function(context) {
return {
status: 200,
body: "hello, world!\n"
};
}
@@ -0,0 +1,42 @@
Fission Specs
=============
This is a set of specifications for a Fission app. This includes functions,
environments, and triggers; we collectively call these things "resources".
How to use these specs
----------------------
These specs are handled with the 'fission spec' command. See 'fission spec --help'.
'fission spec apply' will "apply" all resources specified in this directory to your
cluster. That means it checks what resources exist on your cluster, what resources are
specified in the specs directory, and reconciles the difference by creating, updating or
deleting resources on the cluster.
'fission spec apply' will also package up your source code (or compiled binaries) and
upload the archives to the cluster if needed. It uses 'ArchiveUploadSpec' resources in
this directory to figure out which files to archive.
You can use 'fission spec apply --watch' to watch for file changes and continuously keep
the cluster updated.
You can add YAMLs to this directory by writing them manually, but it's easier to generate
them. Use 'fission function create --spec' to generate a function spec,
'fission environment create --spec' to generate an environment spec, and so on.
You can edit any of the files in this directory, except 'fission-deployment-config.yaml',
which contains a UID that you should never change. To apply your changes simply use
'fission spec apply'.
fission-deployment-config.yaml
------------------------------
fission-deployment-config.yaml contains a UID. This UID is what fission uses to correlate
resources on the cluster to resources in this directory.
All resources created by 'fission spec apply' are annotated with this UID. Resources on
the cluster that are _not_ annotated with this UID are never modified or deleted by
fission.
@@ -0,0 +1,72 @@
apiVersion: fission.io/v1
kind: Environment
metadata:
creationTimestamp: null
name: nodend
namespace: default
spec:
TerminationGracePeriod: 360
builder: {}
keeparchive: false
poolsize: 0
resources: {}
runtime:
functionendpointport: 0
image: fission/node-env
loadendpointpath: ""
loadendpointport: 0
container:
name: nodehellond
volumeMounts:
- name: cvol
mountPath: /etc/cvoldata
readOnly: true
podspec:
hostname: foo-bar
# A container which will be merged with for pool manager
Containers:
- name: nodehellond
image: fission/node-env
volumeMounts:
- name: funcvol
mountPath: /etc/funcdata
readOnly: true
# A additional container in the pods
- name: yanode
image: fission/node-env
command: ['sh', '-c', 'sleep 36000000000']
# Init container before function
initContainers:
- name: init-node
image: fission/node-env
command: ['sh', '-c', 'cat /etc/infopod/labels']
volumeMounts:
- name: infopod
mountPath: /etc/infopod
readOnly: false
tolerations:
- key: "reservation"
operator: "Equal"
value: "fission"
effect: "NoSchedule"
# Additional volumes
volumes:
- name: infopod
downwardAPI:
items:
- path: "labels"
fieldRef:
fieldPath: metadata.labels
- name: funcvol
downwardAPI:
items:
- path: "labels"
fieldRef:
fieldPath: metadata.labels
- name: cvol
downwardAPI:
items:
- path: "labels"
fieldRef:
fieldPath: metadata.labels
version: 1
@@ -0,0 +1,72 @@
apiVersion: fission.io/v1
kind: Environment
metadata:
creationTimestamp: null
name: nodep
namespace: default
spec:
TerminationGracePeriod: 360
builder: {}
keeparchive: false
poolsize: 3
resources: {}
runtime:
functionendpointport: 0
image: fission/node-env
loadendpointpath: ""
loadendpointport: 0
container:
name: nodep
volumeMounts:
- name: cvol
mountPath: /etc/cvoldata
readOnly: true
podspec:
hostname: foo-bar
# A container which will be merged with for pool manager
Containers:
- name: nodep
image: fission/node-env
volumeMounts:
- name: funcvol
mountPath: /etc/funcdata
readOnly: true
# A additional container in the pods
- name: yanode
image: fission/node-env
command: ['sh', '-c', 'sleep 36000000000']
# Init container before function
initContainers:
- name: init-node
image: fission/node-env
command: ['sh', '-c', 'cat /etc/infopod/labels']
volumeMounts:
- name: infopod
mountPath: /etc/infopod
readOnly: false
tolerations:
- key: "reservation"
operator: "Equal"
value: "fission"
effect: "NoSchedule"
# Additional volumes
volumes:
- name: infopod
downwardAPI:
items:
- path: "labels"
fieldRef:
fieldPath: metadata.labels
- name: funcvol
downwardAPI:
items:
- path: "labels"
fieldRef:
fieldPath: metadata.labels
- name: cvol
downwardAPI:
items:
- path: "labels"
fieldRef:
fieldPath: metadata.labels
version: 1
@@ -0,0 +1,7 @@
# This file is generated by the 'fission spec init' command.
# See the README in this directory for background and usage information.
# Do not edit the UID below: that will break 'fission spec apply'
apiVersion: fission.io/v1
kind: DeploymentConfig
name: spec-merge
uid: b1573a35-f3a2-45a8-a430-1f1a08d71177
@@ -0,0 +1,24 @@
apiVersion: fission.io/v1
kind: Function
metadata:
creationTimestamp: null
name: nodehellond
namespace: default
spec:
InvokeStrategy:
ExecutionStrategy:
ExecutorType: newdeploy
MaxScale: 3
MinScale: 1
TargetCPUPercent: 80
StrategyType: execution
configmaps: null
environment:
name: nodend
namespace: default
package:
packageref:
name: hello-js-vm2y
namespace: default
resources: {}
secrets: null
@@ -0,0 +1,50 @@
include:
- hello.js
kind: ArchiveUploadSpec
name: hello-js-leSC
---
apiVersion: fission.io/v1
kind: Package
metadata:
creationTimestamp: null
name: hello-js-vm2y
namespace: default
spec:
deployment:
checksum: {}
type: url
url: archive://hello-js-leSC
environment:
name: nodep
namespace: default
source:
checksum: {}
status:
buildstatus: none
---
apiVersion: fission.io/v1
kind: Function
metadata:
creationTimestamp: null
name: nodehellop
namespace: default
spec:
InvokeStrategy:
ExecutionStrategy:
ExecutorType: poolmgr
MaxScale: 0
MinScale: 0
TargetCPUPercent: 0
StrategyType: execution
configmaps: null
environment:
name: nodep
namespace: default
package:
packageref:
name: hello-js-vm2y
namespace: default
resources: {}
secrets: null
+38
View File
@@ -0,0 +1,38 @@
#!/bin/bash
set -euo pipefail
env_p=nodep
fn_p=nodehellop
env_n=nodend
fn_nd=nodehellond
cleanup() {
echo "Cleaning up..."
popd
fission spec destroy || true
}
trap cleanup EXIT
pushd $(dirname $0)
fission spec apply
fission fn test --name $fn_p
fission fn test --name $fn_nd
hnd=$(kubectl -n $FUNCTION_NAMESPACE get deployment -l=functionName=$fn_nd -ojsonpath='{.items[0].spec.template.spec.hostname}')
if [[ "${hnd}" == "foo-bar" ]]
then
echo "Hostname matches for newdeployment function, podspec test 1/2 passsed"
fi
hnp=$(kubectl -n $FUNCTION_NAMESPACE get deployment -l=environmentName=$env_p -ojsonpath='{.items[0].spec.template.spec.hostname}')
if [[ "${hnp}" == "foo-bar" ]]
then
echo "Hostname matches for poolmgr function, podspec test 2/2 passsed"
fi