diff --git a/cmd/minikube/cmd/config/util.go b/cmd/minikube/cmd/config/util.go index ef601e1b5cb3..4badbc78069f 100644 --- a/cmd/minikube/cmd/config/util.go +++ b/cmd/minikube/cmd/config/util.go @@ -18,6 +18,7 @@ package config import ( "fmt" + "io/ioutil" "os" "strconv" @@ -101,46 +102,72 @@ func EnableOrDisableAddon(name string, val string) error { posResponses := []string{"yes", "y"} negResponses := []string{"no", "n"} + // Default values + awsAccessID := "changeme" + awsAccessKey := "changeme" + awsRegion := "changeme" + awsAccount := "changeme" + gcrApplicationDefaultCredentials := "changeme" + 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: ") - awsRegion := AskForStaticValue("-- Enter AWS Region: ") - awsAccount := AskForStaticValue("-- Enter 12 digit AWS Account ID: ") - - cluster.CreateSecret( - "kube-system", - "registry-creds-ecr", - map[string]string{ - "AWS_ACCESS_KEY_ID": awsAccessID, - "AWS_SECRET_ACCESS_KEY": awsAccessKey, - "aws-account": awsAccount, - "awsregion": awsRegion, - }, - map[string]string{ - "app": "registry-creds", - "cloud": "ecr", - "kubernetes.io/minikube-addons": "registry-creds", - }) + awsAccessID = AskForStaticValue("-- Enter AWS Access Key ID: ") + awsAccessKey = AskForStaticValue("-- Enter AWS Secret Access Key: ") + awsRegion = AskForStaticValue("-- Enter AWS Region: ") + awsAccount = AskForStaticValue("-- Enter 12 digit AWS Account ID: ") } enableGCR := AskForYesNoConfirmation("\nDo you want to enable Google Container Registry?", posResponses, negResponses) if enableGCR { - fmt.Println("-- Enter applicatoin_default_credentials.json as base64 by running following command:") - gcrApplicationDefaultCredentials := AskForStaticValue(" base64 -w 0 $HOME/.config/gcloud/application_default_credentials.json: ") - - cluster.CreateSecret( - "kube-system", - "registry-creds-gcr", - map[string]string{ - "application_default_credentials.json": gcrApplicationDefaultCredentials, - }, - map[string]string{ - "app": "registry-creds", - "cloud": "gcr", - "kubernetes.io/minikube-addons": "registry-creds", - }) + gcrPath := AskForStaticValue("-- Enter path to credentials (e.g. /home/user/.config/gcloud/application_default_credentials.json):") + + // 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) + } + } + + // Create ECR Secret + err = cluster.CreateSecret( + "kube-system", + "registry-creds-ecr", + map[string]string{ + "AWS_ACCESS_KEY_ID": awsAccessID, + "AWS_SECRET_ACCESS_KEY": awsAccessKey, + "aws-account": awsAccount, + "aws-region": awsRegion, + }, + 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 = cluster.CreateSecret( + "kube-system", + "registry-creds-gcr", + map[string]string{ + "application_default_credentials.json": gcrApplicationDefaultCredentials, + }, + 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") } + break } } else { diff --git a/deploy/addons/registry-creds/registry-creds-rc.yaml b/deploy/addons/registry-creds/registry-creds-rc.yaml index 9be5790e56aa..f0b643e95244 100644 --- a/deploy/addons/registry-creds/registry-creds-rc.yaml +++ b/deploy/addons/registry-creds/registry-creds-rc.yaml @@ -5,16 +5,20 @@ metadata: namespace: kube-system labels: version: v1.6 + kubernetes.io/cluster-service: "true" + kubernetes.io/minikube-addons: registry-creds spec: replicas: 1 selector: name: registry-creds version: v1.6 + kubernetes.io/cluster-service: "true" template: metadata: labels: name: registry-creds version: v1.6 + kubernetes.io/cluster-service: "true" spec: containers: - image: upmcenterprises/registry-creds:1.6 @@ -48,7 +52,4 @@ spec: volumes: - name: gcr-creds secret: - secretName: registry-creds-gcr - items: - - key: application_default_credentials.json - path: application_default_credentials.json \ No newline at end of file + secretName: registry-creds-gcr \ No newline at end of file