/
manifest.go
77 lines (64 loc) · 1.88 KB
/
manifest.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
package cmd
import (
"fmt"
"strings"
"github.com/n0madic/app2kube/pkg/app2kube"
"github.com/spf13/cobra"
)
var typeOutput []string
// NewCmdManifest return manifest command
func NewCmdManifest() *cobra.Command {
manifestCmd := &cobra.Command{
Use: "manifest",
Short: "Generate kubernetes manifests for an application",
RunE: manifest,
}
manifestCmd.Flags().StringVarP(&output, "output", "o", "yaml", "Output format")
manifestCmd.Flags().StringArrayVar(&typeOutput, "type", []string{"all"}, "Types of output resources (several can be specified)")
addAppFlags(manifestCmd)
addBlueGreenFlag(manifestCmd)
return manifestCmd
}
func manifest(cmd *cobra.Command, args []string) error {
app, err := initApp()
if err != nil {
return err
}
if app.Namespace == app2kube.NamespaceDefault {
app.Namespace = ""
}
var outputTypes []app2kube.OutputResource
for _, outType := range typeOutput {
switch strings.ToLower(outType) {
case "all":
outputTypes = append(outputTypes, app2kube.OutputAll)
case "configmap":
outputTypes = append(outputTypes, app2kube.OutputConfigMap)
case "cronjob":
outputTypes = append(outputTypes, app2kube.OutputCronJob)
case "deployment":
outputTypes = append(outputTypes, app2kube.OutputDeployment)
case "ingress":
outputTypes = append(outputTypes, app2kube.OutputIngress)
case "pvc":
outputTypes = append(outputTypes, app2kube.OutputPersistentVolumeClaim)
case "secret":
outputTypes = append(outputTypes, app2kube.OutputSecret)
case "service":
outputTypes = append(outputTypes, app2kube.OutputService)
}
}
manifest, err := app.GetManifest(output, outputTypes...)
if err != nil {
return err
}
if app.Namespace != "" && flagIncludeNamespace {
namespace, err := app.GetManifest(output, app2kube.OutputNamespace)
if err != nil {
return err
}
manifest = namespace + manifest
}
fmt.Println(manifest)
return nil
}