Skip to content

Commit

Permalink
Merge pull request #10474 from justinsb/refactor_out_cloud
Browse files Browse the repository at this point in the history
Use Region method of fi.Cloud
  • Loading branch information
k8s-ci-robot authored Dec 22, 2020
2 parents 9bc1c0e + 604cb67 commit f60b0d2
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 29 deletions.
21 changes: 4 additions & 17 deletions upup/pkg/fi/cloudup/apply_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,6 @@ func (c *ApplyClusterCmd) Run(ctx context.Context) error {

checkExisting := true

region := ""
project := ""

var sshPublicKeys [][]byte
Expand All @@ -378,7 +377,6 @@ func (c *ApplyClusterCmd) Run(ctx context.Context) error {
case kops.CloudProviderGCE:
{
gceCloud := cloud.(gce.GCECloud)
region = gceCloud.Region()
project = gceCloud.Project()

if !AlphaAllowGCE.Enabled() {
Expand All @@ -399,7 +397,6 @@ func (c *ApplyClusterCmd) Run(ctx context.Context) error {
case kops.CloudProviderAWS:
{
awsCloud := cloud.(awsup.AWSCloud)
region = awsCloud.Region()

accountID, partition, err := awsCloud.AccountInfo()
if err != nil {
Expand All @@ -425,9 +422,6 @@ func (c *ApplyClusterCmd) Run(ctx context.Context) error {
return fmt.Errorf("aliyun support is currently alpha, and is feature-gated. export KOPS_FEATURE_FLAGS=AlphaAllowALI")
}

aliCloud := cloud.(aliup.ALICloud)
region = aliCloud.Region()

if len(sshPublicKeys) == 0 {
return fmt.Errorf("SSH public key must be specified when running with ALICloud (create with `kops create secret --name %s sshpublickey admin -i ~/.ssh/id_rsa.pub`)", cluster.ObjectMeta.Name)
}
Expand All @@ -444,9 +438,6 @@ func (c *ApplyClusterCmd) Run(ctx context.Context) error {
return fmt.Errorf("azure support is currently alpha, and is feature-gated. Please export KOPS_FEATURE_FLAGS=Azure")
}

azureCloud := cloud.(azure.AzureCloud)
region = azureCloud.Region()

if len(sshPublicKeys) == 0 {
return fmt.Errorf("SSH public key must be specified when running with AzureCloud (create with `kops create secret --name %s sshpublickey admin -i ~/.ssh/id_rsa.pub`)", cluster.ObjectMeta.Name)
}
Expand All @@ -459,10 +450,6 @@ func (c *ApplyClusterCmd) Run(ctx context.Context) error {
}
case kops.CloudProviderOpenstack:
{

osCloud := cloud.(openstack.OpenstackCloud)
region = osCloud.Region()

if len(sshPublicKeys) == 0 {
return fmt.Errorf("SSH public key must be specified when running with Openstack (create with `kops create secret --name %s sshpublickey admin -i ~/.ssh/id_rsa.pub`)", cluster.ObjectMeta.Name)
}
Expand All @@ -477,7 +464,7 @@ func (c *ApplyClusterCmd) Run(ctx context.Context) error {
return fmt.Errorf("unknown CloudProvider %q", cluster.Spec.CloudProvider)
}

modelContext.Region = region
modelContext.Region = cloud.Region()

if dns.IsGossipHostname(cluster.ObjectMeta.Name) {
klog.Infof("Gossip DNS: skipping DNS validation")
Expand Down Expand Up @@ -758,10 +745,10 @@ func (c *ApplyClusterCmd) Run(ctx context.Context) error {
case TargetTerraform:
checkExisting = false
outDir := c.OutDir
tf := terraform.NewTerraformTarget(cloud, region, project, outDir, cluster.Spec.Target)
tf := terraform.NewTerraformTarget(cloud, project, outDir, cluster.Spec.Target)

// We include a few "util" variables in the TF output
if err := tf.AddOutputVariable("region", terraform.LiteralFromStringValue(region)); err != nil {
if err := tf.AddOutputVariable("region", terraform.LiteralFromStringValue(cloud.Region())); err != nil {
return err
}

Expand All @@ -783,7 +770,7 @@ func (c *ApplyClusterCmd) Run(ctx context.Context) error {
case TargetCloudformation:
checkExisting = false
outDir := c.OutDir
target = cloudformation.NewCloudformationTarget(cloud, region, project, outDir)
target = cloudformation.NewCloudformationTarget(cloud, project, outDir)

// Can cause conflicts with cloudformation management
shouldPrecreateDNS = false
Expand Down
4 changes: 2 additions & 2 deletions upup/pkg/fi/cloudup/awstasks/render_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,10 @@ func doRenderTests(t *testing.T, method string, cases []*renderTest) {

switch method {
case "RenderTerraform":
target = terraform.NewTerraformTarget(cloud, "eu-west-2", "test", outdir, nil)
target = terraform.NewTerraformTarget(cloud, "test", outdir, nil)
filename = "kubernetes.tf"
case "RenderCloudformation":
target = cloudformation.NewCloudformationTarget(cloud, "eu-west-2", "test", outdir)
target = cloudformation.NewCloudformationTarget(cloud, "test", outdir)
filename = "kubernetes.json"
default:
t.Errorf("unknown render method: %s", method)
Expand Down
4 changes: 1 addition & 3 deletions upup/pkg/fi/cloudup/cloudformation/target.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ import (

type CloudformationTarget struct {
Cloud fi.Cloud
Region string
Project string

outDir string
Expand All @@ -41,10 +40,9 @@ type CloudformationTarget struct {
resources map[string]*cloudformationResource
}

func NewCloudformationTarget(cloud fi.Cloud, region, project string, outDir string) *CloudformationTarget {
func NewCloudformationTarget(cloud fi.Cloud, project string, outDir string) *CloudformationTarget {
return &CloudformationTarget{
Cloud: cloud,
Region: region,
Project: project,
outDir: outDir,
resources: make(map[string]*cloudformationResource),
Expand Down
2 changes: 1 addition & 1 deletion upup/pkg/fi/cloudup/gcetasks/instancetemplate.go
Original file line number Diff line number Diff line change
Expand Up @@ -538,7 +538,7 @@ func addServiceAccounts(serviceAccounts []*compute.ServiceAccount) *terraformSer
func (_ *InstanceTemplate) RenderTerraform(t *terraform.TerraformTarget, a, e, changes *InstanceTemplate) error {
project := t.Project

i, err := e.mapToGCE(project, t.Region)
i, err := e.mapToGCE(project, t.Cloud.Region())
if err != nil {
return err
}
Expand Down
4 changes: 1 addition & 3 deletions upup/pkg/fi/cloudup/terraform/target.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ import (

type TerraformTarget struct {
Cloud fi.Cloud
Region string
Project string

ClusterName string
Expand All @@ -52,10 +51,9 @@ type TerraformTarget struct {
clusterSpecTarget *kops.TargetSpec
}

func NewTerraformTarget(cloud fi.Cloud, region, project string, outDir string, clusterSpecTarget *kops.TargetSpec) *TerraformTarget {
func NewTerraformTarget(cloud fi.Cloud, project string, outDir string, clusterSpecTarget *kops.TargetSpec) *TerraformTarget {
return &TerraformTarget{
Cloud: cloud,
Region: region,
Project: project,

outDir: outDir,
Expand Down
2 changes: 1 addition & 1 deletion upup/pkg/fi/cloudup/terraform/target_hcl2.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func (t *TerraformTarget) finishHCL2(taskMap map[string]fi.Task) error {
}
providerBlock := rootBody.AppendNewBlock("provider", []string{providerName})
providerBody := providerBlock.Body()
providerBody.SetAttributeValue("region", cty.StringVal(t.Region))
providerBody.SetAttributeValue("region", cty.StringVal(t.Cloud.Region()))
for k, v := range tfGetProviderExtraConfig(t.clusterSpecTarget) {
providerBody.SetAttributeValue(k, cty.StringVal(v))
}
Expand Down
4 changes: 2 additions & 2 deletions upup/pkg/fi/cloudup/terraform/target_json.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,14 @@ func (t *TerraformTarget) finishJSON(taskMap map[string]fi.Task) error {
if t.Cloud.ProviderID() == kops.CloudProviderGCE {
providerGoogle := make(map[string]interface{})
providerGoogle["project"] = t.Project
providerGoogle["region"] = t.Region
providerGoogle["region"] = t.Cloud.Region()
for k, v := range tfGetProviderExtraConfig(t.clusterSpecTarget) {
providerGoogle[k] = v
}
providersByName["google"] = providerGoogle
} else if t.Cloud.ProviderID() == kops.CloudProviderAWS {
providerAWS := make(map[string]interface{})
providerAWS["region"] = t.Region
providerAWS["region"] = t.Cloud.Region()
for k, v := range tfGetProviderExtraConfig(t.clusterSpecTarget) {
providerAWS[k] = v
}
Expand Down

0 comments on commit f60b0d2

Please sign in to comment.