mirror of https://github.com/kubernetes/kops.git
Use Region method of fi.Cloud
There's no need to track it separately, now that we have the Region method on the Cloud interface.
This commit is contained in:
parent
9bc1c0ed77
commit
8fb7f1930d
|
|
@ -354,7 +354,6 @@ func (c *ApplyClusterCmd) Run(ctx context.Context) error {
|
|||
|
||||
checkExisting := true
|
||||
|
||||
region := ""
|
||||
project := ""
|
||||
|
||||
var sshPublicKeys [][]byte
|
||||
|
|
@ -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() {
|
||||
|
|
@ -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 {
|
||||
|
|
@ -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)
|
||||
}
|
||||
|
|
@ -459,10 +453,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)
|
||||
}
|
||||
|
|
@ -477,7 +467,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")
|
||||
|
|
@ -758,10 +748,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
|
||||
}
|
||||
|
||||
|
|
@ -783,7 +773,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
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -31,7 +31,6 @@ import (
|
|||
|
||||
type CloudformationTarget struct {
|
||||
Cloud fi.Cloud
|
||||
Region string
|
||||
Project string
|
||||
|
||||
outDir string
|
||||
|
|
@ -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),
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
|
|
@ -33,7 +33,6 @@ import (
|
|||
|
||||
type TerraformTarget struct {
|
||||
Cloud fi.Cloud
|
||||
Region string
|
||||
Project string
|
||||
|
||||
ClusterName string
|
||||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue