Navigation Menu

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

Use existing SSHKeyName if no public key is created. #6886

Merged
merged 1 commit into from May 7, 2019
Merged

Use existing SSHKeyName if no public key is created. #6886

merged 1 commit into from May 7, 2019

Conversation

rralcala
Copy link
Contributor

@rralcala rralcala commented May 6, 2019

Based on the Readme, if you specify a SSHKeyName in the cluster.spec, you don't need to add an ssh public key, this change allows that
combination to work on aws.

Basically, if a key name is set on the spec and there's no admin key
file, the key name will be used and the key will not be managed in
terraform.

I'd like to be able to use my own key in aws and not have it managed, I've seen similar issues created:

#4728
#3693

@k8s-ci-robot
Copy link
Contributor

Hi @rralcala. Thanks for your PR.

I'm waiting for a kubernetes member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@k8s-ci-robot k8s-ci-robot added the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label May 6, 2019
@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels May 6, 2019
@@ -37,7 +37,9 @@ func (b *SSHKeyModelBuilder) Build(c *fi.ModelBuilderContext) error {
t := &awstasks.SSHKey{
Name: s(name),
Lifecycle: b.Lifecycle,
PublicKey: fi.WrapResource(fi.NewStringResource(string(b.SSHPublicKeys[0]))),
}
if len(b.SSHPublicKeys) == 1 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we make this >= 1 (so we don't change behaviour for people that have more than 1)

@@ -108,6 +109,13 @@ func (e *SSHKey) Run(c *fi.Context) error {
}
glog.V(2).Infof("Computed SSH key fingerprint as %q", keyFingerprint)
e.KeyFingerprint = &keyFingerprint
} else if e.PublicKey == nil && c.Cluster.Spec.SSHKeyName != "" {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So in the tasks layer, we try not to refer back to the Cluster Spec; it's sort of crossing the layers - you might think of the tasks layer as being basically terraform. We probably should rename the Name field to be SSHKeyName in the task, but I think for the logic here you just want to check else if e.PublicKey == nil && e.Name != ""

return err
}

e.KeyFingerprint = a.KeyFingerprint
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think in this case you need to do:

if a == nil {
    return fmt.Errorf("unable to find specified SSH key %q", e.Name)
}

@@ -176,6 +187,9 @@ func (_ *SSHKey) RenderTerraform(t *terraform.TerraformTarget, a, e, changes *SS
}

func (e *SSHKey) TerraformLink() *terraform.Literal {
if e.KeyFingerprint != nil && e.PublicKey == nil {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it suffice to just do if e.PublicKey == nil { here?

One thing that might make it clearer is to explicitly have a method func (e *SSHKey) IsExistingKey() bool { return e.PublicKey == nil } or maybe even a field which you would set in the model.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@justinsb
Copy link
Member

justinsb commented May 7, 2019

Thanks @rralcala - a few suggestions as to the flow of the tasks, but I think we should get this in.

I presume you are setting this in a yaml file and doing kops replace? We could also expose SSHKeyName via the (WIP) support for setting fields https://github.com/kubernetes/kops/blob/master/pkg/commands/set_cluster.go#L82 . One day we'll stop hard-coding all those options, I hope/promise!

@justinsb
Copy link
Member

justinsb commented May 7, 2019

/ok-to-test

@k8s-ci-robot k8s-ci-robot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels May 7, 2019
@rralcala
Copy link
Contributor Author

rralcala commented May 7, 2019

Updated, Thank you @justinsb ! I can also add it to set_cluster

you don't need to add an ssh public key, this change allows that
combination to work on aws.

Basically, if a key name is set on the spec and there's no admin key
file, the key name will be used and the key will not be managed in
terraform.
@rralcala
Copy link
Contributor Author

rralcala commented May 7, 2019

/retest

@justinsb
Copy link
Member

justinsb commented May 7, 2019

Thanks @rralcala - this is a nice feature!

/approve
/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label May 7, 2019
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: justinsb, rralcala

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label May 7, 2019
@k8s-ci-robot k8s-ci-robot merged commit a6ee3cd into kubernetes:master May 7, 2019
k8s-ci-robot added a commit that referenced this pull request May 10, 2019
…ck-of-#6886-upstream-release-1.12

Automated Cherry Pick of #6886
k8s-ci-robot added a commit that referenced this pull request May 12, 2019
…86-origin-release-1.13

Automated cherry pick of #6886: Based on the Readme, if you specify a SSHKeyName in the
k8s-ci-robot added a commit that referenced this pull request May 12, 2019
…86-origin-release-1.14

Automated cherry pick of #6886: Based on the Readme, if you specify a SSHKeyName in the
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants