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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 12 additions & 7 deletions lib/kubernetes-deploy/kubernetes_resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,19 @@ def build(namespace:, context:, definition:, logger:, statsd_tags:)
statsd_tags: statsd_tags }
if definition["kind"].blank?
raise InvalidTemplateError.new("Template missing 'Kind'", content: definition.to_yaml)
elsif KubernetesDeploy.const_defined?(definition["kind"])
klass = KubernetesDeploy.const_get(definition["kind"])
klass.new(**opts)
else
inst = new(**opts)
inst.type = definition["kind"]
inst
end

begin
if KubernetesDeploy.const_defined?(definition["kind"])
klass = KubernetesDeploy.const_get(definition["kind"])
return klass.new(**opts)
end
rescue NameError
end

inst = new(**opts)
inst.type = definition["kind"]
inst
end

def timeout
Expand Down
11 changes: 11 additions & 0 deletions test/unit/kubernetes-deploy/kubernetes_resource_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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_lowercase_custom_resource_kind_does_not_raise
definition = { "kind" => "foobar", "metadata" => { "name" => "test" } }
KubernetesDeploy::KubernetesResource.build(
namespace: 'test',
context: 'test',
definition: definition,
logger: logger,
statsd_tags: []
)
end

private

def kubectl
Expand Down