Convert the Revision controller to use functional options to reduce boilerplate.#2447
Conversation
knative-prow-robot
left a comment
There was a problem hiding this comment.
@mattmoor: 0 warnings.
Details
In response to this:
This explores the use of functional options to cut back on the amount of boilerplate (especially for conditions) to write table tests.
I think this is probably worth pursuing if only because it makes the tests themselves easier to maintain by going through more of our helper routines vs. constructing full condition lists by hand.
WIP building on prior changes: #2446
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.
700fa84 to
7e7359c
Compare
|
/test pull-knative-serving-integration-tests |
dprotaso
left a comment
There was a problem hiding this comment.
I'm generally a fan of this style of initialization. Overall we might look at being consistent with the prefix of the functions.
A quick scan and I see the following
With*
Set*
Mark*
Add*
No*
Clear*
All*
Conditions*I'd imagine choosing a single prefix would reduce the cognitive load of figuring out what options exist for a given type. Secondly, IDEs with autocomplete just typing the prefix would ideally show me the set of options I could pass to the construction of the fixture.
| @@ -46,11 +46,11 @@ func getIsServiceReady(e *corev1.Endpoints) bool { | |||
| } | |||
|
|
|||
| func getRevisionLastTransitionTime(r *v1alpha1.Revision) time.Time { | |||
| return r.CreationTimestamp.Time | ||
| } | ||
| return r.Status.Conditions[condCount-1].LastTransitionTime.Inner.Time | ||
| return ready.LastTransitionTime.Inner.Time |
There was a problem hiding this comment.
Makes me think we should have a function for these transition/created times
ie.
func (c Condition) LastTransitionTime() time.Time {
c.LastTransitionTime.Inner.Time
}| cfg, err := resources.MakeConfiguration(svc) | ||
| type ConfigOption func(*v1alpha1.Configuration) | ||
|
|
||
| func config(name, namespace string, so ServiceOption, co ...ConfigOption) *v1alpha1.Configuration { |
There was a problem hiding this comment.
When seeing config("config", "namespace", WithPin) I couldn't infer how WithPin was manipulating the config - since I thought it modified a service.
If you only allow ConfigOption to be used I could see an alternative
config("name", "namespace", WithPinnedSpec("service", "namespace"))where WithPinnedSpec may be defined like
func WithPinnedSpec(serviceName, serviceNamespace, so ....ServiceOption) *v1alpha1.ConfigurationMaybe the namespace could be omitted
f981591 to
8d543d7
Compare
This starts to factor out functional options for setting up our table tests, which reduces the verbosity a fair amount. I've broken off Configuration from a broader set of changes in knative#2447 to make things a bit more manageable to review.
This starts to factor out functional options for setting up our table tests, which reduces the verbosity a fair amount. I've broken off Configuration from a broader set of changes in knative#2447 to make things a bit more manageable to review.
This starts to factor out functional options for setting up our table tests, which reduces the verbosity a fair amount. I've broken off Configuration from a broader set of changes in knative#2447 to make things a bit more manageable to review.
This starts to factor out functional options for setting up our table tests, which reduces the verbosity a fair amount. I've broken off Configuration from a broader set of changes in knative#2447 to make things a bit more manageable to review.
8d543d7 to
8b12233
Compare
This starts to factor out functional options for setting up our table tests, which reduces the verbosity a fair amount. I've broken off Service from a broader set of changes in knative#2447 to make things a bit more manageable to review.
8b12233 to
3db11bd
Compare
This starts to factor out functional options for setting up our table tests, which reduces the verbosity a fair amount. I've broken off Service from a broader set of changes in knative#2447 to make things a bit more manageable to review.
6654928 to
23f4fe5
Compare
|
/lint |
knative-prow-robot
left a comment
There was a problem hiding this comment.
@mattmoor: 3 warnings.
Details
In response to this:
/lint
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.
| } | ||
| } | ||
|
|
||
| // WithFailedCondif reflects the Configuration's failure in the Service |
There was a problem hiding this comment.
Golint comments: comment on exported function WithFailedConfig should be of the form "WithFailedConfig ...". More info.
| r.Status.LogURL = "http://logger.io/test-uid" | ||
| } | ||
|
|
||
| // TODO(mattmoor): Ideally this could be a more generic Option and use meta.Accessor, |
There was a problem hiding this comment.
Golint comments: comment on exported function WithCreationTimestamp should be of the form "WithCreationTimestamp ...". More info.
| }) | ||
| } | ||
|
|
||
| // WithSuccessfulBuild propagates the status of a successful Build to the Revision's status. |
There was a problem hiding this comment.
Golint comments: comment on exported function WithSucessfulBuild should be of the form "WithSucessfulBuild ...". More info.
This starts to factor out functional options for setting up our table tests, which reduces the verbosity a fair amount. I've broken off Service from a broader set of changes in knative#2447 to make things a bit more manageable to review.
dbee406 to
c43df9d
Compare
|
/lint |
knative-prow-robot
left a comment
There was a problem hiding this comment.
@mattmoor: 1 unresolved warning and 0 new warning.
Details
In response to this:
/lint
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.
|
/test pull-knative-serving-unit-tests |
This starts to factor out functional options for setting up our table tests, which reduces the verbosity a fair amount. I've broken off Configuration from a broader set of changes in knative#2447 to make things a bit more manageable to review.
This starts to factor out functional options for setting up our table tests, which reduces the verbosity a fair amount. I've broken off Service from a broader set of changes in knative#2447 to make things a bit more manageable to review.
This starts to factor out functional options for setting up our table tests, which reduces the verbosity a fair amount. I've broken off Service from a broader set of changes in knative#2447 to make things a bit more manageable to review.
c43df9d to
c63ab41
Compare
| Object: svc("all-ready", "foo", WithRunLatestRollout, | ||
| // When the Route and Configuration come back with ready | ||
| // our initial conditions transition to Ready=True. | ||
| // TODO(mattmoor): Add Latest{Created,REady} |
…tive#2446) An initial cleanup while looking into: knative#2442
c63ab41 to
02acf77
Compare
|
/lgtm |
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: jonjohnsonjr, mattmoor The full list of commands accepted by this bot can be found here. The pull request process is described here DetailsNeeds approval from an approver in each of these files:
Approvers can indicate their approval by writing |
This explores the use of functional options to cut back on the amount of boilerplate (especially for conditions) to write table tests.
I think this is probably worth pursuing if only because it makes the tests themselves easier to maintain by going through more of our helper routines vs. constructing full condition lists by hand.
WIP building on prior changes: #2446