Skip to content
This repository has been archived by the owner on Mar 13, 2022. It is now read-only.

ExecProvider errors when parsing null values #91

Merged

Conversation

fillbit
Copy link
Contributor

@fillbit fillbit commented Oct 5, 2018

When executing a command like kubectl config use-context kubectl rewrite the the kubeconfig file and adds null to optional parameters. For example a a config with

users:
- name: Name1
  user:
    exec:
      apiVersion: client.authentication.k8s.io/v1alpha1
      command: heptio-authenticator-aws

is rewritten as:

users:
- name: Name1
  user:
    exec:
      apiVersion: client.authentication.k8s.io/v1alpha1
      args: null
      command: heptio-authenticator-aws
      env: null

When the ExecParser reads this it returns the error:

ERROR: Invalid kube-config file. Expected key args in kube-config/users[name=Name1]/user/exec

This PR adds a test case and a fix for this issue.

@k8s-ci-robot
Copy link
Contributor

Thanks for your pull request. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

📝 Please follow instructions at https://git.k8s.io/community/CLA.md#the-contributor-license-agreement to sign the CLA.

It may take a couple minutes for the CLA signature to be fully registered; after that, please reply here with a new comment and we'll verify. Thanks.


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. I understand the commands that are listed here.

@k8s-ci-robot k8s-ci-robot added cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Oct 5, 2018
@codecov-io
Copy link

codecov-io commented Oct 5, 2018

Codecov Report

Merging #91 into master will increase coverage by <.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #91      +/-   ##
==========================================
+ Coverage   91.71%   91.72%   +<.01%     
==========================================
  Files          13       13              
  Lines        1135     1136       +1     
==========================================
+ Hits         1041     1042       +1     
  Misses         94       94
Impacted Files Coverage Δ
config/exec_provider_test.py 98.38% <100%> (+0.02%) ⬆️
config/exec_provider.py 82.6% <100%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 2d514ce...3682e9b. Read the comment docs.

@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. and removed cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. labels Oct 5, 2018
@fillbit
Copy link
Contributor Author

fillbit commented Oct 5, 2018

signed CLA?

Copy link
Member

@roycaihw roycaihw left a comment

Choose a reason for hiding this comment

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

Thanks for the contribution! I left some comments.

exec_config['args'] = None
exec_config['env'] = None
try:
ExecProvider(exec_config)
Copy link
Member

Choose a reason for hiding this comment

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

I suppose the test fails when exec_config is of ConfigNode class, e.g. having

exec_config = ConfigNode('test', self.input_ok)

@@ -38,10 +38,10 @@ def __init__(self, exec_config):
'exec: malformed request. missing key \'%s\'' % key)
self.api_version = exec_config['apiVersion']
self.args = [exec_config['command']]
if 'args' in exec_config:
if 'args' in exec_config and exec_config['args']:
Copy link
Member

Choose a reason for hiding this comment

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

The exception comes from ConfigNode which implements __getitem__ under the assumption that

all access keys are present in a well-formed kube-config.

Calling the __getitem__ in the if statement would also raise the exception.

To tolerate malformed config, I'd suggest using exec_config.safe_get(key) to verify if the value is null. Note that the unit test used dict for exec_config which didn't reflect the safe_get attribute.

@fillbit
Copy link
Contributor Author

fillbit commented Oct 10, 2018

I've updated the PR to use safe_get and the unit tests to use ConfigNode instead of dict() so they work correctly. I also updated the input_ok to include a env: null value and removed my test case as it is now redundant

@roycaihw
Copy link
Member

@fillbit Thanks. Could you also add a comment in ExecProvider documenting that __init__ expects exec_config to be of ConfigNode class, which implements the safe_get(self, key) method? Otherwise LGTM

@roycaihw
Copy link
Member

Please fix the pycodestyle error for travis CI to pass, and squash commits before submit :)

*Update unit tests to use ConfigNode() instead of dict()
@fillbit
Copy link
Contributor Author

fillbit commented Oct 12, 2018

@roycaihw @mbohlool Are there any other issue that need to be addressed?

@roycaihw
Copy link
Member

/lgtm
/approve

@k8s-ci-robot k8s-ci-robot added the lgtm Indicates that a PR is ready to be merged. label Oct 12, 2018
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: fillbit, roycaihw

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 Oct 12, 2018
@k8s-ci-robot k8s-ci-robot merged commit 8d7b6f7 into kubernetes-client:master Oct 12, 2018
@nakulpathak3
Copy link

kubernetes-client/python#678 hi I've been seeing the error mentioned in the issue while using both 8.0.0a and 8.0.0. If anyone has any tips/ideas for what I'm doing wrong or if there is something we need to change with the way we are doing exec-provider, please let me know

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
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 Indicates that a PR is ready to be merged. size/S Denotes a PR that changes 10-29 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants