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

prevent invalid const errors from lowercase resource kind #413

Merged
merged 3 commits into from
Jan 17, 2019

Conversation

dwradcliffe
Copy link
Member

@dwradcliffe dwradcliffe commented Jan 15, 2019

What are you trying to accomplish with this PR?
Fix errors that occur if one attempts to deploy a resource that has a kind with a lowercase first letter. This is not the case for any of the standard k8s kinds, but custom resources may use lowercase kinds.

NameError: wrong constant name foobar
    lib/kubernetes-deploy/kubernetes_resource.rb:39:in `const_defined?'
    lib/kubernetes-deploy/kubernetes_resource.rb:39:in `build'

How is this accomplished?
Capitalize the string before checking for a const. This seemed like the simplest change that wouldn't impact the existing logic.
This would also allow these resource types to have custom resources classes added, in the capitalized form.

Rescue the NameError and fallback to the generic class. This is safer than changing the string and catches any other edge cases we haven't thought about.

What could go wrong?
I can't really think of anything.

@@ -288,6 +288,17 @@ def test_disappeared_is_false_if_resource_has_been_deployed_and_we_get_a_server_
refute_predicate(dummy, :disappeared?)
end

def test_custom_resource_kind
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 make this name more descriptive and/or add an assert_nothing_raised and/or assert that build returned an instance of the expected class? I'm thinking it won't be very obvious in the future what this test is covering / what the bug was.

namespace: 'test',
context: 'test',
definition: definition,
logger: ::Logger.new($stderr),
Copy link
Contributor

Choose a reason for hiding this comment

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

Not that it makes any difference here, but FYI there's a logger accessor all tests can use.

@dwradcliffe dwradcliffe changed the title capitalize kind to prevent invalid const errors prevent invalid const errors from lowercase resource kind Jan 17, 2019
@dwradcliffe dwradcliffe merged commit a3d2f05 into master Jan 17, 2019
@dwradcliffe dwradcliffe deleted the fix_invalid_const_name branch January 17, 2019 21:34
@dwradcliffe
Copy link
Member Author

Released in v0.24.0.

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.

None yet

3 participants