Skip to content

feat: add internal node to generated sshconfig #329

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions pkg/simulator/terraform_output.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ type TerraformOutput struct {
BastionPublicIP StringOutput `json:"bastion_public_ip"`
ClusterNodesPrivateIP StringSliceOutput `json:"cluster_nodes_private_ip"`
MasterNodesPrivateIP StringSliceOutput `json:"master_nodes_private_ip"`
InternalNodePrivateIP StringOutput `json:"internal_host_private_ip"`
}

var bastionConfigTmplSrc = `Host bastion {{.Hostname}}
Expand Down Expand Up @@ -111,6 +112,18 @@ func (tfo *TerraformOutput) ToSSHConfig() (*string, error) {
}
}

c := SSHConfig{
Alias: "internal",
Hostname: tfo.InternalNodePrivateIP.Value,
KeyFilePath: ssh.PrivateKeyPath,
KnownHostsFilePath: ssh.KnownHostsPath,
BastionIP: tfo.BastionPublicIP.Value,
}
err = k8sConfigTmpl.Execute(&buf, c)
if err != nil {
return nil, errors.Wrapf(err, "Error populating ssh internal config template with %+v", c)
}

var output = buf.String()
return &output, nil
}
Expand Down
12 changes: 12 additions & 0 deletions pkg/simulator/terraform_output_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ func Test_ToSSHConfig(t *testing.T) {
Type: []interface{}{},
Value: []string{"127.0.0.2", "127.0.0.3"},
},
InternalNodePrivateIP: simulator.StringOutput{
Sensitive: false,
Type: "string",
Value: "127.0.0.4",
},
}
expected := `Host bastion 8.8.8.8
Hostname 8.8.8.8
Expand Down Expand Up @@ -86,6 +91,13 @@ Host node-1 127.0.0.3
IdentityFile ~/.kubesim/cp_simulator_rsa
UserKnownHostsFile ~/.kubesim/cp_simulator_known_hosts
ProxyJump bastion
Host internal 127.0.0.4
Hostname 127.0.0.4
User root
RequestTTY force
IdentityFile ~/.kubesim/cp_simulator_rsa
UserKnownHostsFile ~/.kubesim/cp_simulator_known_hosts
ProxyJump bastion
`

out, err := tfo.ToSSHConfig()
Expand Down