-
Notifications
You must be signed in to change notification settings - Fork 84
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
Support to create and delete ssh-keys in the PowerVS environment. #1087
Support to create and delete ssh-keys in the PowerVS environment. #1087
Conversation
✅ Deploy Preview for kubernetes-sigs-cluster-api-ibmcloud ready!
To edit notification comments on pull requests, go to your Netlify site settings. |
Welcome @kishen-v! |
Hi @kishen-v. Thanks for your PR. I'm waiting for a kubernetes-sigs member to verify that this patch is reasonable to test. If it is, they should reply with Once the patch is verified, the new status will be reflected by the 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. |
/ok-to-test |
f4c478e
to
cd77c22
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Few suggestions otherwise looks good to me.
logger := log.Log | ||
logger.Info("Creating ssh key...") | ||
auth := iam.GetIAMAuth() | ||
accountID, _ := utils.GetAccountID(ctx, auth) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lets handle the error here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressed.
if err != nil { | ||
return err | ||
} | ||
c := instance.NewIBMPIKeyClient(ctx, sess, options.GlobalOptions.ServiceInstanceID) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
instead of c lets use something meaningful name like keyClient.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressed.
ff445ea
to
685bbde
Compare
Example: ` | ||
# Create an ssh key. | ||
export IBMCLOUD_API_KEY=<api-key> | ||
capibmadm powervs key create --name <key-name> --key "<ssh key>" --service-instance-id <service-instance-id> --zone <zone>`, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also should we pass name via flag or as an argument? @Prajyot-Parab @dharaneeshvrd
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMO passing via flag would be more readable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, then I think we can stick to how it is now then.
af0cef1
to
3cbeabf
Compare
LGTM, Please take a look @dharaneeshvrd @Prajyot-Parab later will seek manju's help. |
Testing it on my local, will update. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In general, new line between each block, makes code more readable
otherwise lgtm.
"sigs.k8s.io/cluster-api-provider-ibmcloud/cmd/capibmadm/utils" | ||
) | ||
|
||
type keyCreateParams struct { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
type keyCreateParams struct { | |
type keyCreateOptions struct { |
Options is used more commonly in this repo, better to follow same name conventions here too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changes made as suggested.
Added new-lines to improve readability.
a59ce08
to
1f10bc1
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: Power VS
--> PowerVS
everywhere
04305f6
to
c4ae5c2
Compare
Updated all references of |
/* | ||
Copyright 2023 The Kubernetes Authors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/* | |
Copyright 2023 The Kubernetes Authors. | |
Licensed under the Apache License, Version 2.0 (the "License"); | |
you may not use this file except in compliance with the License. | |
You may obtain a copy of the License at | |
http://www.apache.org/licenses/LICENSE-2.0 | |
Unless required by applicable law or agreed to in writing, software | |
distributed under the License is distributed on an "AS IS" BASIS, | |
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
See the License for the specific language governing permissions and | |
limitations under the License. | |
*/ | |
/* | |
Copyright 2023 The Kubernetes Authors. | |
Licensed under the Apache License, Version 2.0 (the "License"); | |
you may not use this file except in compliance with the License. | |
You may obtain a copy of the License at | |
http://www.apache.org/licenses/LICENSE-2.0 | |
Unless required by applicable law or agreed to in writing, software | |
distributed under the License is distributed on an "AS IS" BASIS, | |
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
See the License for the specific language governing permissions and | |
limitations under the License. | |
*/ |
Fix license header in all files.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated license across all files.
1511011
to
92e6896
Compare
/test all |
/lgtm |
Example: ` | ||
# Create an ssh key. | ||
export IBMCLOUD_API_KEY=<api-key> | ||
capibmadm powervs key create --name <key-name> --key "<ssh key>" --service-instance-id <service-instance-id> --zone <zone>`, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor Nit:
capibmadm powervs key create --name <key-name> --key "<ssh key>" --service-instance-id <service-instance-id> --zone <zone>`, | |
capibmadm powervs key create --name <key-name> --key "<ssh-key>" --service-instance-id <service-instance-id> --zone <zone>`, |
#### Example: | ||
```shell | ||
export IBMCLOUD_API_KEY=<api-key> | ||
capibmadm powervs key create --name <key-name> --key "<ssh key>" --service-instance-id <service-instance-id> --zone <zone> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
capibmadm powervs key create --name <key-name> --key "<ssh key>" --service-instance-id <service-instance-id> --zone <zone> | |
capibmadm powervs key create --name <key-name> --key "<ssh-key>" --service-instance-id <service-instance-id> --zone <zone> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressed, made changes as suggested.
ada69ba
to
d3842a4
Compare
/lgtm |
} | ||
|
||
var keyCreateOption keyCreateOptions | ||
cmd.Flags().StringVar(&keyCreateOption.key, "key", "", "SSH RSA key string within a double quotation marks. For example, \"ssh-rsa AAA... \".") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Most of the folks usually prefer file over a plain text of a key for better UX, wondering if can enhance the code to do so. One more flag can be added like key-file
which reads from the file and does some validation as well.
@Prajyot-Parab @Karthik-K-N wdys?
Note: if agree - we can have a follow up PR
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sure we can introduce a flag , Once this get merged, may be @kishen-v do you want to give a try for that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Karthik-K-N, anything works. If all the PRs for capibmdm needs to go together, I'll work on an enhancement PR to support reading of SSH key from file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1 for --key-file
flag
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changes are made support the --key-path
argument.
kishenv@Kishens-MacBook-Pro capibmadm % ./capibmadm powervs key create --name capiadm-sshkey2 --key-path /Users/kishenv/.ssh/id_rsa.pub --zone osa21 --service-instance-id <redacted>
Creating SSH key...
Successfully created the SSH key. name="capiadm-sshkey2"
} | ||
keyClient := instance.NewIBMPIKeyClient(ctx, sess, options.GlobalOptions.ServiceInstanceID) | ||
|
||
sshBody := models.SSHKey{Name: &keyCreateOption.keyName, SSHKey: &keyCreateOption.key} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we need any validation for the validness of the key or Create
call will take of that?!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mkumatag, I tried to pass an invalid SSH-key to --key
, there is supporting logic on the server's end to validate the key. The following error was returned :
failed to Create PI Key with error [POST /pcloud/v1/tenants/{tenant_id}/sshkeys][400] pcloudTenantsSshkeysPostBadRequest
&{Code:0 Description:capiadm-sshkey sshkey is invalid; please enter a valid ssh RSA key: ssh: no key found Error:bad request Message:}
I'll add supporting changes to validate the key before the request is made.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we really need? or we just rely on server to take care of validation?!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can rely on server too. :)
But I was only thinking if it would be better to validate the key locally, if not this overhead will be borne by the server.
Edit: I have added a check to validate the SSH-key in the code.
705d90b
to
fa964b7
Compare
@kishen-v need to fix conflicts and push again. |
520e250
to
bd94198
Compare
a35bbac
to
5b4e469
Compare
5b4e469
to
3819a3a
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/lgtm
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: kishen-v, mkumatag 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 |
What this PR does / why we need it:
The PR contains the changes to support creation and deletion of ssh-keys in the powervs environment using the capibmadm tool.
The supporting documentation has also been updated.
Which issue(s) this PR fixes (optional, in
fixes #<issue number>(, fixes #<issue_number>, ...)
format, will close the issue(s) when PR gets merged):Fixes #
Special notes for your reviewer:
/area provider/ibmcloud
Release note: