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

@gempesaw feat(pod-exec): add initial support for command execution #329

Merged
merged 1 commit into from
Sep 25, 2018

Conversation

gempesaw
Copy link
Contributor

@gempesaw gempesaw commented Sep 11, 2018

This doesn't work at all yet - I'm just opening the PR early for fun. I'm currently stuck trying to figure out how to pass the ca, cert, & key for the WS connection. Whenever I finish, I'm planning to rebase to fit y'all's commit message format.

edit: Huzzah, this is in a working state now; more details below.

fixes #19, fixes #319

@silasbw
Copy link
Contributor

silasbw commented Sep 15, 2018

Cool! Maybe @3rd-Eden can give some advice on using client certs with ws.

@gempesaw gempesaw changed the title WIP: Implement initial handling for POST /pods/:pod/exec Implement non-interactive pod execution via POST /pods/:pod/exec Sep 16, 2018
@gempesaw
Copy link
Contributor Author

gempesaw commented Sep 16, 2018

Cool, it turns out I had been experimenting without stdin=true&stderr=true&stdout=true query parameters in the exec to Kubernetes; apparently those are mandatory. This is now in a working state, and I also rebased onto master to pick up changes in package-lock.json since last week.

npm test passed locally, but npm run test-integration failed on master for me, so I didn't look too hard into getting in passing this time around.

I've added a few questions inline! Cheers.

'resize'
];

/**
Copy link
Contributor Author

@gempesaw gempesaw Sep 16, 2018

Choose a reason for hiding this comment

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

I'm not in the habit of writing JSDoc, so I'm ready to take any feedback here.

lib/request.js Outdated Show resolved Hide resolved
Copy link
Contributor

@silasbw silasbw left a comment

Choose a reason for hiding this comment

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

🌶️ nice. few comments for improvements / tweaks.

lib/request.js Show resolved Hide resolved
lib/request.js Outdated
* @param {function} cb - callback to handle the response
* @returns {string} All necessary query parameters as a string ready for inclusion in URL
*/
function buildExecQueryParams(qs, cb) {
Copy link
Contributor

Choose a reason for hiding this comment

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

can you use qs to implement this function? e.g.,

qs.stringify(qs, { indicies: false });

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh, yes - that should make this much cleaner.

lib/request.js Outdated
const commandAsParams = command.map((cmd) => `command=${encodeURIComponent(cmd)}`);
delete qs.command;

const execParams = Object.assign(qs, {
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of adding these on implicitly, i'd just assume the caller specified them.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm, so the caller must know to include them in the body on every call? aka usage example would change to

client.api.v1.namespaces('namespace_name').pods('pod_name').exec.post({
  qs: {
    command: [ 'ls', '-al' ],
    stdin: true, // hmm perhaps stdin isn't necessary, i'll have to double check
    stdout: true,
    stderr: true
  }
})

Unfortunately, the error response while I was forgetting to include stdout/stderr query params was just a 400 Error with no message, so it may be a bit difficult for users to debug... but if it's in the examples/ usage, hopefully that's enough guidance?

Happy to make the change, and agree it makes sense since kubernetes-client isn't in the habit of adding query parameters anywhere else, just wondering about troubleshooting :P

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, I'm suggesting that the user needs to include those on every call for the reason you mention about eschewing adding query parameters. I think the example/ you wrote will help. I think is there's enough interest and/or common patterns it could make sense to have a separate module focused on helping exec things (e.g., kubernetes-exec).

lib/request.js Show resolved Hide resolved
lib/request.js Outdated Show resolved Hide resolved
@gempesaw
Copy link
Contributor Author

Ok, I think we're all set, based on the last round of feedback...

Copy link
Contributor

@silasbw silasbw left a comment

Choose a reason for hiding this comment

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

small spacing nit, but good stuff.

I'm excited to get this merged and iterate on. thanks for contributing! 🌶️ 🌶️ 🌶️

lib/request.js Outdated

function upgradeRequest(options, cb) {
const queryParams = qs.stringify(options.qs, { indices: false });
const wsUrl = `${options.baseUrl}/${options.uri}?${queryParams}`;
Copy link
Contributor

Choose a reason for hiding this comment

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

spacing nit

@gempesaw gempesaw changed the title Implement non-interactive pod execution via POST /pods/:pod/exec @gempesaw feat(pod-exec): add initial support for command execution Sep 25, 2018
@gempesaw
Copy link
Contributor Author

gempesaw commented Sep 25, 2018

Heh heh, oops, good catch. Also, I rebased into one commit to try to match y'all's style. Cheers!

@silasbw silasbw merged commit ed47d43 into godaddy:master Sep 25, 2018
@gempesaw gempesaw deleted the pod-exec branch September 25, 2018 04:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants