fix: remove references to unused binaries appsody, kn, kubectl

This commit is contained in:
Luke K 2020-08-19 10:00:50 +09:00
parent 3d51c27c6c
commit ce48083a10
No known key found for this signature in database
GPG Key ID: 4896F75BAF2E1966
16 changed files with 121 additions and 652 deletions

View File

@ -1,60 +0,0 @@
package appsody
import (
"errors"
"fmt"
"os"
"os/exec"
"github.com/boson-project/faas"
)
// Runner of Functions using the appsody binary.
type Runner struct {
// Verbose logging flag.
Verbose bool
}
// NewRunner creates an instance of an appsody-backed runner.
func NewRunner() *Runner {
return &Runner{}
}
// Run the Function at path
func (n *Runner) Run(f faas.Function) error {
// Check for the appsody binary explicitly so that we can return
// an extra-friendly error message.
_, err := exec.LookPath("appsody")
if err != nil {
return errors.New("please install 'appsody'")
}
// Extra arguments to appsody
args := []string{"run"}
// If verbosity is enabled, pass along as an environment variable to the Function.
if n.Verbose {
args = append(args, []string{"--docker-options", "-e VERBOSE=true"}...)
}
// Set up the command with extra arguments and to run rooted at path
cmd := exec.Command("appsody", args...)
cmd.Dir = f.Root
// If verbose logging is enabled, echo command
if n.Verbose {
fmt.Println(cmd)
}
// We need to show the user all output, so a method to squelch
// appsody's chattiness is not immediately apparent.
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
// Run the command, echoing captured stderr as well ass the cmd internal error.
// Will run until explicitly canceled.
// TODO: will we need to run with context and explicitly wait for a custom
// signal in order to play ball with tests?
fmt.Println(cmd)
return cmd.Run()
}

View File

@ -1,4 +0,0 @@
# www.example.com
The directory in which the appsody concrete implementations use
as the root for tests.

View File

@ -1,2 +0,0 @@
project-name: testfunc
stack: quay.io/boson/go:0.0

View File

@ -1,5 +0,0 @@
module function
go 1.13
require github.com/cloudevents/sdk-go v0.10.2

View File

