Skip to content

Commit

Permalink
update ssh authorized in worker node groups in API tests (aws#5842)
Browse files Browse the repository at this point in the history
  • Loading branch information
cxbrowne1207 committed May 11, 2023
1 parent 9db95bb commit 577a333
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
12 changes: 8 additions & 4 deletions internal/pkg/api/vspheremachines.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package api

import (
"os"

anywherev1 "github.com/aws/eks-anywhere/pkg/api/v1alpha1"
)

Expand Down Expand Up @@ -64,10 +66,12 @@ func WithSSHKey(value string) VSphereMachineConfigFiller {
}
}

func setSSHKeyForFirstUser(m *anywherev1.VSphereMachineConfig, key string) {
if len(m.Spec.Users) == 0 {
m.Spec.Users = []anywherev1.UserConfiguration{{}}
}
// WithStringFromEnvVar returns a VSphereMachineConfigFiller function with the value from an envVar passed to it.
func WithStringFromEnvVar(envVar string, opt func(string) VSphereMachineConfigFiller) VSphereMachineConfigFiller {
return opt(os.Getenv(envVar))
}

func setSSHKeyForFirstUser(m *anywherev1.VSphereMachineConfig, key string) {
m.SetUserDefaults()
m.Spec.Users[0].SshAuthorizedKeys = []string{key}
}
8 changes: 7 additions & 1 deletion test/framework/vsphere.go
Original file line number Diff line number Diff line change
Expand Up @@ -457,8 +457,9 @@ func WithVSphereWorkerNodeGroup(name string, workerNodeGroup *WorkerNodeGroup, f
// WithWorkerNodeGroup returns an api.ClusterFiller that adds a new workerNodeGroupConfiguration and
// a corresponding VSphereMachineConfig to the cluster config.
func (v *VSphere) WithWorkerNodeGroup(name string, workerNodeGroup *WorkerNodeGroup, fillers ...api.VSphereMachineConfigFiller) api.ClusterConfigFiller {
machineConfigFillers := append([]api.VSphereMachineConfigFiller{updateMachineSSHAuthorizedKey()}, fillers...)
return api.JoinClusterConfigFillers(
api.VSphereToConfigFiller(vSphereMachineConfig(name, fillers...)),
api.VSphereToConfigFiller(vSphereMachineConfig(name, machineConfigFillers...)),
api.ClusterToConfigFiller(buildVSphereWorkerNodeGroupClusterFiller(name, workerNodeGroup)),
)
}
Expand All @@ -468,6 +469,11 @@ func (v *VSphere) WithWorkerNodeGroupConfiguration(name string, workerNodeGroup
return api.ClusterToConfigFiller(buildVSphereWorkerNodeGroupClusterFiller(name, workerNodeGroup))
}

// updateMachineSSHAuthorizedKey updates a vsphere machine configs SSHAuthorizedKey.
func updateMachineSSHAuthorizedKey() api.VSphereMachineConfigFiller {
return api.WithStringFromEnvVar(vsphereSshAuthorizedKeyVar, api.WithSSHKey)
}

// WithVSphereFillers adds VSphereFiller to the provider default fillers.
func WithVSphereFillers(fillers ...api.VSphereFiller) VSphereOpt {
return func(v *VSphere) {
Expand Down

0 comments on commit 577a333

Please sign in to comment.