This repository has been archived by the owner on Jan 5, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
163 lines (156 loc) · 3.99 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
package main
import (
"fmt"
"os"
"os/signal"
"time"
"github.com/saschagrunert/crio-demos/pkg/demo"
"github.com/saschagrunert/crio-demos/pkg/runs"
"github.com/urfave/cli"
)
func main() {
app := cli.NewApp()
app.Name = "crio-demos"
app.Usage = "CRI-O Demonstration Examples"
app.Authors = []cli.Author{
{Name: "Sascha Grunert", Email: "sgrunert@suse.com"},
}
app.HideVersion = true
app.UseShortOptionHandling = true
app.Before = demo.Setup
app.After = demo.Cleanup
app.Flags = []cli.Flag{
cli.BoolFlag{
Name: "1, interaction",
Usage: "this demo shows basic interactions with CRI-O, the kubelet and between both of them",
},
cli.BoolFlag{
Name: "2, logging",
Usage: "this demo shows how to configure CRI-O logging and reload the configuration during runtime",
},
cli.BoolFlag{
Name: "3, lifecycle",
Usage: "this demo shows how CRI-O ensures the containers life-cycle in conjunction with the kubelet",
},
cli.BoolFlag{
Name: "4, port-forward",
Usage: "this demo shows how port forwaring works in CRI-O",
},
cli.BoolFlag{
Name: "5, recovering",
Usage: "this demo shows what happens if a workload unexpectedly stops",
},
cli.BoolFlag{
Name: "6, networking",
Usage: "this demo shows how the basic networking works in CRI-O",
},
cli.BoolFlag{
Name: "7, pull-auth",
Usage: "this demo shows how registry authentication works in CRI-O",
},
cli.BoolFlag{
Name: "8, registries",
Usage: "this demo shows how to configure registries with CRI-O",
},
cli.BoolFlag{
Name: "9, registry-mirrors",
Usage: "this demo shows how to configure registries mirrors in CRI-O",
},
cli.BoolFlag{
Name: "10, storage",
Usage: "this demo shows how container storage can be configured",
},
cli.BoolFlag{
Name: "all, l",
Usage: "run all demos",
},
cli.BoolFlag{
Name: "auto, a",
Usage: "run the demo in automatic mode, " +
"where every step gets executed automatically",
},
cli.DurationFlag{
Name: "auto-timeout, t",
Usage: "the timeout to be waited when `auto` is enabled",
Value: 3 * time.Second,
},
cli.BoolFlag{
Name: "continuously, c",
Usage: "run the demos continuously without any end",
},
cli.BoolFlag{
Name: "immediate, i",
Usage: "immediately output without the typewriter animation",
},
cli.IntFlag{
Name: "skip-steps, s",
Usage: "skip the amount of initial steps within the demo",
},
}
app.Action = func(ctx *cli.Context) error {
demos := []cli.ActionFunc{}
all := ctx.GlobalBool("all")
if all || ctx.GlobalBool("interaction") {
demos = append(demos, runs.Interaction)
}
if all || ctx.GlobalBool("logging") {
demos = append(demos, runs.Logging)
}
if all || ctx.GlobalBool("lifecycle") {
demos = append(demos, runs.LifeCycle)
}
if all || ctx.GlobalBool("port-forward") {
demos = append(demos, runs.PortForward)
}
if all || ctx.GlobalBool("recovering") {
demos = append(demos, runs.Recovering)
}
if all || ctx.GlobalBool("networking") {
demos = append(demos, runs.Networking)
}
if all || ctx.GlobalBool("pull-auth") {
demos = append(demos, runs.PullAuth)
}
if all || ctx.GlobalBool("registries") {
demos = append(demos, runs.Registries)
}
if all || ctx.GlobalBool("registry-mirrors") {
demos = append(demos, runs.RegistryMirrors)
}
if all || ctx.GlobalBool("storage") {
demos = append(demos, runs.Storage)
}
runDemos := func() error {
for _, runDemo := range demos {
if err := runDemo(ctx); err != nil {
return err
}
if err := demo.Setup(ctx); err != nil {
return err
}
}
return nil
}
if ctx.GlobalBool("continuously") {
for {
if err := runDemos(); err != nil {
return err
}
}
}
return runDemos()
}
// Catch interrupts and cleanup
c := make(chan os.Signal, 1)
signal.Notify(c, os.Interrupt)
go func() {
for range c {
_ = demo.Cleanup(nil)
os.Exit(0)
}
}()
if err := app.Run(os.Args); err != nil {
fmt.Printf("run failed: %v", err)
os.Exit(1)
}
}