-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
67 lines (53 loc) · 1.92 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package main
import (
"fmt"
"os"
"flag"
"github.com/jwendell/fnkube/pkg/fnkube"
)
func main() {
namespace := flag.String("namespace", "", "Which namespace we should use. If not provided, a new one will be created. Be aware that in most kubernetes/openshift instances the creation of namespaces is restricted to cluster administrators.")
image := flag.String("image", "", "Docker image to run on the kubernetes instance")
timeout := flag.Int("timeout", 120, "Timeout (in seconds) to wait for the job to complete (0 to wait indefinitely)")
cleanup := flag.Bool("cleanup", true, "Delete all created artifacts (including the namespace, if we created it) after finishing the job")
insecure := flag.Bool("insecure", false, "Allow insecure TLS communication to kubernetes API server")
flag.Usage = func() {
fmt.Fprintf(os.Stderr, `Runs a docker image in a kubernetes cluster and prints its output
Usage: fnkube [OPTIONS] -image <IMAGE> -- COMMANDS
Examples:
# Runs the perl image and prints π with 100 places
fnkube -image perl -- perl "-Mbignum=bpi" -wle "print bpi(100)"
# Same as above, but specifies a namespace and do not delete stuff (useful for debugging)
fnkube -namespace myproject -cleanup=false -image perl -- perl "-Mbignum=bpi" -wle "print bpi(100)"
Options:
`)
flag.PrintDefaults()
}
flag.Parse()
if len(*image) == 0 {
fmt.Fprintf(os.Stderr, "Missing image. Specify one with -image\n\n")
flag.Usage()
os.Exit(1)
}
command := flag.Args()
if len(command) == 0 {
fmt.Fprintf(os.Stderr, "Missing the command to run\n\n")
flag.Usage()
os.Exit(1)
}
options := &fnkube.Options{
Namespace: *namespace,
Image: *image,
Command: command,
Timeout: *timeout,
Cleanup: *cleanup,
Auth: fnkube.AuthInfo{Insecure: *insecure},
}
stdout, stderr, err := fnkube.Run(options)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
fmt.Fprint(os.Stdout, stdout)
fmt.Fprint(os.Stderr, stderr)
}