forked from jenkins-x/jx
-
Notifications
You must be signed in to change notification settings - Fork 0
/
create_cluster_gke.go
108 lines (85 loc) · 2.84 KB
/
create_cluster_gke.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
package cmd
import (
"io"
"os"
"fmt"
"github.com/jenkins-x/jx/pkg/jx/cmd/log"
"github.com/jenkins-x/jx/pkg/jx/cmd/templates"
cmdutil "github.com/jenkins-x/jx/pkg/jx/cmd/util"
"github.com/spf13/cobra"
)
// CreateClusterOptions the flags for running crest cluster
type CreateClusterGKEOptions struct {
CreateClusterOptions
Flags CreateClusterGKEFlags
}
type CreateClusterGKEFlags struct {
}
var (
createClusterGKELong = templates.LongDesc(`
This command creates a new kubernetes cluster on GKE, installing required local dependencies and provisions the
Jenkins X platform
Google Kubernetes Engine is a managed environment for deploying containerized applications. It brings our latest
innovations in developer productivity, resource efficiency, automated operations, and open source flexibility to
accelerate your time to market.
Google has been running production workloads in containers for over 15 years, and we build the best of what we
learn into Kubernetes, the industry-leading open source container orchestrator which powers Kubernetes Engine.
`)
createClusterGKEExample = templates.Examples(`
jx create cluster gke
`)
)
// NewCmdGet creates a command object for the generic "init" action, which
// installs the dependencies required to run the jenkins-x platform on a kubernetes cluster.
func NewCmdCreateClusterGKE(f cmdutil.Factory, out io.Writer, errOut io.Writer) *cobra.Command {
options := CreateClusterGKEOptions{
CreateClusterOptions: CreateClusterOptions{
CreateOptions: CreateOptions{
CommonOptions: CommonOptions{
Factory: f,
Out: out,
Err: errOut,
},
},
Provider: GKE,
},
}
cmd := &cobra.Command{
Use: "gke",
Short: "Create a new kubernetes cluster on GKE: Runs on Google Cloud",
Long: createClusterGKELong,
Example: createClusterGKEExample,
Run: func(cmd *cobra.Command, args []string) {
options.Cmd = cmd
options.Args = args
err := options.Run()
cmdutil.CheckErr(err)
},
}
options.addCreateClusterFlags(cmd)
//cmd.Flags().StringVarP(&options.Flags.Memory, "memory", "m", "4096", "Amount of RAM allocated to the minikube VM in MB")
//cmd.Flags().StringVarP(&options.Flags.CPU, "cpu", "c", "3", "Number of CPUs allocated to the minikube VM")
return cmd
}
func (o *CreateClusterGKEOptions) Run() error {
var deps []string
d := binaryShouldBeInstalled("gcloud")
if d != "" {
deps = append(deps, d)
}
err := o.installMissingDependencies(deps)
if err != nil {
log.Errorf("error installing missing dependencies %v, please fix or install manually then try again", err)
os.Exit(-1)
}
err = o.createClusterGKE()
if err != nil {
log.Errorf("error creating cluster %v", err)
os.Exit(-1)
}
return nil
}
func (o *CreateClusterGKEOptions) createClusterGKE() error {
// TODO
return fmt.Errorf("Create %s cluster not yet implemented", o.Provider)
}