Skip to content

Commit

Permalink
pr review
Browse files Browse the repository at this point in the history
  • Loading branch information
timothysmith0609 committed Jan 18, 2019
1 parent 2e7e5bf commit 44f890a
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 19 deletions.
21 changes: 7 additions & 14 deletions lib/kubernetes-deploy/kubernetes_resource.rb
Expand Up @@ -36,28 +36,21 @@ def build(namespace:, context:, definition:, logger:, statsd_tags:, crd: nil)
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)
elsif crd
CustomResource.new(crd: crd, **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
if crd
CustomResource.new(crd: crd, **opts)
else
inst = new(**opts)
inst.type = definition["kind"]
inst
end
end

def timeout
Expand Down
1 change: 0 additions & 1 deletion test/fixtures/crd/with_custom_conditions.yml
Expand Up @@ -3,7 +3,6 @@ kind: CustomResourceDefinition
metadata:
name: customizeds.stable.example.io
annotations:
kubernetes-deploy.shopify.io/instance-timeout: '5S'
kubernetes-deploy.shopify.io/instance-rollout-conditions: '{
"success_conditions": [
{
Expand Down
Expand Up @@ -90,10 +90,13 @@ def test_cr_instance_fails_validation_when_rollout_conditions_for_crd_invalid
"metadata" => { "name" => "test" },
})
cr.validate_definition(kubectl)
assert(cr.validation_error_msg.match(
"Annotation #{KubernetesDeploy::CustomResourceDefinition::ROLLOUT_CONDITIONS_ANNOTATION} " \
"on #{crd.name} is invalid: Rollout conditions are not valid JSON:"
))
assert_equal(cr.validation_error_msg,
"The CRD that specifies this resource is using invalid rollout conditions. Kubernetes-deploy will not be " \
"able to continue until those rollout conditions are fixed.\nRollout conditions can be found on the CRD " \
"that defines this resource (unittests.stable.example.io), Under the annotation " \
"kubernetes-deploy.shopify.io/instance-rollout-conditions.\nValidation failed with: " \
"Rollout conditions are not valid JSON: Empty input () at line 1, column 1 [parse.c:963] in 'bad string"
)
end

def test_cr_instance_valid_when_rollout_conditions_for_crd_valid
Expand Down
2 changes: 2 additions & 0 deletions test/unit/kubernetes-deploy/kubernetes_resource_test.rb
Expand Up @@ -297,6 +297,8 @@ def test_lowercase_custom_resource_kind_does_not_raise
logger: logger,
statsd_tags: []
)
end

def test_build_handles_hardcoded_and_core_and_dynamic_objects
# Hardcoded CRs
redis_crd = KubernetesDeploy::KubernetesResource.build(namespace: "test", context: "test",
Expand Down

0 comments on commit 44f890a

Please sign in to comment.