Skip to content

Commit 9e1aece

Browse files
committed
feat(deisctl): kubectl for install and uninstall
1 parent 93de7d7 commit 9e1aece

4 files changed

Lines changed: 269 additions & 35 deletions

File tree

trireme/k8s/decode.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package k8s
2+
3+
import (
4+
//"k8s.io/kubernetes/pkg/api/latest"
5+
//"k8s.io/kubernetes/pkg/runtime"
6+
)
7+
8+
/*
9+
func DecodeFile(path string, o runtime.Object) error {
10+
data, err := ioutil.ReadFile(path)
11+
if err != nil {
12+
return err
13+
}
14+
15+
if err := latest.Codec.DecodeInto(data, o); err != nil {
16+
return err
17+
}
18+
}
19+
*/

trireme/k8s/kubectl.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package k8s
2+
3+
import (
4+
"fmt"
5+
"os/exec"
6+
)
7+
8+
// The plan is to eventually call all of these commands directly from the
9+
// k8s API. For the sake of expedience, this is a convenience wrapper until
10+
// we get there.
11+
12+
// KubectlCreate calls 'kubectl create'.
13+
func KubectlCreate(file string) error {
14+
out, err := exec.Command("kubectl", "create", "-f", file).CombinedOutput()
15+
if err != nil {
16+
fmt.Printf("%s\n", out)
17+
return err
18+
}
19+
fmt.Printf("Scheduled %s", out)
20+
return nil
21+
}
22+
23+
func KubectlDelete(filename string) error {
24+
out, err := exec.Command("kubectl", "delete", "-f", filename).CombinedOutput()
25+
if err != nil {
26+
fmt.Printf("%s\n", out)
27+
return err
28+
}
29+
fmt.Printf("Deleting %s", out)
30+
return nil
31+
}

trireme/main.go

Lines changed: 103 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -11,46 +11,52 @@ import (
1111
)
1212

1313
// Components, in the order in which they must be started.
14+
//
15+
// This list describes all of the components that the CLI has the ability to
16+
// manage. When things are installed, namespaces, services, volumes and secrets
17+
// are installed first, then pods and rcs are installed.
1418
var components = []*platform.Component{
1519
{
1620
Name: "builder",
1721
Description: "the builder",
18-
RCs: []string{"deis-builder.json"},
19-
Services: []string{"deis-builder-service.json"},
22+
Namespaces: []string{"namespaces/deis-namespace.json"},
23+
RCs: []string{"rcs/deis-builder.json"},
24+
Services: []string{"services/deis-builder-service.json"},
2025
},
2126
{
2227
Name: "controller",
2328
Description: "the controller",
24-
RCs: []string{"deis-controller.json"},
25-
Services: []string{"deis-controller-service.json"},
29+
RCs: []string{"rcs/deis-controller.json"},
30+
Services: []string{"services/deis-controller-service.json"},
2631
},
2732
{
2833
Name: "database",
2934
Description: "the database",
30-
RCs: []string{"deis-database.json"},
31-
Services: []string{"deis-database-service.json"},
35+
RCs: []string{"rcs/deis-database.json"},
36+
Services: []string{"services/deis-database-service.json"},
3237
},
3338
{
3439
Name: "registry",
3540
Description: "the registry",
36-
RCs: []string{"deis-registry.json"},
37-
Services: []string{"deis-registry-service.json"},
41+
RCs: []string{"rcs/deis-registry.json"},
42+
Services: []string{"services/deis-registry-service.json"},
3843
},
3944
{
4045
Name: "router",
4146
Description: "the router mesh",
42-
RCs: []string{"router.json"},
43-
Services: []string{"router-service.json"},
47+
RCs: []string{"rcs/deis-router.json"},
48+
//Services: []string{"services/deis-router-service.json"},
4449
},
4550
{
4651
Name: "store",
4752
Description: "the persistent storage cluster",
48-
RCs: []string{"deis-store-gtw.json", "deis-store-mds.json", "deis-store-mon.json", "deis-store-osd.json"},
49-
Services: []string{"deis-store-gtw-service.json"},
53+
RCs: []string{"rcs/deis-store-gtw.json", "rcs/deis-store-mds.json", "rcs/deis-store-mon.json", "rcs/deis-store-osd.json"},
54+
Services: []string{"services/deis-store-gtw-service.json"},
5055
Optional: true,
5156
},
5257
}
5358

59+
// config is where configuration data is stored.
5460
var config storage.Storer
5561