@ -1,198 +0,0 @@
cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
cloud.google.com/go v0.38.0/go.mod h1:990N+gfupTy94rShfmMCWGDn0LpTmnzTp2qbd1dvSRU=
cloud.google.com/go v0.40.0/go.mod h1:Tk58MuI9rbLMKlAjeO/bDnteAx7tX2gJIXw4T5Jwlro=
contrib.go.opencensus.io/exporter/ocagent v0.4.12/go.mod h1:450APlNTSR6FrvC3CTRqYosuDstRB9un7SOx2k/9ckA=
contrib.go.opencensus.io/exporter/prometheus v0.1.0/go.mod h1:cGFniUXGZlKRjzOyuZJ6mgB+PgBcCIa79kEKR8YCW+A=
github.com/Azure/azure-sdk-for-go v30.1.0+incompatible/go.mod h1:9XXNKU+eRnpl9moKnB4QOLf1HestfXbmab5FXxiDBjc=
github.com/Azure/go-autorest/autorest v0.2.0/go.mod h1:AKyIcETwSUFxIcs/Wnq/C+kwCtlEYGUVd7FPNb2slmg=
github.com/Azure/go-autorest/autorest/adal v0.1.0/go.mod h1:MeS4XhScH55IST095THyTxElntu7WqB7pNbZo8Q5G3E=
github.com/Azure/go-autorest/autorest/date v0.1.0/go.mod h1:plvfp3oPSKwf2DNjlBjWF/7vwR+cUD/ELuzDCXwHUVA=
github.com/Azure/go-autorest/autorest/mocks v0.1.0/go.mod h1:OTyCOPRA2IgIlWxVYxBee2F5Gr4kF2zd2J5cFRaIDN0=
github.com/Azure/go-autorest/autorest/to v0.2.0/go.mod h1:GunWKJp1AEqgMaGLV+iocmRAJWqST1wQYhyyjXJ3SJc=
github.com/Azure/go-autorest/autorest/validation v0.1.0/go.mod h1:Ha3z/SqBeaalWQvokg3NZAlQTalVMtOIAs1aGK7G6u8=
github.com/Azure/go-autorest/logger v0.1.0/go.mod h1:oExouG+K6PryycPJfVSxi/koC6LSNgds39diKLz7Vrc=
github.com/Azure/go-autorest/tracing v0.1.0/go.mod h1:ROEEAFwXycQw7Sn3DXNtEedEvdeRAgDr0izn4z5Ij88=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/Shopify/sarama v1.19.0/go.mod h1:FVkBWblsNy7DGZRfXLU0O9RCGt5g3g3yEuWXgklEdEo=
github.com/Shopify/toxiproxy v2.1.4+incompatible/go.mod h1:OXgGpZ6Cli1/URJOF1DMxUHB2q5Ap20/P/eIdh4G0pI=
github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=
github.com/apache/thrift v0.12.0/go.mod h1:cp2SuWMxlEZw2r+iP2GNCdIi4C1qmUzdZFSVb+bacwQ=
github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q=
github.com/census-instrumentation/opencensus-proto v0.2.0/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
github.com/cloudevents/sdk-go v0.10.2 h1:CAqHqDHmBkCG4OUeUBt7q2Ql8KV25U+bgPUtlcJelZ4=
github.com/cloudevents/sdk-go v0.10.2/go.mod h1:EHG6NmU3XkIeuueER6+vbnhYfWlgVlfUQVzPC+UK7ao=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ=
github.com/eapache/go-resiliency v1.1.0/go.mod h1:kFI+JgMyC7bLPUVY133qvEBtVayf5mFgVsvEsIPBvNs=
github.com/eapache/go-xerial-snappy v0.0.0-20180814174437-776d5712da21/go.mod h1:+020luEh2TKB4/GOp8oxxtq0Daoen/Cii55CzbTV6DU=
github.com/eapache/queue v1.1.0/go.mod h1:6eCeP0CKFpHLu8blIFXhExK/dRa7WDZfr6jVFPTqq+I=
github.com/fortytw2/leaktest v1.3.0/go.mod h1:jDsjWgpAGjm2CA7WthBh/CdZYEPF31XHquHwclZch5g=
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as=
github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE=
github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY=
github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ=
github.com/gogo/protobuf v1.2.0/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ=
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A=
github.com/golang/mock v1.2.0/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A=
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/golang/snappy v0.0.0-20180518054509-2e65f85255db/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ=
github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs=
github.com/google/pprof v0.0.0-20181206194817-3ea8567a2e57/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc=
github.com/google/uuid v1.1.1 h1:Gkbcsh/GbpXz7lPftLA3P6TYMwjCLYm83jiFQZF/3gY=
github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg=
github.com/gorilla/context v1.1.1/go.mod h1:kBGZzfjB9CEq2AlWe17Uuf7NDRt0dE0s8S51q0aT7Yg=
github.com/gorilla/mux v1.6.2/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2zaAs=
github.com/grpc-ecosystem/grpc-gateway v1.8.5/go.mod h1:vNeuVxBJEsws4ogUvrchl83t/GYV9WGTSLVdBhOQFDY=
github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
github.com/hashicorp/golang-lru v0.5.1 h1:0hERBMJE1eitiLkihrMvRVBYAkpHzc/J3QdDN+dAcgU=
github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU=
github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w=
github.com/kelseyhightower/envconfig v1.4.0/go.mod h1:cccZRl6mQpaq41TPp5QxidR+Sa3axMbJDNb//FQX6Gg=
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0=
github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
github.com/nats-io/jwt v0.3.0/go.mod h1:fRYCDE99xlTsqUzISS1Bi75UBJ6ljOJQOAAu5VglpSg=
github.com/nats-io/jwt v0.3.2/go.mod h1:/euKqTS1ZD+zzjYrY7pseZrTtWQSjujC7xjPc8wL6eU=
github.com/nats-io/nats-server/v2 v2.1.2/go.mod h1:Afk+wRZqkMQs/p45uXdrVLuab3gwv3Z8C4HTBu8GD/k=
github.com/nats-io/nats.go v1.9.1/go.mod h1:ZjDU1L/7fJ09jvUSRVBR2e7+RnLiiIQyqyzEE/Zbp4w=
github.com/nats-io/nkeys v0.1.0/go.mod h1:xpnFELMwJABBLVhffcfd1MZx6VsNRFpEugbxziKVo7w=
github.com/nats-io/nkeys v0.1.3/go.mod h1:xpnFELMwJABBLVhffcfd1MZx6VsNRFpEugbxziKVo7w=
github.com/nats-io/nuid v1.0.1/go.mod h1:19wcPz3Ph3q0Jbyiqsd0kePYG7A95tJPxeL+1OSON2c=
github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
github.com/onsi/ginkgo v1.7.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
github.com/onsi/gomega v1.4.3/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY=
github.com/openzipkin/zipkin-go v0.1.6/go.mod h1:QgAqvLzwWbR/WpD4A3cGpPtJrZXNIiJc5AZX7/PBEpw=
github.com/pierrec/lz4 v2.0.5+incompatible/go.mod h1:pdkljMzZIN41W+lC3N2tnIh5sFi+IEE17M5jbnwPHcY=
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw=
github.com/prometheus/client_golang v0.9.2/go.mod h1:OsXs2jCmiKlQ1lTBmv21f2mNfw4xf/QclQDMrYNZzcM=
github.com/prometheus/client_golang v0.9.3-0.20190127221311-3c4408c8b829/go.mod h1:p2iRAGwDERtqlqzRXnrOVns+ignqQo//hLXqYxZYVNs=
github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo=
github.com/prometheus/client_model v0.0.0-20190115171406-56726106282f/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo=
github.com/prometheus/common v0.0.0-20181126121408-4724e9255275/go.mod h1:daVV7qP5qjZbuso7PdcryaAu0sAZbrN9i7WWcTMWvro=
github.com/prometheus/common v0.2.0/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4=
github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk=
github.com/prometheus/procfs v0.0.0-20181204211112-1dc9a6cbc91a/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk=
github.com/prometheus/procfs v0.0.0-20190117184657-bf6a532e95b1/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk=
github.com/rcrowley/go-metrics v0.0.0-20181016184325-3113b8401b8a/go.mod h1:bCqnVzQkZxMG4s8nGwiZ5l3QUCyqpo9Y+/ZMZ9VjZe4=
github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6SoW27p1b0cqNHllgS5HIMJraePCO15w5zCzIWYg=
github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
go.opencensus.io v0.20.1/go.mod h1:6WKK9ahsWS3RSO+PY9ZHZUfv2irvY6gN279GOPZjmmk=
go.opencensus.io v0.20.2/go.mod h1:6WKK9ahsWS3RSO+PY9ZHZUfv2irvY6gN279GOPZjmmk=
go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU=
go.opencensus.io v0.22.0 h1:C9hSCOW830chIVkdja34wa6Ky+IzWllkUinR+BtRZd4=
go.opencensus.io v0.22.0/go.mod h1:+kGneAE2xo2IficOXnaByMWTGM9T73dGwxeWcUqIpI8=
go.uber.org/atomic v1.4.0 h1:cxzIVoETapQEqDhQu3QfnvXAV4AlzcvUCxkVUFw3+EU=
go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE=
go.uber.org/multierr v1.1.0 h1:HoEmRHQPVSqub6w2z2d2EOVs2fjyFRGyofhKuyDq0QI=
go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0=
go.uber.org/zap v1.10.0 h1:ORx85nbTijNz8ljznvCMR1ZBIPKFn3jQrag10X2AsuM=
go.uber.org/zap v1.10.0/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q=
golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20190701094942-4def268fd1a4/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU=
golang.org/x/lint v0.0.0-20190301231843-5614ed5bae6f/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
golang.org/x/lint v0.0.0-20190409202823-959b441ac422/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20181114220301-adae6a3d119a/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20181201002055-351d144fa1fc/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20181220203305-927f97764cc3/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20190108225652-1e06a53dbb7e/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20190125091013-d26f9f9a57f3/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190501004415-9ce7a6920f09/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190503192946-f4e77d36d62c/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20181107165924-66b7b1311ac8/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20181116152217-5ac8a444bdc5/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20181122145206-62eef0e2fa9b/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190502145724-3ef323f4f1fd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190507160741-ecd444e8653b/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190726091711-fc99dfbffb4e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/tools v0.0.0-20180828015842-6cd1fcedba52/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY=
golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
golang.org/x/tools v0.0.0-20190312170243-e65039ee4138/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
golang.org/x/tools v0.0.0-20190506145303-2d16b83fe98c/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q=
google.golang.org/api v0.3.1/go.mod h1:6wY9I6uQWHQ8EM57III9mq/AjF+i8G65rmVagqKMtkk=
google.golang.org/api v0.4.0/go.mod h1:8k5glujaEP+g9n7WNsDg8QP6cUVNI86fCNMcbazEtwE=
google.golang.org/api v0.6.0/go.mod h1:btoxGiFvQNVUZQ8W08zLtrVS08CNpINPEfxXxgJL1Q4=
google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM=
google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
google.golang.org/appengine v1.5.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc=
google.golang.org/genproto v0.0.0-20190307195333-5fe7a883aa19/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE=
google.golang.org/genproto v0.0.0-20190418145605-e7d98fc518a7/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE=
google.golang.org/genproto v0.0.0-20190425155659-357c62f0e4bb/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE=
google.golang.org/genproto v0.0.0-20190502173448-54afdca5d873/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE=
google.golang.org/genproto v0.0.0-20190530194941-fb225487d101/go.mod h1:z3L6/3dTEVtUr6QSP8miRzeRqwQOioJ9I66odjN4I7s=
google.golang.org/grpc v1.17.0/go.mod h1:6QZJwpn2B+Zp71q/5VxRsJ6NXXVCE5NRUHRo+f3cWCs=
google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c=
google.golang.org/grpc v1.19.1/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c=
google.golang.org/grpc v1.20.1/go.mod h1:10oTOabMzJvdu6/UiuZezV6QK5dSlG84ov/aaiqXj38=
gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys=
gopkg.in/resty.v1 v1.12.0/go.mod h1:mDo4pnntr5jdWRML875a/NmxYqAlA73dVijT2AXvQQo=
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw=
gopkg.in/yaml.v2 v2.0.0-20170812160011-eb3733d160e7/go.mod h1:JAlM8MvJe8wmxCU4Bli9HhUf9+ttbYbLASfIpnQbh74=
gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
honnef.co/go/tools v0.0.0-20180728063816-88497007e858/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
honnef.co/go/tools v0.0.0-20190418001031-e561f6794a2a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
pack.ag/amqp v0.11.0/go.mod h1:4/cbmt4EJXSKlG6LCfWHoqmN0uFdy5i/+YFz+fTfhV4=
rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8=

