-
Notifications
You must be signed in to change notification settings - Fork 115
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
[Bug Fix] Grouping Cluster Resources by group and Kind #875
Changes from all commits
4e123fc
699e170
c614da0
d2eba74
4063283
be52459
2c7fafd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -59,7 +59,7 @@ def status | |
end | ||
|
||
def type | ||
kind | ||
group_kind | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For other reviewers:
def type
@type || self.class.kind
end
All this to say, I'm hoping the use of |
||
end | ||
|
||
def validate_definition(*, **) | ||
|
@@ -77,7 +77,11 @@ def validate_definition(*, **) | |
private | ||
|
||
def kind | ||
@definition["kind"] | ||
@crd.kind | ||
end | ||
|
||
def group_kind | ||
@crd.group_kind | ||
end | ||
|
||
def rollout_conditions | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -52,6 +52,10 @@ def group | |
@definition.dig("spec", "group") | ||
end | ||
|
||
def group_kind | ||
"#{kind}.#{group}" | ||
end | ||
|
||
Comment on lines
+55
to
+58
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The behaviour of |
||
def prunable? | ||
prunable = krane_annotation_value("prunable") | ||
prunable == "true" | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
--- | ||
apiVersion: apiextensions.k8s.io/v1 | ||
kind: CustomResourceDefinition | ||
metadata: | ||
name: same-kinds.with-rollout-conditions.example.io | ||
labels: | ||
app: krane | ||
annotations: | ||
krane.shopify.io/instance-rollout-conditions: "true" | ||
spec: | ||
group: with-rollout-conditions.example.io | ||
names: | ||
kind: SameKind | ||
listKind: SameKindList | ||
plural: same-kinds | ||
singular: same-kind | ||
scope: Namespaced | ||
versions: | ||
- name: v1 | ||
served: true | ||
storage: true | ||
schema: | ||
openAPIV3Schema: | ||
type: object | ||
properties: | ||
spec: | ||
type: object | ||
status: | ||
type: object | ||
properties: | ||
observedGeneration: | ||
type: integer | ||
conditions: | ||
type: array | ||
items: | ||
type: object | ||
properties: | ||
type: | ||
type: string | ||
reason: | ||
type: string | ||
message: | ||
type: string | ||
status: | ||
type: string | ||
|
||
--- | ||
apiVersion: apiextensions.k8s.io/v1 | ||
kind: CustomResourceDefinition | ||
metadata: | ||
name: same-kinds.no-rollout-conditions.example.io | ||
labels: | ||
app: krane | ||
spec: | ||
group: no-rollout-conditions.example.io | ||
names: | ||
kind: SameKind | ||
listKind: SameKindList | ||
plural: same-kinds | ||
singular: same-kind | ||
scope: Namespaced | ||
versions: | ||
- name: v1 | ||
served: true | ||
storage: true | ||
schema: | ||
openAPIV3Schema: | ||
type: object | ||
properties: | ||
spec: | ||
type: object |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
--- | ||
apiVersion: "with-rollout-conditions.example.io/v1" | ||
kind: SameKind | ||
metadata: | ||
name: monitored | ||
--- | ||
apiVersion: "no-rollout-conditions.example.io/v1" | ||
kind: SameKind | ||
metadata: | ||
name: unmonitored |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -265,9 +265,9 @@ def test_custom_resources_predeployed | |
end | ||
assert_deploy_success(result) | ||
|
||
mail_cr_id = "#{add_unique_prefix_for_test('Mail')}/my-first-mail" | ||
thing_cr_id = "#{add_unique_prefix_for_test('Thing')}/my-first-thing" | ||
widget_cr_id = "#{add_unique_prefix_for_test('Widget')}/my-first-widget" | ||
mail_cr_id = "#{add_unique_prefix_for_test('Mail')}.stable.example.io/my-first-mail" | ||
thing_cr_id = "#{add_unique_prefix_for_test('Thing')}.stable.example.io/my-first-thing" | ||
widget_cr_id = "#{add_unique_prefix_for_test('Widget')}.stable.example.io/my-first-widget" | ||
assert_logs_match_all([ | ||
/Phase 3: Predeploying priority resources/, | ||
/Successfully deployed in \d.\ds: #{mail_cr_id}/, | ||
|
@@ -291,11 +291,11 @@ def test_cr_deploys_without_rollout_conditions_when_none_present | |
end | ||
|
||
assert_deploy_success(result) | ||
prefixed_kind = add_unique_prefix_for_test("Widget") | ||
prefixed_kind = "#{add_unique_prefix_for_test('Widget')}.stable.example.io" | ||
assert_logs_match_all([ | ||
"Don't know how to monitor resources of type #{prefixed_kind}.", | ||
"Assuming #{prefixed_kind}/my-first-widget deployed successfully.", | ||
%r{Widget/my-first-widget\s+Exists}, | ||
%r{#{prefixed_kind}/my-first-widget\s+Exists}, | ||
]) | ||
end | ||
|
||
|
@@ -320,10 +320,11 @@ def test_cr_success_with_default_rollout_conditions | |
cr.merge!(success_conditions) | ||
cr["kind"] = add_unique_prefix_for_test(cr["kind"]) | ||
end | ||
prefixed_name = "#{add_unique_prefix_for_test('Parameterized')}.stable.example.io" | ||
assert_deploy_success(result) | ||
assert_logs_match_all([ | ||
%r{Successfully deployed in .*: #{add_unique_prefix_for_test("Parameterized")}\/with-default-params}, | ||
%r{Parameterized/with-default-params\s+Healthy}, | ||
%r{Successfully deployed in .*: #{prefixed_name}\/with-default-params}, | ||
%r{Parameterized.stable.example.io/with-default-params\s+Healthy}, | ||
]) | ||
end | ||
|
||
|
@@ -374,12 +375,47 @@ def test_cr_failure_with_default_rollout_conditions | |
assert_deploy_failure(result) | ||
|
||
assert_logs_match_all([ | ||
"Parameterized/with-default-params: FAILED", | ||
"Parameterized.stable.example.io/with-default-params: FAILED", | ||
"custom resource rollout failed", | ||
"Final status: Unhealthy", | ||
], in_order: true) | ||
end | ||
|
||
# # Make 2 CRDs of same kind, different group. We expect the appropriate one to be monitored and | ||
# # the other to be unmonitored for rollout conditions | ||
def test_cr_references_parent_crd_by_group_kind | ||
assert_deploy_success(deploy_global_fixtures("crd", subset: %(for_group_kind_test.yml))) | ||
success_conditions = { | ||
"status" => { | ||
"observedGeneration" => 1, | ||
"conditions" => [ | ||
{ | ||
"type" => "Ready", | ||
"reason" => "test", | ||
"message" => "test", | ||
"status" => "True", | ||
}, | ||
], | ||
}, | ||
} | ||
|
||
result = deploy_fixtures("crd", subset: %(for_group_kind_test_cr.yml)) do |resource| | ||
monitored = resource["for_group_kind_test_cr.yml"]["SameKind"][0] | ||
monitored["kind"] = add_unique_prefix_for_test(monitored["kind"]) | ||
monitored.merge!(success_conditions) | ||
|
||
unmonitored = resource["for_group_kind_test_cr.yml"]["SameKind"][1] | ||
unmonitored["kind"] = add_unique_prefix_for_test(unmonitored["kind"]) | ||
end | ||
assert_deploy_success(result) | ||
prefixed_kind = add_unique_prefix_for_test("SameKind") | ||
assert_logs_match_all([ | ||
/Successfully deployed in .*: /, | ||
%r{#{prefixed_kind}.no-rollout-conditions.example.io/unmonitored Exists}, | ||
%r{#{prefixed_kind}.with-rollout-conditions.example.io/monitored Healthy}, | ||
]) | ||
end | ||
|
||
def test_cr_success_with_arbitrary_rollout_conditions | ||
assert_deploy_success(deploy_global_fixtures("crd", subset: %(with_custom_conditions.yml))) | ||
|
||
|
@@ -398,8 +434,9 @@ def test_cr_success_with_arbitrary_rollout_conditions | |
cr.merge!(success_conditions) | ||
end | ||
assert_deploy_success(result) | ||
prefixed_name = "#{add_unique_prefix_for_test('Customized')}.stable.example.io" | ||
assert_logs_match_all([ | ||
%r{Successfully deployed in .*: #{add_unique_prefix_for_test("Customized")}\/with-customized-params}, | ||
%r{Successfully deployed in .*: #{prefixed_name}\/with-customized-params}, | ||
]) | ||
end | ||
|
||
|
@@ -450,7 +487,7 @@ def test_deploying_crs_with_invalid_crd_conditions_fails | |
end | ||
end | ||
assert_deploy_failure(result) | ||
prefixed_name = add_unique_prefix_for_test("Customized-with-customized-params") | ||
prefixed_name = add_unique_prefix_for_test('Customized.stable.example.io-with-customized-params').to_s | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the most visible consequence of our change, and I would argue it's a feature: CRDs are now logged showing both their group and kind. This should make things easier to understand in the case of multiple kinds among difference groups |
||
assert_logs_match_all([ | ||
/Invalid template: #{prefixed_name}/, | ||
/Rollout conditions are not valid JSON/, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -96,6 +96,7 @@ def test_cr_instance_fails_validation_when_rollout_conditions_for_crd_invalid | |
logger: @logger, statsd_tags: @statsd_tags, crd: crd, | ||
definition: { | ||
"kind" => "UnitTest", | ||
"apiVersion" => "stable.example.io/v1", | ||
"metadata" => { "name" => "test" }, | ||
}) | ||
cr.validate_definition(kubectl: kubectl) | ||
|
@@ -129,6 +130,7 @@ def test_cr_instance_valid_when_rollout_conditions_for_crd_valid | |
logger: @logger, statsd_tags: [], crd: crd, | ||
definition: { | ||
"kind" => "UnitTest", | ||
"apiVersion" => "stable.example.io/v1", | ||
"metadata" => { "name" => "test" }, | ||
}) | ||
cr.validate_definition(kubectl: kubectl) | ||
|
@@ -154,7 +156,11 @@ def test_instance_timeout_annotation | |
)) | ||
cr = Krane::KubernetesResource.build(namespace: "test", context: "test", | ||
logger: @logger, statsd_tags: [], crd: crd, | ||
definition: { "kind" => "UnitTest", "metadata" => { "name" => "test" } }) | ||
definition: { | ||
"kind" => "UnitTest", | ||
"apiVersion" => "stable.example.io/v1", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We need to add |
||
"metadata" => { "name" => "test" }, | ||
}) | ||
assert_equal(cr.timeout, 60) | ||
end | ||
|
||
|
@@ -171,6 +177,7 @@ def test_instance_timeout_messages_with_rollout_conditions | |
logger: @logger, statsd_tags: [], crd: crd, | ||
definition: { | ||
"kind" => "UnitTest", | ||
"apiVersion" => "stable.example.io/v1", | ||
"metadata" => { | ||
"name" => "test", | ||
}, | ||
|
@@ -195,6 +202,7 @@ def test_instance_timeout_messages_without_rollout_conditions | |
logger: @logger, statsd_tags: [], crd: crd, | ||
definition: { | ||
"kind" => "UnitTest", | ||
"apiVersion" => "stable.example.io/v1", | ||
"metadata" => { | ||
"name" => "test", | ||
}, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are there tests to cover this change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will be great to test this change, this is supposed to change the order of the items
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added new tests to cover these changes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't quite understand what you mean by this, could you explain please?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, sorry, I misread the issue in #873 and I thought a consequence of this PR is that it'll change the order of the items in some list, however, this change is about grouping differently. Sorry for the noise