Skip to content

Commit

Permalink
Prevent duplicate deprecated template warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
Ryan Brushett committed Sep 12, 2019
1 parent b2c4633 commit 6e7b7ad
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/kubernetes-deploy/kubernetes_resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -425,12 +425,14 @@ def validate_timeout_annotation
end

def validate_annotation_version
return if validation_warning_msg.include?("annotations is deprecated")
annotation_keys = @definition.dig("metadata", "annotations")&.keys
annotation_keys&.each do |annotation|
if annotation.include?("kubernetes-deploy.shopify.io")
annotation_prefix = annotation.split('/').first
@validation_warnings << "#{annotation_prefix} as a prefix for annotations is deprecated: "\
"Use the 'krane.shopify.io' annotation prefix instead"
return
end
end
end
Expand Down
14 changes: 14 additions & 0 deletions test/unit/kubernetes-deploy/kubernetes_resource_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,20 @@ def test_deprecated_annotation_generates_warning
customized_resource.validation_warning_msg)
end

def test_multiple_deprecated_annotations_generates_only_one_warning
definition_extras = build_timeout_metadata("60S", use_deprecated: true).dup
definition_extras['metadata']['annotations']['kubernetes-deploy.shopify.io/something'] = "thing"
customized_resource = DummyResource.new(definition_extras: definition_extras)
customized_resource.validate_definition(kubectl)

warning_message = <<~MESSAGE.strip
kubernetes-deploy.shopify.io as a prefix for annotations is deprecated: Use the 'krane.shopify.io' annotation prefix instead
MESSAGE

assert(customized_resource.has_warnings?, "Deprecated annotation did not generate a warning")
assert_equal(customized_resource.validation_warning_msg, warning_message)
end

def test_valid_annotations_generate_no_warning
customized_resource = DummyResource.new(definition_extras: build_timeout_metadata("60S"))
customized_resource.validate_definition(kubectl)
Expand Down

0 comments on commit 6e7b7ad

Please sign in to comment.