e2e.go / kops: Add ssh-key option to override ssh key

By default, Jenkins stuffs the ssh key in
/workspace/.aws/kube_aws_rsa. Allow this to be overridden easily on
the command line.
This commit is contained in:
Zach Loafman 2016-10-03 17:18:29 -07:00
parent dab787d80d
commit eb44add29c
2 changed files with 19 additions and 1 deletions

View File

@ -25,6 +25,7 @@ import (
"log"
"os"
"os/exec"
"os/user"
"path/filepath"
"strconv"
"strings"
@ -54,6 +55,7 @@ var (
kopsPath = flag.String("kops", "", "(kops only) Path to the kops binary. Must be set for kops.")
kopsCluster = flag.String("kops-cluster", "", "(kops only) Cluster name. Must be set for kops.")
kopsState = flag.String("kops-state", os.Getenv("KOPS_STATE_STORE"), "(kops only) s3:// path to kops state store. Must be set. (This flag defaults to $KOPS_STATE_STORE, and overrides it if set.)")
kopsSSHKey = flag.String("kops-ssh-key", os.Getenv("AWS_SSH_KEY"), "(kops only) Path to ssh key-pair for each node. (Defaults to $AWS_SSH_KEY or '~/.ssh/kube_aws_rsa'.)")
kopsZones = flag.String("kops-zones", "us-west-2a", "(kops AWS only) AWS zones for kops deployment, comma delimited.")
kopsNodes = flag.Int("kops-nodes", 2, "(kops only) Number of nodes to create.")
@ -391,6 +393,7 @@ func (b bash) Down() error {
type kops struct {
path string
sshKey string
zones []string
nodes int
cluster string
@ -407,6 +410,14 @@ func NewKops() (*kops, error) {
if *kopsState == "" {
return nil, fmt.Errorf("--kops-state must be set to a valid S3 path for kops deployment.")
}
sshKey := *kopsSSHKey
if sshKey == "" {
usr, err := user.Current()
if err != nil {
return nil, err
}
sshKey = filepath.Join(usr.HomeDir, ".ssh/kube_aws_rsa")
}
if err := os.Setenv("KOPS_STATE_STORE", *kopsState); err != nil {
return nil, err
}
@ -432,13 +443,18 @@ func NewKops() (*kops, error) {
if err := os.Setenv("KUBERNETES_CONFORMANCE_PROVIDER", "aws"); err != nil {
return nil, err
}
// ZONE is required by the AWS e2e tests
// AWS_SSH_KEY is required by the AWS e2e tests.
if err := os.Setenv("AWS_SSH_KEY", sshKey); err != nil {
return nil, err
}
// ZONE is required by the AWS e2e tests.
zones := strings.Split(*kopsZones, ",")
if err := os.Setenv("ZONE", zones[0]); err != nil {
return nil, err
}
return &kops{
path: *kopsPath,
sshKey: sshKey + ".pub", // kops only needs the public key, e2es need the private key.
zones: zones,
nodes: *kopsNodes,
cluster: *kopsCluster,
@ -450,6 +466,7 @@ func (k kops) Up() error {
if err := finishRunning("kops config", exec.Command(
k.path, "create", "cluster",
"--name", k.cluster,
"--ssh-public-key", k.sshKey,
"--node-count", strconv.Itoa(k.nodes),
"--zones", strings.Join(k.zones, ","))); err != nil {
return fmt.Errorf("kops configuration failed: %v", err)

View File

@ -276,6 +276,7 @@ keep-gogoproto
km-path
kops-cluster
kops-nodes
kops-ssh-key
kops-state
kops-zones
kube-api-burst