forked from kubernetes/minikube
/
configure.go
166 lines (141 loc) · 5.34 KB
/
configure.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
/*
Copyright 2016 The Kubernetes Authors All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package config
import (
"fmt"
"io/ioutil"
"os"
"k8s.io/minikube/pkg/minikube/service"
"github.com/spf13/cobra"
)
var addonsConfigureCmd = &cobra.Command{
Use: "configure ADDON_NAME",
Short: "Configures the addon w/ADDON_NAME within minikube (example: minikube addons configure registry-creds). For a list of available addons use: minikube addons list ",
Long: "Configures the addon w/ADDON_NAME within minikube (example: minikube addons configure registry-creds). For a list of available addons use: minikube addons list ",
Run: func(cmd *cobra.Command, args []string) {
if len(args) != 1 {
fmt.Fprintln(os.Stderr, "usage: minikube addons configure ADDON_NAME")
os.Exit(1)
}
addon := args[0]
// allows for additional prompting of information when enabling addons
switch addon {
case "registry-creds":
posResponses := []string{"yes", "y"}
negResponses := []string{"no", "n"}
// Default values
awsAccessID := "changeme"
awsAccessKey := "changeme"
awsSessionToken := ""
awsRegion := "changeme"
awsAccount := "changeme"
awsRole := "changeme"
gcrApplicationDefaultCredentials := "changeme"
dockerServer := "changeme"
dockerUser := "changeme"
dockerPass := "changeme"
gcrURL := "https://gcr.io"
enableAWSECR := AskForYesNoConfirmation("\nDo you want to enable AWS Elastic Container Registry?", posResponses, negResponses)
if enableAWSECR {
awsAccessID = AskForStaticValue("-- Enter AWS Access Key ID: ")
awsAccessKey = AskForStaticValue("-- Enter AWS Secret Access Key: ")
awsSessionToken = AskForStaticValueOptional("-- (Optional) Enter AWS Session Token: ")
awsRegion = AskForStaticValue("-- Enter AWS Region: ")
awsAccount = AskForStaticValue("-- Enter 12 digit AWS Account ID: ")
awsRole = AskForStaticValueOptional("-- (Optional) Enter ARN of AWS role to assume: ")
}
enableGCR := AskForYesNoConfirmation("\nDo you want to enable Google Container Registry?", posResponses, negResponses)
if enableGCR {
gcrPath := AskForStaticValue("-- Enter path to credentials (e.g. /home/user/.config/gcloud/application_default_credentials.json):")
gcrchangeURL := AskForYesNoConfirmation("-- Do you want to change the GCR URL (Default https://gcr.io)?", posResponses, negResponses)
if gcrchangeURL {
gcrURL = AskForStaticValue("-- Enter GCR URL (e.g. https://asia.gcr.io):")
}
// Read file from disk
dat, err := ioutil.ReadFile(gcrPath)
if err != nil {
fmt.Println("Could not read file for application_default_credentials.json")
} else {
gcrApplicationDefaultCredentials = string(dat)
}
}
enableDR := AskForYesNoConfirmation("\nDo you want to enable Docker Registry?", posResponses, negResponses)
if enableDR {
dockerServer = AskForStaticValue("-- Enter docker registry server url: ")
dockerUser = AskForStaticValue("-- Enter docker registry username: ")
dockerPass = AskForPasswordValue("-- Enter docker registry password: ")
}
// Create ECR Secret
err := service.CreateSecret(
"kube-system",
"registry-creds-ecr",
map[string]string{
"AWS_ACCESS_KEY_ID": awsAccessID,
"AWS_SECRET_ACCESS_KEY": awsAccessKey,
"AWS_SESSION_TOKEN": awsSessionToken,
"aws-account": awsAccount,
"aws-region": awsRegion,
"aws-assume-role": awsRole,
},
map[string]string{
"app": "registry-creds",
"cloud": "ecr",
"kubernetes.io/minikube-addons": "registry-creds",
})
if err != nil {
fmt.Println("ERROR creating `registry-creds-ecr` secret")
}
// Create GCR Secret
err = service.CreateSecret(
"kube-system",
"registry-creds-gcr",
map[string]string{
"application_default_credentials.json": gcrApplicationDefaultCredentials,
"gcrurl": gcrURL,
},
map[string]string{
"app": "registry-creds",
"cloud": "gcr",
"kubernetes.io/minikube-addons": "registry-creds",
})
if err != nil {
fmt.Println("ERROR creating `registry-creds-gcr` secret")
}
// Create Docker Secret
err = service.CreateSecret(
"kube-system",
"registry-creds-dpr",
map[string]string{
"DOCKER_PRIVATE_REGISTRY_SERVER": dockerServer,
"DOCKER_PRIVATE_REGISTRY_USER": dockerUser,
"DOCKER_PRIVATE_REGISTRY_PASSWORD": dockerPass,
},
map[string]string{
"app": "registry-creds",
"cloud": "dpr",
"kubernetes.io/minikube-addons": "registry-creds",
})
if err != nil {
fmt.Println("ERROR creating `registry-creds-dpr` secret")
}
break
default:
fmt.Fprintln(os.Stdout, fmt.Sprintf("%s has no available configuration options", addon))
return
}
fmt.Fprintln(os.Stdout, fmt.Sprintf("%s was successfully configured", addon))
},
}
func init() {
AddonsCmd.AddCommand(addonsConfigureCmd)
}