Skip to content
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

Workload updates #76

Merged
merged 1 commit into from
Jan 29, 2025
Merged
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
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:1.22
FROM golang:1.23

ENV GOPATH /root/go
ENV PATH ${PATH}:/root/go/bin
Expand Down
57 changes: 32 additions & 25 deletions framework/set/provisioning/multiclusters/setMultiCluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (

"github.com/hashicorp/hcl/v2/hclwrite"
"github.com/rancher/shepherd/clients/rancher"
"github.com/rancher/shepherd/pkg/config/operations"
namegen "github.com/rancher/shepherd/pkg/namegenerator"
configuration "github.com/rancher/tfp-automation/config"
"github.com/rancher/tfp-automation/defaults/clustertypes"
Expand All @@ -24,15 +25,17 @@ import (
)

// SetMultiCluster is a function that will set multiple cluster configurations in the main.tf file.
func SetMultiCluster(client *rancher.Client, rancherConfig *rancher.Config, configMap []map[string]any, clusterName string, newFile *hclwrite.File, rootBody *hclwrite.Body, file *os.File, rbacRole configuration.Role, poolName string) error {
func SetMultiCluster(client *rancher.Client, rancherConfig *rancher.Config, configMap []map[string]any, clusterName string, newFile *hclwrite.File, rootBody *hclwrite.Body, file *os.File, rbacRole configuration.Role, poolName string) ([]string, error) {

var err error
clusterNames := []string{}
customClusterNames := []string{}

for i, terratestConfig := range configMap {

terraformConfig := terratestConfig["terraform"].(configuration.TerraformConfig)
terratestConfig := terratestConfig["terratest"].(configuration.TerratestConfig)
for i, config := range configMap {
terraformConfig := new(configuration.TerraformConfig)
operations.LoadObjectFromMap(configuration.TerraformConfigurationFileKey, config, terraformConfig)
terratestConfig := new(configuration.TerratestConfig)
operations.LoadObjectFromMap(configuration.TerratestConfigurationFileKey, config, terratestConfig)

kubernetesVersion := terratestConfig.KubernetesVersion
nodePools := terratestConfig.Nodepools
Expand All @@ -45,72 +48,76 @@ func SetMultiCluster(client *rancher.Client, rancherConfig *rancher.Config, conf
terraformConfig.ClusterName = clusterName
poolName = namegen.AppendRandomString(configs.TFP)

clusterNames = append(clusterNames, clusterName)

if terraformConfig.Module == modules.CustomEC2RKE2 || terraformConfig.Module == modules.CustomEC2K3s {
customClusterNames = append(customClusterNames, clusterName)
}

switch {
case module == clustertypes.AKS:
file, err = hosted.SetAKS(&terraformConfig, clusterName, kubernetesVersion, nodePools, newFile, rootBody, file)
file, err = hosted.SetAKS(terraformConfig, clusterName, kubernetesVersion, nodePools, newFile, rootBody, file)
if err != nil {
return err
return clusterNames, err
}
case module == clustertypes.EKS:
file, err = hosted.SetEKS(&terraformConfig, clusterName, kubernetesVersion, nodePools, newFile, rootBody, file)
file, err = hosted.SetEKS(terraformConfig, clusterName, kubernetesVersion, nodePools, newFile, rootBody, file)
if err != nil {
return err
return clusterNames, err
}
case module == clustertypes.GKE:
file, err = hosted.SetGKE(&terraformConfig, clusterName, kubernetesVersion, nodePools, newFile, rootBody, file)
file, err = hosted.SetGKE(terraformConfig, clusterName, kubernetesVersion, nodePools, newFile, rootBody, file)
if err != nil {
return err
return clusterNames, err
}
case strings.Contains(module, clustertypes.RKE1) && !strings.Contains(module, defaults.Custom):
file, err = nodedriver.SetRKE1(&terraformConfig, clusterName, poolName, kubernetesVersion, psact, nodePools,
file, err = nodedriver.SetRKE1(terraformConfig, clusterName, poolName, kubernetesVersion, psact, nodePools,
snapshotInput, newFile, rootBody, file, rbacRole)
if err != nil {
return err
return clusterNames, err
}
case (strings.Contains(module, clustertypes.RKE2) || strings.Contains(module, clustertypes.K3S)) && !strings.Contains(module, defaults.Custom):
file, err = nodedriverV2.SetRKE2K3s(client, &terraformConfig, clusterName, poolName, kubernetesVersion, psact, nodePools,
file, err = nodedriverV2.SetRKE2K3s(client, terraformConfig, clusterName, poolName, kubernetesVersion, psact, nodePools,
snapshotInput, newFile, rootBody, file, rbacRole)
if err != nil {
return err
return clusterNames, err
}
case module == modules.CustomEC2RKE1:
file, err = custom.SetCustomRKE1(rancherConfig, &terraformConfig, &terratestConfig, configMap, clusterName, newFile, rootBody, file)
file, err = custom.SetCustomRKE1(rancherConfig, terraformConfig, terratestConfig, configMap, clusterName, newFile, rootBody, file)
if err != nil {
return err
return clusterNames, err
}
case module == modules.CustomEC2RKE2 || module == modules.CustomEC2K3s:
file, err = customV2.SetCustomRKE2K3s(rancherConfig, &terraformConfig, &terratestConfig, configMap, clusterName, newFile, rootBody, file)
file, err = customV2.SetCustomRKE2K3s(rancherConfig, terraformConfig, terratestConfig, configMap, clusterName, newFile, rootBody, file)
if err != nil {
return err
return clusterNames, err
}
case module == modules.AirgapRKE2 || module == modules.AirgapK3S:
file, err = airgap.SetAirgapRKE2K3s(rancherConfig, &terraformConfig, &terratestConfig, nil, clusterName, newFile, rootBody, file)
return err
file, err = airgap.SetAirgapRKE2K3s(rancherConfig, terraformConfig, terratestConfig, nil, clusterName, newFile, rootBody, file)
if err != nil {
return clusterNames, err
}
default:
logrus.Errorf("Unsupported module: %v", module)
}

if i == len(configMap)-1 {
file, err = locals.SetLocals(rootBody, &terraformConfig, configMap, clusterName, newFile, file, customClusterNames)
file, err = locals.SetLocals(rootBody, terraformConfig, configMap, clusterName, newFile, file, customClusterNames)
}
}

keyPath := resources.SetKeyPath()
file, err = os.Create(keyPath + configs.MainTF)
if err != nil {
logrus.Infof("Failed to reset/overwrite main.tf file. Error: %v", err)
return err
return clusterNames, err
}

_, err = file.Write(newFile.Bytes())
if err != nil {
logrus.Infof("Failed to write RKE2/K3S configurations to main.tf file. Error: %v", err)
return err
return clusterNames, err
}

return nil
return clusterNames, nil
}
27 changes: 14 additions & 13 deletions framework/set/setConfigTF.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,17 @@ import (

// ConfigTF is a function that will set the main.tf file based on the module type.
func ConfigTF(client *rancher.Client, rancherConfig *rancher.Config, terraformConfig *config.TerraformConfig, terratestConfig *config.TerratestConfig,
testUser, testPassword, clusterName, poolName string, rbacRole config.Role, configMap []map[string]any) error {
testUser, testPassword, clusterName, poolName string, rbacRole config.Role, configMap []map[string]any) ([]string, error) {
module := terraformConfig.Module

clusterNames := []string{clusterName}
var file *os.File
keyPath := resources.SetKeyPath()

file, err := os.Create(keyPath + configs.MainTF)
if err != nil {
logrus.Infof("Failed to reset/overwrite main.tf file. Error: %v", err)
return err
return nil, err
}

defer file.Close()
Expand All @@ -42,40 +43,40 @@ func ConfigTF(client *rancher.Client, rancherConfig *rancher.Config, terraformCo
rootBody.AppendNewline()

if terraformConfig.MultiCluster {
err = multiclusters.SetMultiCluster(client, rancherConfig, configMap, clusterName, newFile, rootBody, file, rbacRole, poolName)
return err
clusterNames, err = multiclusters.SetMultiCluster(client, rancherConfig, configMap, clusterName, newFile, rootBody, file, rbacRole, poolName)
return clusterNames, err
} else {
switch {
case module == clustertypes.AKS:
_, err = hosted.SetAKS(terraformConfig, clusterName, terratestConfig.KubernetesVersion, terratestConfig.Nodepools, newFile, rootBody, file)
return err
return clusterNames, err
case module == clustertypes.EKS:
_, err = hosted.SetEKS(terraformConfig, clusterName, terratestConfig.KubernetesVersion, terratestConfig.Nodepools, newFile, rootBody, file)
return err
return clusterNames, err
case module == clustertypes.GKE:
_, err = hosted.SetGKE(terraformConfig, clusterName, terratestConfig.KubernetesVersion, terratestConfig.Nodepools, newFile, rootBody, file)
return err
return clusterNames, err
case strings.Contains(module, clustertypes.RKE1) && !strings.Contains(module, defaults.Custom):
_, err = nodedriver.SetRKE1(terraformConfig, clusterName, poolName, terratestConfig.KubernetesVersion, terratestConfig.PSACT, terratestConfig.Nodepools,
terratestConfig.SnapshotInput, newFile, rootBody, file, rbacRole)
return err
return clusterNames, err
case (strings.Contains(module, clustertypes.RKE2) || strings.Contains(module, clustertypes.K3S)) && !strings.Contains(module, defaults.Custom) && !strings.Contains(module, defaults.Airgap):
_, err = nodedriverV2.SetRKE2K3s(client, terraformConfig, clusterName, poolName, terratestConfig.KubernetesVersion, terratestConfig.PSACT, terratestConfig.Nodepools,
terratestConfig.SnapshotInput, newFile, rootBody, file, rbacRole)
return err
return clusterNames, err
case module == modules.CustomEC2RKE1:
_, err = custom.SetCustomRKE1(rancherConfig, terraformConfig, terratestConfig, nil, clusterName, newFile, rootBody, file)
return err
return clusterNames, err
case module == modules.CustomEC2RKE2 || module == modules.CustomEC2K3s:
_, err = customV2.SetCustomRKE2K3s(rancherConfig, terraformConfig, terratestConfig, nil, clusterName, newFile, rootBody, file)
return err
return clusterNames, err
case module == modules.AirgapRKE2 || module == modules.AirgapK3S:
_, err = airgap.SetAirgapRKE2K3s(rancherConfig, terraformConfig, terratestConfig, nil, clusterName, newFile, rootBody, file)
return err
return clusterNames, err
default:
logrus.Errorf("Unsupported module: %v", module)
}

return nil
return clusterNames, nil
}
}
26 changes: 13 additions & 13 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
module github.com/rancher/tfp-automation

go 1.22.0
go 1.23.0

toolchain go1.22.3
toolchain go1.23.4

replace (
github.com/containerd/containerd => github.com/containerd/containerd v1.6.27 // for compatibilty with docker 20.10.x
Expand All @@ -29,10 +29,10 @@ require (
require (
github.com/antihax/optional v1.0.0
github.com/gruntwork-io/terratest v0.42.0
github.com/rancher/norman v0.0.0-20241001183610-78a520c160ab
github.com/rancher/rancher v0.0.0-20241111070012-ce59843e7b2b
github.com/rancher/norman v0.5.1
github.com/rancher/rancher v0.0.0-20250122213954-464e5c27fe8d
github.com/rancher/rancher/pkg/apis v0.0.0
github.com/rancher/shepherd v0.0.0-20241111160715-689bb4ad6d39
github.com/rancher/shepherd v0.0.0-20250106223550-9350f4861af3
github.com/sirupsen/logrus v1.9.3
)

Expand Down Expand Up @@ -92,11 +92,11 @@ require (
github.com/ulikunitz/xz v0.5.10 // indirect
github.com/zclconf/go-cty v1.14.1
go.opencensus.io v0.24.0 // indirect
golang.org/x/crypto v0.28.0 // indirect
golang.org/x/net v0.30.0 // indirect
golang.org/x/crypto v0.31.0 // indirect
golang.org/x/net v0.33.0 // indirect
golang.org/x/oauth2 v0.23.0 // indirect
golang.org/x/sys v0.26.0 // indirect
golang.org/x/text v0.19.0 // indirect
golang.org/x/sys v0.28.0 // indirect
golang.org/x/text v0.21.0 // indirect
google.golang.org/api v0.201.0 // indirect
google.golang.org/genproto v0.0.0-20241007155032-5fefd90f89a9 // indirect
google.golang.org/grpc v1.67.1 // indirect
Expand Down Expand Up @@ -152,9 +152,9 @@ require (
github.com/rancher/aks-operator v1.10.0 // indirect
github.com/rancher/apiserver v0.0.0-20241009200134-5a4ecca7b988 // indirect
github.com/rancher/eks-operator v1.10.0 // indirect
github.com/rancher/fleet/pkg/apis v0.11.0 // indirect
github.com/rancher/fleet/pkg/apis v0.12.0-alpha.2 // indirect
github.com/rancher/gke-operator v1.10.0 // indirect
github.com/rancher/lasso v0.0.0-20240924233157-8f384efc8813 // indirect
github.com/rancher/lasso v0.0.0-20241202185148-04649f379358 // indirect
github.com/rancher/rke v1.7.0-rc.5 // indirect
github.com/rancher/system-upgrade-controller/pkg/apis v0.0.0-20240301001845-4eacc2dabbde // indirect
github.com/rancher/wrangler v1.1.2 // indirect
Expand All @@ -164,8 +164,8 @@ require (
github.com/xlab/treeprint v1.2.0 // indirect
go.qase.io/client v0.0.0-20231114201952-65195ec001fa
go.starlark.net v0.0.0-20230525235612-a134d8f9ddca // indirect
golang.org/x/sync v0.8.0 // indirect
golang.org/x/term v0.25.0 // indirect
golang.org/x/sync v0.10.0 // indirect
golang.org/x/term v0.27.0 // indirect
golang.org/x/time v0.7.0 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20240930140551-af27646dc61f // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20241007155032-5fefd90f89a9 // indirect
Expand Down
Loading
Loading