Skip to content

Commit

Permalink
Use keys specified in env vars for GCP and AWS
Browse files Browse the repository at this point in the history
Signed-off-by: Davanum Srinivas <davanum@gmail.com>
  • Loading branch information
dims committed Aug 30, 2024
1 parent d5c56dc commit ef76bf9
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions tests/e2e/kubetest2-kops/deployer/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@ func (d *deployer) initialize() error {

switch d.CloudProvider {
case "aws":
if d.SSHPrivateKeyPath == "" {
d.SSHPrivateKeyPath = os.Getenv("AWS_SSH_PRIVATE_KEY_FILE")
}
if d.SSHPublicKeyPath == "" {
d.SSHPublicKeyPath = os.Getenv("AWS_SSH_PUBLIC_KEY_FILE")
}
if d.SSHPrivateKeyPath == "" || d.SSHPublicKeyPath == "" {
publicKeyPath, privateKeyPath, err := util.CreateSSHKeyPair(d.ClusterName)
if err != nil {
Expand Down Expand Up @@ -90,6 +96,12 @@ func (d *deployer) initialize() error {
d.GCPProject = resource.Name
klog.V(1).Infof("Got project %s from boskos", d.GCPProject)

if d.SSHPrivateKeyPath == "" {
d.SSHPrivateKeyPath = os.Getenv("GCE_SSH_PRIVATE_KEY_FILE")
}
if d.SSHPublicKeyPath == "" {
d.SSHPublicKeyPath = os.Getenv("GCE_SSH_PUBLIC_KEY_FILE")
}
if d.SSHPrivateKeyPath == "" && d.SSHPublicKeyPath == "" {
privateKey, publicKey, err := gce.SetupSSH(d.GCPProject)
if err != nil {
Expand All @@ -98,12 +110,15 @@ func (d *deployer) initialize() error {
d.SSHPrivateKeyPath = privateKey
d.SSHPublicKeyPath = publicKey
}

d.createBucket = true
} else if d.SSHPrivateKeyPath == "" && os.Getenv("KUBE_SSH_KEY_PATH") != "" {
d.SSHPrivateKeyPath = os.Getenv("KUBE_SSH_KEY_PATH")
}
}

klog.V(1).Infof("Using SSH keypair: [%s,%s]", d.SSHPrivateKeyPath, d.SSHPublicKeyPath)

if d.commonOptions.ShouldBuild() {
if err := d.verifyBuildFlags(); err != nil {
return fmt.Errorf("init failed to check build flags: %v", err)
Expand All @@ -113,6 +128,8 @@ func (d *deployer) initialize() error {
if d.SSHUser == "" {
d.SSHUser = os.Getenv("KUBE_SSH_USER")
}
klog.V(1).Infof("Using SSH user: [%s]", d.SSHUser)

if d.TerraformVersion != "" {
t, err := target.NewTerraform(d.TerraformVersion)
if err != nil {
Expand Down

0 comments on commit ef76bf9

Please sign in to comment.