-
Notifications
You must be signed in to change notification settings - Fork 1
/
create_cluster.go
171 lines (139 loc) · 5.32 KB
/
create_cluster.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
164
165
166
167
168
169
170
171
package cmd
import (
"fmt"
"io"
"sort"
"strings"
"github.com/jenkins-x/jx/pkg/jx/cmd/templates"
"github.com/spf13/cobra"
)
type KubernetesProvider string
// CreateClusterOptions the flags for running create cluster
type CreateClusterOptions struct {
CreateOptions
InstallOptions InstallOptions
Flags InitFlags
Provider string
}
const (
GKE = "gke"
OKE = "oke"
EKS = "eks"
AKS = "aks"
AWS = "aws"
PKS = "pks"
MINIKUBE = "minikube"
MINISHIFT = "minishift"
KUBERNETES = "kubernetes"
OPENSHIFT = "openshift"
ORACLE = "oracle"
IBM = "ibm"
JX_INFRA = "jx-infra"
optionKubernetesVersion = "kubernetes-version"
optionNodes = "nodes"
optionClusterName = "cluster-name"
)
var KUBERNETES_PROVIDERS = []string{MINIKUBE, GKE, OKE, AKS, AWS, EKS, KUBERNETES, IBM, OPENSHIFT, MINISHIFT, JX_INFRA, PKS}
const (
stableKubeCtlVersionURL = "https://storage.googleapis.com/kubernetes-release/release/stable.txt"
valid_providers = `Valid kubernetes providers include:
* aks (Azure Container Service - https://docs.microsoft.com/en-us/azure/aks)
* aws (Amazon Web Services via kops - https://github.com/aws-samples/aws-workshop-for-kubernetes/blob/master/readme.adoc)
* eks (Amazon Web Services Elastic Container Service for Kubernetes - https://docs.aws.amazon.com/eks/latest/userguide/getting-started.html)
* gke (Google Container Engine - https://cloud.google.com/kubernetes-engine)
* oke (Oracle Cloud Infrastructure Container Engine for Kubernetes - https://docs.cloud.oracle.com/iaas/Content/ContEng/Concepts/contengoverview.htm)
* kubernetes for custom installations of Kubernetes
* minikube (single-node Kubernetes cluster inside a VM on your laptop)
* minishift (single-node OpenShift cluster inside a VM on your laptop)
* openshift for installing on 3.9.x or later clusters of OpenShift
* coming soon:
eks (Amazon Elastic Container Service - https://aws.amazon.com/eks) `
)
type CreateClusterFlags struct {
}
var (
createClusterLong = templates.LongDesc(`
This command creates a new kubernetes cluster, installing required local dependencies and provisions the Jenkins X platform
You can see a demo of this command here: [https://jenkins-x.io/demos/create_cluster/](https://jenkins-x.io/demos/create_cluster/)
%s
Depending on which cloud provider your cluster is created on possible dependencies that will be installed are:
- kubectl (CLI to interact with kubernetes clusters)
- helm (package manager for kubernetes)
- draft (CLI that makes it easy to build applications that run on kubernetes)
- minikube (single-node Kubernetes cluster inside a VM on your laptop )
- minishift (single-node OpenShift cluster inside a VM on your laptop)
- virtualisation drivers (to run minikube in a VM)
- gcloud (Google Cloud CLI)
- oci (Oracle Cloud Infrastructure CLI)
- az (Azure CLI)
For more documentation see: [https://jenkins-x.io/getting-started/create-cluster/](https://jenkins-x.io/getting-started/create-cluster/)
`)
createClusterExample = templates.Examples(`
jx create cluster minikube
`)
)
// KubernetesProviderOptions returns all the kubernetes providers as a string
func KubernetesProviderOptions() string {
values := []string{}
values = append(values, KUBERNETES_PROVIDERS...)
sort.Strings(values)
return strings.Join(values, ", ")
}
// 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 NewCmdCreateCluster(f Factory, out io.Writer, errOut io.Writer) *cobra.Command {
options := createCreateClusterOptions(f, out, errOut, "")
cmd := &cobra.Command{
Use: "cluster [kubernetes provider]",
Short: "Create a new kubernetes cluster",
Long: fmt.Sprintf(createClusterLong, valid_providers),
Example: createClusterExample,
Run: func(cmd2 *cobra.Command, args []string) {
options.Cmd = cmd2
options.Args = args
err := options.Run()
CheckErr(err)
},
}
cmd.AddCommand(NewCmdCreateClusterAKS(f, out, errOut))
cmd.AddCommand(NewCmdCreateClusterAWS(f, out, errOut))
cmd.AddCommand(NewCmdCreateClusterEKS(f, out, errOut))
cmd.AddCommand(NewCmdCreateClusterGKE(f, out, errOut))
cmd.AddCommand(NewCmdCreateClusterMinikube(f, out, errOut))
cmd.AddCommand(NewCmdCreateClusterMinishift(f, out, errOut))
cmd.AddCommand(NewCmdCreateClusterOKE(f, out, errOut))
return cmd
}
func createCreateClusterOptions(f Factory, out io.Writer, errOut io.Writer, cloudProvider string) CreateClusterOptions {
commonOptions := CommonOptions{
Factory: f,
Out: out,
Err: errOut,
}
options := CreateClusterOptions{
CreateOptions: CreateOptions{
CommonOptions: commonOptions,
},
Provider: cloudProvider,
InstallOptions: createInstallOptions(f, out, errOut),
}
return options
}
func (o *CreateClusterOptions) initAndInstall(provider string) error {
// call jx init
o.InstallOptions.BatchMode = o.BatchMode
o.InstallOptions.Flags.Provider = provider
// call jx install
installOpts := &o.InstallOptions
err := installOpts.Run()
if err != nil {
return err
}
return nil
}
func (o *CreateClusterOptions) Run() error {
return o.Cmd.Help()
}
func (o *CreateClusterOptions) addCreateClusterFlags(cmd *cobra.Command) {
o.InstallOptions.addInstallFlags(cmd, true)
}