@@ -18,6 +18,7 @@ package config
18
18
19
19
import (
20
20
"fmt"
21
+ "io/ioutil"
21
22
"os"
22
23
"strconv"
23
24
@@ -101,46 +102,72 @@ func EnableOrDisableAddon(name string, val string) error {
101
102
posResponses := []string {"yes" , "y" }
102
103
negResponses := []string {"no" , "n" }
103
104
105
+ // Default values
106
+ awsAccessID := "changeme"
107
+ awsAccessKey := "changeme"
108
+ awsRegion := "changeme"
109
+ awsAccount := "changeme"
110
+ gcrApplicationDefaultCredentials := "changeme"
111
+
104
112
enableAWSECR := AskForYesNoConfirmation ("\n Do you want to enable AWS Elastic Container Registry?" , posResponses , negResponses )
105
113
if enableAWSECR {
106
- awsAccessID := AskForStaticValue ("-- Enter AWS Access Key ID: " )
107
- awsAccessKey := AskForStaticValue ("-- Enter AWS Secret Access Key: " )
108
- awsRegion := AskForStaticValue ("-- Enter AWS Region: " )
109
- awsAccount := AskForStaticValue ("-- Enter 12 digit AWS Account ID: " )
110
-
111
- cluster .CreateSecret (
112
- "kube-system" ,
113
- "registry-creds-ecr" ,
114
- map [string ]string {
115
- "AWS_ACCESS_KEY_ID" : awsAccessID ,
116
- "AWS_SECRET_ACCESS_KEY" : awsAccessKey ,
117
- "aws-account" : awsAccount ,
118
- "awsregion" : awsRegion ,
119
- },
120
- map [string ]string {
121
- "app" : "registry-creds" ,
122
- "cloud" : "ecr" ,
123
- "kubernetes.io/minikube-addons" : "registry-creds" ,
124
- })
114
+ awsAccessID = AskForStaticValue ("-- Enter AWS Access Key ID: " )
115
+ awsAccessKey = AskForStaticValue ("-- Enter AWS Secret Access Key: " )
116
+ awsRegion = AskForStaticValue ("-- Enter AWS Region: " )
117
+ awsAccount = AskForStaticValue ("-- Enter 12 digit AWS Account ID: " )
125
118
}
126
119
127
120
enableGCR := AskForYesNoConfirmation ("\n Do you want to enable Google Container Registry?" , posResponses , negResponses )
128
121
if enableGCR {
129
- fmt .Println ("-- Enter applicatoin_default_credentials.json as base64 by running following command:" )
130
- gcrApplicationDefaultCredentials := AskForStaticValue (" base64 -w 0 $HOME/.config/gcloud/application_default_credentials.json: " )
131
-
132
- cluster .CreateSecret (
133
- "kube-system" ,
134
- "registry-creds-gcr" ,
135
- map [string ]string {
136
- "application_default_credentials.json" : gcrApplicationDefaultCredentials ,
137
- },
138
- map [string ]string {
139
- "app" : "registry-creds" ,
140
- "cloud" : "gcr" ,
141
- "kubernetes.io/minikube-addons" : "registry-creds" ,
142
- })
122
+ gcrPath := AskForStaticValue ("-- Enter path to credentials (e.g. /home/user/.config/gcloud/application_default_credentials.json):" )
123
+
124
+ // Read file from disk
125
+ dat , err := ioutil .ReadFile (gcrPath )
126
+
127
+ if err != nil {
128
+ fmt .Println ("Could not read file for application_default_credentials.json" )
129
+ } else {
130
+ gcrApplicationDefaultCredentials = string (dat )
131
+ }
132
+ }
133
+
134
+ // Create ECR Secret
135
+ err = cluster .CreateSecret (
136
+ "kube-system" ,
137
+ "registry-creds-ecr" ,
138
+ map [string ]string {
139
+ "AWS_ACCESS_KEY_ID" : awsAccessID ,
140
+ "AWS_SECRET_ACCESS_KEY" : awsAccessKey ,
141
+ "aws-account" : awsAccount ,
142
+ "aws-region" : awsRegion ,
143
+ },
144
+ map [string ]string {
145
+ "app" : "registry-creds" ,
146
+ "cloud" : "ecr" ,
147
+ "kubernetes.io/minikube-addons" : "registry-creds" ,
148
+ })
149
+
150
+ if err != nil {
151
+ fmt .Println ("ERROR creating `registry-creds-ecr` secret" )
152
+ }
153
+
154
+ // Create GCR Secret
155
+ err = cluster .CreateSecret (
156
+ "kube-system" ,
157
+ "registry-creds-gcr" ,
158
+ map [string ]string {
159
+ "application_default_credentials.json" : gcrApplicationDefaultCredentials ,
160
+ },
161
+ map [string ]string {
162
+ "app" : "registry-creds" ,
163
+ "cloud" : "gcr" ,
164
+ "kubernetes.io/minikube-addons" : "registry-creds" ,
165
+ })
166
+
167
+ if err != nil {
168
+ fmt .Println ("ERROR creating `registry-creds-gcr` secret" )
143
169
}
170
+
144
171
break
145
172
}
146
173
} else {
0 commit comments