From f19c6a622b7a48d7b0e497fb03fd7ad3e8b4211e Mon Sep 17 00:00:00 2001 From: James Cleverley-Prance Date: Tue, 22 Feb 2022 15:08:57 +0000 Subject: [PATCH] feat: add internal node to generated sshconfig --- pkg/simulator/terraform_output.go | 13 +++++++++++++ pkg/simulator/terraform_output_test.go | 12 ++++++++++++ 2 files changed, 25 insertions(+) diff --git a/pkg/simulator/terraform_output.go b/pkg/simulator/terraform_output.go index 95ccb018..78f3866e 100644 --- a/pkg/simulator/terraform_output.go +++ b/pkg/simulator/terraform_output.go @@ -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}} @@ -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 } diff --git a/pkg/simulator/terraform_output_test.go b/pkg/simulator/terraform_output_test.go index 1b77398b..3b5ecae2 100644 --- a/pkg/simulator/terraform_output_test.go +++ b/pkg/simulator/terraform_output_test.go @@ -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 @@ -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()