5662
func main() {
@@ -68,21 +74,35 @@ func main() {
6874
app := cli.NewApp()
6975
app.Name = "trireme"
7076
app.Usage = "A control tool for Deis"
77+
app.Flags = []cli.Flag{
78+
// This is currently not used.
79+
cli.StringFlag{
80+
Name: "tunnel, t",
81+
Value: "127.0.0.1",
82+
EnvVar: "DEISCTL_TUNNEL",
83+
Usage: "The IP address or hostname of the tunnel.",
84+
},
85+
}
7186
app.Commands = commands()
7287
app.Run(os.Args)
7388
}
7489

7590
func commands() []cli.Command {
7691
return []cli.Command{
92+
{
93+
Name: "config",
94+
Usage: "Get and set configuration values",
95+
Subcommands: configCommands(),
96+
},
7797
{
7898
Name: "install",
7999
Usage: "Install platform components",
80100
Subcommands: installCommands(),
81101
},
82102
{
83-
Name: "config",
84-
Usage: "Get and set configuration values",
85-
Subcommands: configCommands(),
103+
Name: "uninstall",
104+
Usage: "Uninstall platform components",
105+
Subcommands: uninstallCommands(),
86106
},
87107
}
88108
}
@@ -200,7 +220,6 @@ func configCommands() []cli.Command {
200220
}
201221

202222
func installCommands() []cli.Command {
203-
204223
// This basically ensures that append() will not have to reallocate.
205224
cmds := make([]cli.Command, 0, len(components)+1)
206225

@@ -219,10 +238,10 @@ func installCommands() []cli.Command {
219238
Action: installPlatform,
220239
Flags: []cli.Flag{
221240
cli.StringFlag{
222-
Name: "units, u",
223-
Value: "units/",
241+
Name: "unit-files, u",
242+
Value: "./units/",
224243
Usage: "The path to the Deis Kubernetes JSON unit files.",
225-
EnvVar: "DEIS_K8S_UNITS",
244+
EnvVar: "DEISCTL_UNITS",
226245
},
227246
cli.StringFlag{
228247
Name: "registry, r",
@@ -231,29 +250,89 @@ func installCommands() []cli.Command {
231250
},
232251
},
233252
})
253+
return cmds
254+
}
255+
func uninstallCommands() []cli.Command {
256+
// This basically ensures that append() will not have to reallocate.
257+
cmds := make([]cli.Command, 0, len(components)+1)
234258

259+
for _, c := range components {
260+
n := c.Name
261+
v := c.Description
262+
cmds = append(cmds, cli.Command{
263+
Name: n,
264+
Usage: fmt.Sprintf("Uninstall %s.", v),
265+
Action: func(c *cli.Context) { uninstallComponent(c, n) },
266+
})
267+
}
268+
cmds = append(cmds, cli.Command{
269+
Name: "platform",
270+
Usage: "Uninstall the entire platform",
271+
Action: uninstallPlatform,
272+
Flags: []cli.Flag{
273+
cli.StringFlag{
274+
Name: "unit-files, u",
275+
Value: "./units/",
276+
Usage: "The path to the Deis Kubernetes JSON unit files.",
277+
EnvVar: "DEISCTL_UNITS",
278+
},
279+
cli.StringFlag{
280+
Name: "registry, r",
281+
Usage: "The URL to a Docker registry that holds Deis images images.",
282+
EnvVar: "DEV_REGISTRY",
283+
},
284+
},
285+
})
235286
return cmds
236287
}
237288

238289
func installPlatform(c *cli.Context) {
239290
fmt.Println("Installing platform")
240-
if err := platform.InstallAll(components, false); err != nil {
291+
292+
dir := c.String("unit-files")
293+
if err := platform.InstallAll(components, dir, false); err != nil {
241294
fmt.Printf("Failed to install platform: %s\n", err)
242295
os.Exit(500)
243296
}
244297
}
298+
299+
func uninstallPlatform(c *cli.Context) {
300+
dir := c.String("unit-files")
301+
if err := platform.DeleteAll(components, dir); err != nil {
302+
fmt.Printf("Failed to uninstall platform: %s\n", err)
303+
os.Exit(500)
304+
}
305+
}
245306
func installComponent(c *cli.Context, name string) {
246307
comp, err := findComponent(name)
247308
if err != nil {
248309
fmt.Printf("Failed to install %s: %s\n", name, err)
249310
os.Exit(404)
250311
}
251-
if err := comp.InstallPrereqs(); err != nil {
252-
fmt.Printf("Failed to install prereqs of %s: %s\n", name, err)
312+
dir := c.String("unit-files")
313+
if err := comp.Install(dir); err != nil {
314+
fmt.Printf("Failed to install %s: %s\n", name, err)
253315
os.Exit(500)
254316
}
255-
if err := comp.Install(); err != nil {
256-
fmt.Printf("Failed to install %s: %s\n", name, err)
317+
if err := comp.InstallPrereqs(dir); err != nil {
318+
fmt.Printf("Failed to install dependencies of %s: %s\n", name, err)
319+
os.Exit(500)
320+
}
321+
}
322+
323+
func uninstallComponent(c *cli.Context, name string) {
324+
comp, err := findComponent(name)
325+
if err != nil {
326+
fmt.Printf("Failed to uninstall %s: %s\n", name, err)
327+
os.Exit(404)
328+
}
329+
dir := c.String("unit-files")
330+
if err := comp.Delete(dir); err != nil {
331+
fmt.Printf("Failed to uninstall %s: %s\n", name, err)
332+
os.Exit(500)
333+
}
334+
if err := comp.DeletePrereqs(dir); err != nil {
335+
fmt.Printf("Failed to uninstall dependencies of %s: %s\n", name, err)
257336
os.Exit(500)
258337
}
259338
}

0 commit comments

Comments
 (0)