-
Notifications
You must be signed in to change notification settings - Fork 61
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
[OSD-26117] Add command to start ssm session for nodes of HCP clusters #585
base: main
Are you sure you want to change the base?
Conversation
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: Dee-6777 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 |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #585 +/- ##
==========================================
- Coverage 45.39% 45.24% -0.15%
==========================================
Files 87 88 +1
Lines 6759 6852 +93
==========================================
+ Hits 3068 3100 +32
- Misses 3311 3367 +56
- Partials 380 385 +5
|
@Dee-6777: all tests passed! Full PR test history. Your PR dashboard. 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-sigs/prow repository. I understand the commands that are listed here. |
Follow up card to add test cases https://issues.redhat.com/browse/OSD-27393 |
// getInstanceID fetches the instance id of the given node | ||
func getInstanceID(Node string) (string, error) { | ||
logger.Infof("Fetching instance ID for node: %s", Node) | ||
command := fmt.Sprintf("oc get node %s -o jsonpath='{.spec.providerID}' | awk -F/ '{print $NF}'", Node) |
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.
Let's try using client-go
whenever possible instead of calling the oc
command directly.
Could you have a try to see if client-go
can work for this?
https://pkg.go.dev/k8s.io/client-go/kubernetes#Clientset.CoreV1
https://pkg.go.dev/k8s.io/[email protected]/kubernetes/typed/core/v1#CoreV1Client.Nodes
Examples:
deploymentsClient := clientSet.AppsV1().Deployments(ConsoleNS) |
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.
I can try to use this
@Dee-6777 Thank you for the well-struct code and a detailed README! |
command := fmt.Sprintf("aws ssm start-session --target %s", instanceID) | ||
logger.Infof("Executing command: %s", command) | ||
|
||
cmdExec := exec.Command("sh", "-c", command) | ||
cmdExec.Stdout = os.Stdout | ||
cmdExec.Stderr = os.Stderr | ||
|
||
if err := cmdExec.Run(); err != nil { | ||
logger.Errorf("Failed to start SSM session: %v", err) | ||
fmt.Printf("To manually start the session, run: %s\n", command) | ||
return err | ||
} |
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.
This is acting as a wrapper around the CLI. We should be looking to use native Go libraries itself to run the command
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.
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.
Thanks pratik, I can try to implement this
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.
https://pkg.go.dev/github.com/aws/aws-sdk-go-v2/service/ssm - those have all the required APIs but we also need to implement the ssm plugin
What type of PR is this?
feature
What this PR does / Why we need it?
This PR will add a subcommand named "ssm" to start a ssm session for HCP with a given node name in it's management cluster
Example command:
ocm backplane cloud ssm --node ${NODE_NAME}
Which Jira/Github issue(s) does this PR fix?
Resolves OSD-26117
Special notes for your reviewer
Unit Test Coverage
Guidelines
Test coverage checks
Pre-checks (if applicable)