forked from rancher/tfp-automation
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Automate proxy checks for release testing
Co-authored-by: Markus Walker <[email protected]> Co-authored-by: Josh Keslar <[email protected]>
- Loading branch information
1 parent
52387c7
commit 119d6d9
Showing
40 changed files
with
1,327 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
framework/set/provisioning/nodedriver/rke2k3s/setProxyConfig.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package rke2k3s | ||
|
||
import ( | ||
"github.com/hashicorp/hcl/v2/hclwrite" | ||
"github.com/rancher/tfp-automation/config" | ||
"github.com/rancher/tfp-automation/framework/set/defaults" | ||
"github.com/zclconf/go-cty/cty" | ||
) | ||
|
||
// SetProxyConfig is a function that will set the proxy configurations in the main.tf file. | ||
func SetProxyConfig(clusterBlockBody *hclwrite.Body, terraformConfig *config.TerraformConfig) error { | ||
agentVarsOneBlock := clusterBlockBody.AppendNewBlock(defaults.AgentEnvVars, nil) | ||
agentVarsOneBlockBody := agentVarsOneBlock.Body() | ||
|
||
agentVarsOneBlockBody.SetAttributeValue(defaults.ResourceName, cty.StringVal(httpProxy)) | ||
agentVarsOneBlockBody.SetAttributeValue(defaults.Value, cty.StringVal("http://"+terraformConfig.Proxy.ProxyBastion+":3128")) | ||
|
||
agentVarsTwoBlock := clusterBlockBody.AppendNewBlock(defaults.AgentEnvVars, nil) | ||
agentVarsTwoBlockBody := agentVarsTwoBlock.Body() | ||
|
||
agentVarsTwoBlockBody.SetAttributeValue(defaults.ResourceName, cty.StringVal(httpsProxy)) | ||
agentVarsTwoBlockBody.SetAttributeValue(defaults.Value, cty.StringVal("http://"+terraformConfig.Proxy.ProxyBastion+":3128")) | ||
|
||
agentVarsThreeBlock := clusterBlockBody.AppendNewBlock(defaults.AgentEnvVars, nil) | ||
agentVarsThreeBlockBody := agentVarsThreeBlock.Body() | ||
|
||
agentVarsThreeBlockBody.SetAttributeValue(defaults.ResourceName, cty.StringVal(noProxy)) | ||
agentVarsThreeBlockBody.SetAttributeValue(defaults.Value, cty.StringVal(noProxyValue)) | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
package proxy | ||
|
||
import ( | ||
"os" | ||
"testing" | ||
|
||
"github.com/gruntwork-io/terratest/modules/terraform" | ||
"github.com/hashicorp/hcl/v2/hclwrite" | ||
"github.com/rancher/tfp-automation/config" | ||
"github.com/rancher/tfp-automation/framework/set/resources/proxy/rancher" | ||
"github.com/rancher/tfp-automation/framework/set/resources/proxy/rke2" | ||
"github.com/rancher/tfp-automation/framework/set/resources/proxy/squid" | ||
"github.com/rancher/tfp-automation/framework/set/resources/sanity" | ||
"github.com/rancher/tfp-automation/framework/set/resources/sanity/aws" | ||
) | ||
|
||
const ( | ||
rke2Bastion = "rke2_bastion" | ||
rke2ServerOne = "rke2_server1" | ||
rke2ServerTwo = "rke2_server2" | ||
rke2ServerThree = "rke2_server3" | ||
|
||
rke2ServerOnePublicDNS = "rke2_server1_public_dns" | ||
rke2BastionPublicDNS = "rke2_bastion_public_dns" | ||
rke2ServerOnePrivateIP = "rke2_server1_private_ip" | ||
rke2ServerTwoPublicDNS = "rke2_server2_public_dns" | ||
rke2ServerThreePublicDNS = "rke2_server3_public_dns" | ||
|
||
terraformConst = "terraform" | ||
) | ||
|
||
// CreateMainTF is a helper function that will create the main.tf file for creating a Rancher server behind a proxy. | ||
func CreateMainTF(t *testing.T, terraformOptions *terraform.Options, keyPath string, terraformConfig *config.TerraformConfig, | ||
terratest *config.TerratestConfig) (string, string, error) { | ||
var file *os.File | ||
file = sanity.OpenFile(file, keyPath) | ||
defer file.Close() | ||
|
||
newFile := hclwrite.NewEmptyFile() | ||
rootBody := newFile.Body() | ||
|
||
tfBlock := rootBody.AppendNewBlock(terraformConst, nil) | ||
tfBlockBody := tfBlock.Body() | ||
|
||
instances := []string{rke2Bastion, rke2ServerOne, rke2ServerTwo, rke2ServerThree} | ||
file, err := aws.CreateAWSResources(file, newFile, tfBlockBody, rootBody, terraformConfig, terratest, instances) | ||
if err != nil { | ||
return "", "", err | ||
} | ||
|
||
terraform.InitAndApply(t, terraformOptions) | ||
|
||
rke2BastionPublicDNS := terraform.Output(t, terraformOptions, rke2BastionPublicDNS) | ||
rke2ServerOnePublicDNS := terraform.Output(t, terraformOptions, rke2ServerOnePublicDNS) | ||
rke2ServerOnePrivateIP := terraform.Output(t, terraformOptions, rke2ServerOnePrivateIP) | ||
rke2ServerTwoPublicDNS := terraform.Output(t, terraformOptions, rke2ServerTwoPublicDNS) | ||
rke2ServerThreePublicDNS := terraform.Output(t, terraformOptions, rke2ServerThreePublicDNS) | ||
|
||
terraform.InitAndApply(t, terraformOptions) | ||
|
||
file = sanity.OpenFile(file, keyPath) | ||
file, err = squid.CreateSquidProxy(file, newFile, rootBody, terraformConfig, rke2BastionPublicDNS) | ||
if err != nil { | ||
return "", "", err | ||
} | ||
|
||
terraform.InitAndApply(t, terraformOptions) | ||
|
||
file = sanity.OpenFile(file, keyPath) | ||
file, err = rke2.CreateRKE2Cluster(file, newFile, rootBody, terraformConfig, rke2BastionPublicDNS, rke2ServerOnePublicDNS, rke2ServerOnePrivateIP, rke2ServerTwoPublicDNS, rke2ServerThreePublicDNS) | ||
if err != nil { | ||
return "", "", err | ||
} | ||
|
||
terraform.InitAndApply(t, terraformOptions) | ||
|
||
file = sanity.OpenFile(file, keyPath) | ||
file, err = rancher.CreateProxiedRancher(file, newFile, rootBody, terraformConfig, rke2ServerOnePublicDNS, rke2BastionPublicDNS) | ||
if err != nil { | ||
return "", "", err | ||
} | ||
|
||
terraform.InitAndApply(t, terraformOptions) | ||
|
||
return rke2BastionPublicDNS, rke2ServerOnePublicDNS, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package proxy | ||
|
||
import ( | ||
"os" | ||
"path/filepath" | ||
|
||
"github.com/sirupsen/logrus" | ||
) | ||
|
||
const ( | ||
mainTfKeyPath = "PROXY_KEY_PATH" | ||
) | ||
|
||
// KeyPath is a function that will set the path to the key file. | ||
func KeyPath() string { | ||
userDir, err := os.UserHomeDir() | ||
if err != nil { | ||
return "" | ||
} | ||
|
||
mainTfDirPath := os.Getenv(mainTfKeyPath) | ||
if mainTfDirPath == "" { | ||
logrus.Fatalf("Expected env var not set: %s", mainTfKeyPath) | ||
} | ||
|
||
keyPath := filepath.Join(userDir, mainTfDirPath) | ||
|
||
return keyPath | ||
} |
Oops, something went wrong.