View File

@ -1,115 +0,0 @@
package function
import (
"context"
"fmt"
"net/url"
"testing"
cloudevents "github.com/cloudevents/sdk-go"
)
// TestHandle ensures that Handle accepts a valid CloudEvent without error.
func TestHandle(t *testing.T) {
// A minimal, but valid, event.
event := cloudevents.NewEvent()
event.SetID("TEST-EVENT-01")
event.SetType("com.example.cloudevents.test")
event.SetSource("http://localhost:8080/")
// Invoke the defined handler.
if err := Handle(context.Background(), event); err != nil {
t.Fatal(err)
}
}
// TestHandleInvalid ensures that an invalid input event generates an error.
func TestInvalidInput(t *testing.T) {
invalidEvent := cloudevents.NewEvent() // missing required fields
// Attempt to handle the invalid event, ensuring that the handler validats events.
if err := Handle(context.Background(), invalidEvent); err == nil {
t.Fatalf("handler did not generate error on invalid event. Missing .Validate() check?")
}
}
// TestE2E also tests the Handle function, but does so by creating an actual
// CloudEvents HTTP sending and receiving clients. This is a bit redundant
// with TestHandle, but illustrates how clients are configured and used.
func TestE2E(t *testing.T) {
var (
receiver cloudevents.Client
address string // at which the receiver beings listening (os-chosen port)
sender cloudevents.Client // sends an event to the receiver via HTTP
handler = Handle // test the user-defined Handler
err error
)
if receiver, address, err = newReceiver(t); err != nil {
t.Fatal(err)
}
if sender, err = newSender(t, address); err != nil {
t.Fatal(err)
}
go func() {
if err := receiver.StartReceiver(context.Background(), handler); err != nil {
t.Fatal(err)
}
}()
_, resp, err := sender.Send(context.Background(), newEvent(t, TestData{Sequence: 1, Message: "test message"}))
if err != nil {
t.Fatal(err)
}
fmt.Printf("OK:\n%v\n", resp)
}
type TestData struct {
Sequence int `json:"id"`
Message string `json:"message"`
}
func newReceiver(t *testing.T) (c cloudevents.Client, address string, err error) {
t.Helper()
transport, err := cloudevents.NewHTTPTransport(
cloudevents.WithPort(0), // use an OS-chosen unused port.
cloudevents.WithPath("/"))
if err != nil {
return
}
address = fmt.Sprintf("http://127.0.0.1:%v/", transport.GetPort())
c, err = cloudevents.NewClient(transport)
return
}
func newSender(t *testing.T, address string) (c cloudevents.Client, err error) {
t.Helper()
transport, err := cloudevents.NewHTTPTransport(
cloudevents.WithTarget(address),
cloudevents.WithEncoding(cloudevents.HTTPStructuredV01))
if err != nil {
return
}
return cloudevents.NewClient(transport, cloudevents.WithTimeNow())
}
func newEvent(t *testing.T, data TestData) (event cloudevents.Event) {
source, err := url.Parse("https://example.com/cloudfunction/cloudevent/cmd/runner")
if err != nil {
t.Fatal(err)
}
contentType := "application/json"
event = cloudevents.Event{
Context: cloudevents.EventContextV01{
EventID: "test-event-01",
EventType: "com.cloudevents.sample.sent",
Source: cloudevents.URLRef{URL: *source},
ContentType: &contentType,
}.AsV01(),
Data: &data,
}
return
}

