Set ssh key on the model context in one location

This commit is contained in:
Ole Markus With 2021-01-13 19:24:02 +01:00
parent 9b214b48cf
commit 782052f472
1 changed files with 1 additions and 10 deletions

View File

@ -401,7 +401,6 @@ func (c *ApplyClusterCmd) Run(ctx context.Context) error {
return fmt.Errorf("GCE support is currently alpha, and is feature-gated. export KOPS_FEATURE_FLAGS=AlphaAllowGCE") return fmt.Errorf("GCE support is currently alpha, and is feature-gated. export KOPS_FEATURE_FLAGS=AlphaAllowGCE")
} }
modelContext.SSHPublicKeys = sshPublicKeys
} }
case kops.CloudProviderDO: case kops.CloudProviderDO:
@ -410,7 +409,6 @@ func (c *ApplyClusterCmd) Run(ctx context.Context) error {
return fmt.Errorf("SSH public key must be specified when running with DigitalOcean (create with `kops create secret --name %s sshpublickey admin -i ~/.ssh/id_rsa.pub`)", cluster.ObjectMeta.Name) return fmt.Errorf("SSH public key must be specified when running with DigitalOcean (create with `kops create secret --name %s sshpublickey admin -i ~/.ssh/id_rsa.pub`)", cluster.ObjectMeta.Name)
} }
modelContext.SSHPublicKeys = sshPublicKeys
} }
case kops.CloudProviderAWS: case kops.CloudProviderAWS:
{ {
@ -427,8 +425,6 @@ func (c *ApplyClusterCmd) Run(ctx context.Context) error {
return fmt.Errorf("SSH public key must be specified when running with AWS (create with `kops create secret --name %s sshpublickey admin -i ~/.ssh/id_rsa.pub`)", cluster.ObjectMeta.Name) return fmt.Errorf("SSH public key must be specified when running with AWS (create with `kops create secret --name %s sshpublickey admin -i ~/.ssh/id_rsa.pub`)", cluster.ObjectMeta.Name)
} }
modelContext.SSHPublicKeys = sshPublicKeys
if len(sshPublicKeys) > 1 { if len(sshPublicKeys) > 1 {
return fmt.Errorf("exactly one 'admin' SSH public key can be specified when running with AWS; please delete a key using `kops delete secret`") return fmt.Errorf("exactly one 'admin' SSH public key can be specified when running with AWS; please delete a key using `kops delete secret`")
} }
@ -448,8 +444,6 @@ func (c *ApplyClusterCmd) Run(ctx context.Context) error {
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) 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)
} }
modelContext.SSHPublicKeys = sshPublicKeys
if len(sshPublicKeys) != 1 { if len(sshPublicKeys) != 1 {
return fmt.Errorf("exactly one 'admin' SSH public key can be specified when running with ALICloud; please delete a key using `kops delete secret`") return fmt.Errorf("exactly one 'admin' SSH public key can be specified when running with ALICloud; please delete a key using `kops delete secret`")
} }
@ -464,8 +458,6 @@ func (c *ApplyClusterCmd) Run(ctx context.Context) error {
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) 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)
} }
modelContext.SSHPublicKeys = sshPublicKeys
if len(sshPublicKeys) != 1 { if len(sshPublicKeys) != 1 {
return fmt.Errorf("exactly one 'admin' SSH public key can be specified when running with AzureCloud; please delete a key using `kops delete secret`") return fmt.Errorf("exactly one 'admin' SSH public key can be specified when running with AzureCloud; please delete a key using `kops delete secret`")
} }
@ -476,8 +468,6 @@ func (c *ApplyClusterCmd) Run(ctx context.Context) error {
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) 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)
} }
modelContext.SSHPublicKeys = sshPublicKeys
if len(sshPublicKeys) != 1 { if len(sshPublicKeys) != 1 {
return fmt.Errorf("exactly one 'admin' SSH public key can be specified when running with Openstack; please delete a key using `kops delete secret`") return fmt.Errorf("exactly one 'admin' SSH public key can be specified when running with Openstack; please delete a key using `kops delete secret`")
} }
@ -486,6 +476,7 @@ func (c *ApplyClusterCmd) Run(ctx context.Context) error {
return fmt.Errorf("unknown CloudProvider %q", cluster.Spec.CloudProvider) return fmt.Errorf("unknown CloudProvider %q", cluster.Spec.CloudProvider)
} }
modelContext.SSHPublicKeys = sshPublicKeys
modelContext.Region = cloud.Region() modelContext.Region = cloud.Region()
if dns.IsGossipHostname(cluster.ObjectMeta.Name) { if dns.IsGossipHostname(cluster.ObjectMeta.Name) {