mirror of
				https://github.com/optim-enterprises-bv/kubernetes.git
				synced 2025-11-03 19:58:17 +00:00 
			
		
		
		
	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:
		
							
								
								
									
										19
									
								
								hack/e2e.go
									
									
									
									
									
								
							
							
						
						
									
										19
									
								
								hack/e2e.go
									
									
									
									
									
								
							@@ -25,6 +25,7 @@ import (
 | 
				
			|||||||
	"log"
 | 
						"log"
 | 
				
			||||||
	"os"
 | 
						"os"
 | 
				
			||||||
	"os/exec"
 | 
						"os/exec"
 | 
				
			||||||
 | 
						"os/user"
 | 
				
			||||||
	"path/filepath"
 | 
						"path/filepath"
 | 
				
			||||||
	"strconv"
 | 
						"strconv"
 | 
				
			||||||
	"strings"
 | 
						"strings"
 | 
				
			||||||
@@ -54,6 +55,7 @@ var (
 | 
				
			|||||||
	kopsPath    = flag.String("kops", "", "(kops only) Path to the kops binary. Must be set for kops.")
 | 
						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.")
 | 
						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.)")
 | 
						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.")
 | 
						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.")
 | 
						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 {
 | 
					type kops struct {
 | 
				
			||||||
	path    string
 | 
						path    string
 | 
				
			||||||
 | 
						sshKey  string
 | 
				
			||||||
	zones   []string
 | 
						zones   []string
 | 
				
			||||||
	nodes   int
 | 
						nodes   int
 | 
				
			||||||
	cluster string
 | 
						cluster string
 | 
				
			||||||
@@ -407,6 +410,14 @@ func NewKops() (*kops, error) {
 | 
				
			|||||||
	if *kopsState == "" {
 | 
						if *kopsState == "" {
 | 
				
			||||||
		return nil, fmt.Errorf("--kops-state must be set to a valid S3 path for kops deployment.")
 | 
							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 {
 | 
						if err := os.Setenv("KOPS_STATE_STORE", *kopsState); err != nil {
 | 
				
			||||||
		return nil, err
 | 
							return nil, err
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
@@ -432,13 +443,18 @@ func NewKops() (*kops, error) {
 | 
				
			|||||||
	if err := os.Setenv("KUBERNETES_CONFORMANCE_PROVIDER", "aws"); err != nil {
 | 
						if err := os.Setenv("KUBERNETES_CONFORMANCE_PROVIDER", "aws"); err != nil {
 | 
				
			||||||
		return nil, err
 | 
							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, ",")
 | 
						zones := strings.Split(*kopsZones, ",")
 | 
				
			||||||
	if err := os.Setenv("ZONE", zones[0]); err != nil {
 | 
						if err := os.Setenv("ZONE", zones[0]); err != nil {
 | 
				
			||||||
		return nil, err
 | 
							return nil, err
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	return &kops{
 | 
						return &kops{
 | 
				
			||||||
		path:    *kopsPath,
 | 
							path:    *kopsPath,
 | 
				
			||||||
 | 
							sshKey:  sshKey + ".pub", // kops only needs the public key, e2es need the private key.
 | 
				
			||||||
		zones:   zones,
 | 
							zones:   zones,
 | 
				
			||||||
		nodes:   *kopsNodes,
 | 
							nodes:   *kopsNodes,
 | 
				
			||||||
		cluster: *kopsCluster,
 | 
							cluster: *kopsCluster,
 | 
				
			||||||
@@ -450,6 +466,7 @@ func (k kops) Up() error {
 | 
				
			|||||||
	if err := finishRunning("kops config", exec.Command(
 | 
						if err := finishRunning("kops config", exec.Command(
 | 
				
			||||||
		k.path, "create", "cluster",
 | 
							k.path, "create", "cluster",
 | 
				
			||||||
		"--name", k.cluster,
 | 
							"--name", k.cluster,
 | 
				
			||||||
 | 
							"--ssh-public-key", k.sshKey,
 | 
				
			||||||
		"--node-count", strconv.Itoa(k.nodes),
 | 
							"--node-count", strconv.Itoa(k.nodes),
 | 
				
			||||||
		"--zones", strings.Join(k.zones, ","))); err != nil {
 | 
							"--zones", strings.Join(k.zones, ","))); err != nil {
 | 
				
			||||||
		return fmt.Errorf("kops configuration failed: %v", err)
 | 
							return fmt.Errorf("kops configuration failed: %v", err)
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -276,6 +276,7 @@ keep-gogoproto
 | 
				
			|||||||
km-path
 | 
					km-path
 | 
				
			||||||
kops-cluster
 | 
					kops-cluster
 | 
				
			||||||
kops-nodes
 | 
					kops-nodes
 | 
				
			||||||
 | 
					kops-ssh-key
 | 
				
			||||||
kops-state
 | 
					kops-state
 | 
				
			||||||
kops-zones
 | 
					kops-zones
 | 
				
			||||||
kube-api-burst
 | 
					kube-api-burst
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user