View File

@ -22,7 +22,7 @@ func NewBuilder() *Builder {
return &Builder{}
}
var runtime2pack = map[string]string{
var Runtimes = map[string]string{
"quarkus": "quay.io/boson/faas-quarkus-builder",
"node": "quay.io/boson/faas-nodejs-builder",
"go": "quay.io/boson/faas-go-builder",
@ -31,7 +31,7 @@ var runtime2pack = map[string]string{
// Build the Function at path.
func (builder *Builder) Build(f faas.Function) (err error) {
// dervive the builder from the specificed runtime
packBuilder, ok := runtime2pack[f.Runtime]
packBuilder, ok := Runtimes[f.Runtime]
if !ok {
return errors.New(fmt.Sprint("unsupported runtime: ", f.Runtime))
}

View File

@ -7,7 +7,7 @@ import (
"path"
"github.com/boson-project/faas"
"github.com/boson-project/faas/appsody"
"github.com/boson-project/faas/buildpacks"
"github.com/boson-project/faas/knative"
"github.com/spf13/cobra"
)
@ -28,8 +28,8 @@ func CompleteFunctionList(cmd *cobra.Command, args []string, toComplete string)
return
}
func CompleteRuntimeList(cmd *cobra.Command, args []string, toComplete string) (strings []string, directive cobra.ShellCompDirective) {
strings = make([]string, 0, len(appsody.StackShortNames))
for lang := range appsody.StackShortNames {
strings = []string{}
for lang := range buildpacks.Runtimes {
strings = append(strings, lang)
}
directive = cobra.ShellCompDirectiveDefault

View File

@ -5,7 +5,7 @@ import (
"github.com/spf13/cobra"
"github.com/boson-project/faas"
"github.com/boson-project/faas/appsody"
"github.com/boson-project/faas/docker"
)
func init() {
@ -17,10 +17,10 @@ var runCmd = &cobra.Command{
Use: "run",
Short: "Run Function locally",
Long: "Runs the function locally within an isolated environment. Modifications to the Function trigger a reload. This holds open the current window with the logs from the running Function, and the run is canceled on interrupt.",
RunE: run,
RunE: runRun,
}
func run(cmd *cobra.Command, args []string) (err error) {
func runRun(cmd *cobra.Command, args []string) (err error) {
var (
path = "" // defaults to current working directory
verbose = viper.GetBool("verbose")
@ -30,7 +30,7 @@ func run(cmd *cobra.Command, args []string) (err error) {
path = args[0]
}
runner := appsody.NewRunner()
runner := docker.NewRunner()
runner.Verbose = verbose
client := faas.New(

View File

@ -39,7 +39,7 @@ func (n *Pusher) Push(f faas.Function) (err error) {
// standard output and error.
cmd := exec.Command("docker", "push", f.Image)
// If verbose logging is enabled, echo appsody's chatty stdout.
// If verbose logging is enabled, echo chatty stdout.
if n.Verbose {
fmt.Println(cmd)
cmd.Stdout = os.Stdout
@ -52,7 +52,7 @@ func (n *Pusher) Push(f faas.Function) (err error) {
// Run the command, echoing captured stderr as well ass the cmd internal error.
err = cmd.Run()
if err != nil {
// TODO: sanitize stderr from appsody, or submit a PR to remove duplicates etc.
// TODO: sanitize stderr from docker?
err = fmt.Errorf("%v. %v", stderr.String(), err.Error())
}
return

66
docker/runner.go Normal file
View File

@ -0,0 +1,66 @@
package docker
import (
"errors"
"fmt"
"os"
"os/exec"
"github.com/boson-project/faas"
)
// Runner of functions using the docker command.
type Runner struct {
// Verbose logging flag.
Verbose bool
}
// NewRunner creates an instance of a docker-backed runner.
func NewRunner() *Runner {
return &Runner{}
}
// Run the function at path
func (n *Runner) Run(f faas.Function) error {
// Check for the docker binary explicitly so that we can return
// an extra-friendly error message.
_, err := exec.LookPath("docker")
if err != nil {
return errors.New("please install 'docker'")
}
if f.Image == "" {
return errors.New("Function has no associated image. Has it been built?")
}
// Extra arguments to docker
args := []string{"run", "--rm", "-t", "-p=8080:8080"}
// If verbosity is enabled, pass along as an environment variable to the Function.
if n.Verbose {
args = append(args, []string{"-e VERBOSE=true"}...)
}
args = append(args, f.Image)
// Set up the command with extra arguments and to run rooted at path
cmd := exec.Command("docker", args...)
cmd.Dir = f.Root
// If verbose logging is enabled, echo command
if n.Verbose {
fmt.Println(cmd)
}
// We need to show the user all output, so a method to squelch
// docker's chattiness is not immediately apparent.
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
// Run the command, echoing captured stderr as well ass the cmd internal error.
// Will run until explicitly canceled.
// TODO: this runner is current stubbed pending an architectural discussion
// on how closely we would like to emulate the previous funcitonality, and
// if we can use Grid as a localhost integraiton events fabric.
fmt.Println(cmd)
return cmd.Run()
}

44
docker/runner_test.go Normal file
View File

@ -0,0 +1,44 @@
package docker_test
import (
"flag"
"fmt"
"os"
"testing"
"github.com/boson-project/faas"
"github.com/boson-project/faas/docker"
)
// Docker Run Integraiton Test
// This is an integraiton test meant to be manually run in order to confirm proper funcitoning of the docker runner.
// It requires that the funciton already be built.
var enableTestDocker = flag.Bool("enable-test-docker", false, "Enable tests requiring local docker.")
func TestDockerRun(t *testing.T) {
// Skip this test unless explicitly enabled, as it is more of
// an integration test.
if !*enableTestDocker {
fmt.Fprintln(os.Stdout, "Skipping docker integration test for 'run'. Enable with --enable-test-docker")
t.Skip()
}
f, err := faas.NewFunction("testdata/example.com/runnable")
if err != nil {
t.Fatal(err)
}
// TODO: This test is too tricky, as it requires the related image be
// already built. Build the funciton prior to running?
runner := docker.NewRunner()
runner.Verbose = true
if err = runner.Run(f); err != nil {
t.Fatal(err)
}
/* TODO
// submit cloud event
// send os.SIGUSR1 in leay of SIGTERM
*/
}

View File

@ -179,7 +179,6 @@ func assertEmptyRoot(path string) (err error) {
// Function rooted in the given directory.
var contentiousFiles = []string{
ConfigFile,
".appsody-config.yaml",
}
// contentiousFilesIn the given directoy

View File

@ -1,65 +0,0 @@
package kn
import (
"bytes"
"errors"
"fmt"
"os"
"os/exec"
"time"
"github.com/boson-project/faas"
"github.com/boson-project/faas/k8s"
)
// Updater implemented using the kn binary.
type Updater struct {
// Verbose logging.
Verbose bool
}
// NewUpdater creates an instance of the kubectl-based deployer.
func NewUpdater() *Updater {
return &Updater{}
}
// Update the named service with the new image.
func (d *Updater) Update(name, image string) (err error) {
// assert kubectl
if _, err = exec.LookPath("kn"); err != nil {
return errors.New("please install 'kn'")
}
// Convert the project name proper (a valid domain) to how it is being
// represented in kubernetes: as a domain label (RFC1035)
// for use as the service's deployed name.
project, err := k8s.ToSubdomain(name)
if err != nil {
return
}
timestamp := fmt.Sprintf("BUILT=%v", time.Now().Format("20060102T150405"))
// TODO: use knative client directly.
// TODO: use tags and traffic splitting.
cmd := exec.Command("kn", "service", "update", project, "--env", timestamp, "--namespace", faas.DefaultNamespace)
// If verbose logging is enabled, echo appsody's chatty stdout.
if d.Verbose {
fmt.Println(cmd)
cmd.Stdout = os.Stdout
}
// Capture stderr for echoing on failure.
var stderr bytes.Buffer
cmd.Stderr = &stderr
// Run the command, echoing captured stderr as well ass the cmd internal error.
if err = cmd.Run(); err != nil {
// TODO: sanitize stderr from appsody, or submit a PR to remove duplicates etc.
return fmt.Errorf("%v. %v", stderr.String(), err.Error())
}
// TODO: explicitly pull address:
return nil
}

View File

@ -1,131 +0,0 @@
package kubectl
import (
"bytes"
"errors"
"fmt"
"html/template"
"io/ioutil"
"log"
"os"
"os/exec"
"strings"
"github.com/boson-project/faas"
"github.com/boson-project/faas/k8s"
)
// TODO: Replace this implementation with an implementation which
// directly uses the client, using this as a reference.
const service = `
apiVersion: serving.knative.dev/v1
kind: Service
metadata:
name: {{ .Project }}
namespace: {{ .Namespace }}
labels:
# Will be exposed as this domain as per the knative service domains config.
# Configured in config-domain
faas.domain: {{ .Domain }}
bosonFunction: "True"
annotations:
# Will be exposed as this specific subdomain rather than the autogernerated
# name.namespace.
# Configured in config-network
faas.subdomain: {{ .Subdomain }}
# TODO: test if the following forces the service to be cluster.local:
# serving.knative.dev/visibility=cluster-local
spec:
template:
spec:
containers:
- image: {{ .Image }}
env:
- name: VERBOSE
value: "true"
`
// Deployer implemented using the kubectl binary.
type Deployer struct {
// Verbose logging.
Verbose bool
}
// NewDeployer creates an instance of the kubectl-based deployer.
func NewDeployer() *Deployer {
return &Deployer{}
}
// Deploy the named image.
func (d *Deployer) Deploy(name, image string) (address string, err error) {
// assert kubectl
if _, err = exec.LookPath("kubectl"); err != nil {
err = errors.New("please install 'kubectl'")
return
}
// Parse the service template
t := template.Must(template.New("service").Parse(service))
// Create an autoremoved temp file for the service config.
f, err := ioutil.TempFile("", "faas-service")
if err != nil {
log.Fatal(err)
}
defer os.Remove(f.Name())
// Convert the project name proper (a valid domain) to how it is being
// represented by appsody: as a kubernetes and docker valid name (RFC1035 label)
// for use as the service's deployed name.
project, err := k8s.ToSubdomain(name)
if err != nil {
return
}
nn := strings.Split(name, ".")
if len(nn) < 3 {
err = fmt.Errorf("invalid service name '%v', must be at least three parts.\n", name)
}
subdomain := nn[0]
domain := strings.Join(nn[1:], ".")
// Minimum three parts expected: [service].[domain].[tld].
// Since knative+kube does not support multi-level subdomains, we can simply
// consider the first token to be the subdomain, and in the event of a
// multi-level path, the config-domain map would have to include separate
// entries for, ex x.example.com and y.x.example.com, with only the leading
// node being considered the subdomain for
// Write out the final service yaml
err = t.Execute(f, map[string]string{
"Project": project,
"Namespace": faas.DefaultNamespace,
"Subdomain": subdomain,
"Domain": domain,
"Image": image,
})
cmd := exec.Command("kubectl", "apply", "-f", f.Name())
// If verbose logging is enabled, echo appsody's chatty stdout.
if d.Verbose {
fmt.Println(cmd)
cmd.Stdout = os.Stdout
}
// Capture stderr for echoing on failure.
var stderr bytes.Buffer
cmd.Stderr = &stderr
// Run the command, echoing captured stderr as well ass the cmd internal error.
err = cmd.Run()
if err != nil {
// TODO: sanitize stderr from appsody, or submit a PR to remove duplicates etc.
err = fmt.Errorf("%v. %v", stderr.String(), err.Error())
return
}
// TODO: explicitly pull address from API. The Knative Serving Networking LB.
return "[cluster-address]", nil
}

View File

@ -1,60 +0,0 @@
package kubectl
import (
"bytes"
"errors"
"fmt"
"os"
"os/exec"
"github.com/boson-project/faas"
"github.com/boson-project/faas/k8s"
)
// Remover implemented using the kubectl binary.
type Remover struct {
// Verbose logging.
Verbose bool
}
// NewRemover creates an instance of the kubectl-based deployer.
func NewRemover() *Remover {
return &Remover{}
}
// Remove the named service.
// Name is expected
func (d *Remover) Remove(name string) (err error) {
// assert kubectl
if _, err = exec.LookPath("kubectl"); err != nil {
err = errors.New("please install 'kubectl'")
return
}
// Convert the project name proper (a valid domain) to how it is being
// represented: as a kubernetes and docker valid name (RFC1035 label)
serviceName, err := k8s.ToSubdomain(name)
if err != nil {
return
}
// Command to run
cmd := exec.Command("kubectl", "delete", "kservice", serviceName, "--namespace", faas.DefaultNamespace)
// If verbose logging is enabled, echo appsody's chatty stdout.
if d.Verbose {
fmt.Println(cmd)
cmd.Stdout = os.Stdout
}
// Capture stderr for echoing on failure.
var stderr bytes.Buffer
cmd.Stderr = &stderr
// Run the command, echoing captured stderr as well as the cmd internal error.
err = cmd.Run()
if err != nil {
err = fmt.Errorf("%v. %v", stderr.String(), err.Error())
}
return
}