Skip to content

Commit

Permalink
Refactor registry addon
Browse files Browse the repository at this point in the history
  • Loading branch information
stevesloka committed Feb 27, 2017
1 parent c3d962b commit 60d9d1e
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 37 deletions.
93 changes: 60 additions & 33 deletions cmd/minikube/cmd/config/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package config

import (
"fmt"
"io/ioutil"
"os"
"strconv"

Expand Down Expand Up @@ -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 {
Expand Down
9 changes: 5 additions & 4 deletions deploy/addons/registry-creds/registry-creds-rc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
secretName: registry-creds-gcr

0 comments on commit 60d9d1e

Please sign in to comment.