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

Add Exec command to Pods #38

Merged
merged 3 commits into from
Apr 29, 2022
Merged

Conversation

pablochacin
Copy link
Contributor

@pablochacin pablochacin commented Apr 28, 2022

Add function for executing a command in an existing pod and return the output (stdin and strerr) in a similar way than executing a non interactive command using kubectl exec

Note: for implementing this functionality it is necessary to access the k8s client configuration. As the client library does not allow to retrieve it from the client instance, it was necessary to add the config to the Pod structure.

Closes #35

Signed-off-by: Pablo Chacin <pablochacin@gmail.com>
Signed-off-by: Pablo Chacin <pablochacin@gmail.com>
Signed-off-by: Pablo Chacin <pablochacin@gmail.com>
const result = kubernetes.pods.exec({
namespace: namespace,
pod: podName,
container: container.name,
Copy link
Contributor

Choose a reason for hiding this comment

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

@pablochacin

Reviewing the example from a user perspective, it would be ideal to skip passing the container name.

What makes me think if we could pass the pod directly , so either the podName or the pod.

kubernetes.pods.exec({
  pod: pod,
  command:[]
  stadin: []
});

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Pods can have multiple containers, so it is important that the API allows specifying the target container.

For example, when using ephemeral containers to add chaos behavior to a running pod, it is necessary to be able to execute commands in the ephemeral container.

What could be improved is to mimic the behavior of the kubectl command and chose a default container if none is specified.

Copy link
Member

Choose a reason for hiding this comment

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

What could be improved is to mimic the behavior of the kubectl command and chose a default container if none is specified.

Personally, I never liked this behavior :(

So, I would keep it as it is right now.

Copy link
Contributor

@ppcano ppcano left a comment

Choose a reason for hiding this comment

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

posted a code comment

@ppcano ppcano requested a review from javaducky April 29, 2022 09:14
@ppcano
Copy link
Contributor

ppcano commented Apr 29, 2022

cc @javaducky

Copy link
Contributor

@javaducky javaducky left a comment

Choose a reason for hiding this comment

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

LGTM

@javaducky javaducky merged commit 4eb6350 into grafana:main Apr 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add function to execute a command in a running pod
4 participants