-
Notifications
You must be signed in to change notification settings - Fork 342
Include GetTopLevelConditionType for KRShaped #1298
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
Changes from all commits
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 |
|---|---|---|
|
|
@@ -33,6 +33,8 @@ type KRShaped interface { | |
| GetTypeMeta() *metav1.TypeMeta | ||
|
|
||
| GetStatus() *Status | ||
|
|
||
| GetTopLevelConditionType() apis.ConditionType | ||
| } | ||
|
|
||
| // Asserts KResource conformance with KRShaped | ||
|
|
@@ -88,3 +90,13 @@ func (t *KResource) GetTypeMeta() *metav1.TypeMeta { | |
| func (t *KResource) GetStatus() *Status { | ||
| return &t.Status | ||
| } | ||
|
|
||
| // GetTopLevelConditionType retrieves the happy condition of this resource. Implements the KRShaped interface. | ||
| func (t *KResource) GetTopLevelConditionType() apis.ConditionType { | ||
| // Note: KResources are unmarshalled from existing resources. This will only work properly for resources that | ||
| // have already been initialized to their type. | ||
| if cond := t.Status.GetCondition(apis.ConditionSucceeded); cond != nil { | ||
|
Contributor
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 will not work for un-initialized resources, the condition set will be an empty list.
Contributor
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. sorry I did not see the final impl, this will work but it wil also require all downstreams to update
Contributor
Author
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. I have that included as a comment. The idea is that each API shape reports its type and gets initialized. KResource is a generic struct we unmarshal to, but not something that directly manages init. |
||
| return apis.ConditionSucceeded | ||
| } | ||
| return apis.ConditionReady | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| /* | ||
| Copyright 2020 The Knative Authors | ||
|
|
||
| Licensed under the Apache License, Version 2.0 (the "License"); | ||
| you may not use this file except in compliance with the License. | ||
| You may obtain a copy of the License at | ||
|
|
||
| http://www.apache.org/licenses/LICENSE-2.0 | ||
|
|
||
| Unless required by applicable law or agreed to in writing, software | ||
| distributed under the License is distributed on an "AS IS" BASIS, | ||
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| See the License for the specific language governing permissions and | ||
| limitations under the License. | ||
| */ | ||
|
|
||
| package v1 | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| "knative.dev/pkg/apis" | ||
| ) | ||
|
|
||
| func TestGetTopLevelCondition(t *testing.T) { | ||
| resource := KResource{} | ||
|
|
||
| condSet := apis.NewLivingConditionSet("Foo") | ||
| mgr := condSet.Manage(resource.GetStatus()) | ||
| mgr.InitializeConditions() | ||
|
whaught marked this conversation as resolved.
|
||
|
|
||
| if resource.GetTopLevelConditionType() != apis.ConditionReady { | ||
| t.Error("Expected Ready as happy condition for living condition set type") | ||
| } | ||
|
|
||
| condSet = apis.NewBatchConditionSet("Foo") | ||
| mgr = condSet.Manage(resource.GetStatus()) | ||
| mgr.InitializeConditions() | ||
|
|
||
| if resource.GetTopLevelConditionType() != apis.ConditionSucceeded { | ||
| t.Error("Expected Succeeded as happy condition for living condition set type") | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.
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.
Too late, but I'm curious why we didn't stick to the current naming here (
Happyinstead ofTopLevel).