-
Notifications
You must be signed in to change notification settings - Fork 6
/
main.go
115 lines (95 loc) · 3.42 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
package main
import (
"fmt"
"log"
"github.com/cli-playground/kodo/pkg/kodo/cmd"
"github.com/spf13/cobra"
)
var envVar = new(cmd.EnvironmentVariables) // creating instance of struct EnvironmentVariables from cmd.openshiftclient.go
var deployVar = new(cmd.DeploymentVariables) // creating instance of struct EnvironmentVariables from cmd.deploy.go
var rcommand = &cobra.Command{
Use: "kodo",
}
var versionCommand = &cobra.Command{
Use: "version",
Run: func(cmd *cobra.Command, args []string) {
fmt.Println("Version 2")
},
}
func init() {
rcommand.AddCommand(versionCommand)
rcommand.AddCommand(countCommand)
countCommand.AddCommand(podCommand)
rcommand.AddCommand(deployCommand)
rcommand.PersistentFlags().StringVarP(&envVar.Host, "server", "s", "myurl", "this is the cluster url")
rcommand.PersistentFlags().StringVarP(&envVar.Bearertoken, "token", "t", "usertoken", "this is the user token")
rcommand.PersistentFlags().StringVarP(&envVar.Namespace, "namespace", "n", "", "this is the namespace")
/* Changed default namespace from 'namespace' to "" because
'namespace' causes some internal error and returns 0 pods
even if login credentials correct but namespace not explicitly set
whereas "" works fine */
rcommand.PersistentFlags().StringVarP(&deployVar.Image, "image", "i", "myimage", "this is the tagged image for deployment")
rcommand.PersistentFlags().Int32VarP(&deployVar.Replicas, "replicas", "r", 1, "number of replicas")
rcommand.PersistentFlags().Int32VarP(&deployVar.Port, "port", "p", 8000, "port at which app should run")
rcommand.MarkFlagRequired("server")
rcommand.AddCommand(buildCommand)
rcommand.PersistentFlags().StringVarP(&deployVar.Source, "source", "o", "github.com", "github repo which has docker image")
}
func main() {
rcommand.Execute()
}
var countCommand = &cobra.Command{
Use: "count",
Short: "Command to count <resources>",
}
var podCommand = &cobra.Command{
Use: "pods",
Run: func(cm *cobra.Command, args []string) {
fmt.Println("List All Kubernetes Applications")
fmt.Printf("\nFetching all applications from %s in namespace %s", envVar.Host, envVar.Namespace)
cmd.List(envVar)
},
}
var buildCommand = &cobra.Command{
Use: "build",
Run: func(cm *cobra.Command, args []string) {
fmt.Println("Building image from docker file at source")
err := cmd.BuildDockerFile(envVar, deployVar)
if err == nil {
fmt.Println("BuildConfig and ImageStream Created Successfully, Build can now be Started")
} else {
log.Fatal(err)
}
},
}
var deployCommand = &cobra.Command{
Use: "deploy",
Run: func(cm *cobra.Command, args []string) {
fmt.Println("Creating image deployment")
deploymentID := cmd.GenerateUniqueIdentifiers()
client, clientError := cmd.NewOpenShiftClient(envVar)
if clientError != nil {
log.Fatal(clientError)
} else {
_, deployError := cmd.Deploy(client.AppsV1(), deployVar, envVar, deploymentID)
if deployError != nil {
log.Fatal(deployError)
} else {
serviceObj, serviceObjError := cmd.Service(client.CoreV1(), deployVar, envVar, deploymentID)
if serviceObjError != nil {
log.Fatal(serviceObjError)
} else {
routeClient, routev1ClientError := cmd.NewRouteClient(envVar)
if routev1ClientError != nil {
log.Fatal(routev1ClientError)
} else {
_, routeError := cmd.Route(routeClient, deployVar, envVar, serviceObj, deploymentID)
if routeError != nil {
log.Fatal(routeError)
}
}
}
}
}
},
}