Skip to content

Convert the Revision controller to use functional options to reduce boilerplate.#2447

Merged
knative-prow-robot merged 2 commits intoknative:masterfrom
mattmoor:simple-conditions
Nov 16, 2018
Merged

Convert the Revision controller to use functional options to reduce boilerplate.#2447
knative-prow-robot merged 2 commits intoknative:masterfrom
mattmoor:simple-conditions

Conversation

@mattmoor
Copy link
Copy Markdown
Member

@mattmoor mattmoor commented Nov 9, 2018

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

@knative-prow-robot knative-prow-robot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Nov 9, 2018
@knative-prow-robot knative-prow-robot added size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. approved Indicates a PR has been approved by an approver from all required OWNERS files. labels Nov 9, 2018
Copy link
Copy Markdown
Contributor

@knative-prow-robot knative-prow-robot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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.

@mattmoor mattmoor force-pushed the simple-conditions branch 6 times, most recently from 700fa84 to 7e7359c Compare November 10, 2018 04:33
@mattmoor
Copy link
Copy Markdown
Member Author

/test pull-knative-serving-integration-tests

Copy link
Copy Markdown
Member

@dprotaso dprotaso left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Separate PR?

return r.CreationTimestamp.Time
}
return r.Status.Conditions[condCount-1].LastTransitionTime.Inner.Time
return ready.LastTransitionTime.Inner.Time
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.Configuration

Maybe the namespace could be omitted

@mattmoor mattmoor force-pushed the simple-conditions branch 3 times, most recently from f981591 to 8d543d7 Compare November 14, 2018 17:38
mattmoor added a commit to mattmoor/serving that referenced this pull request Nov 14, 2018
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.
mattmoor added a commit to mattmoor/serving that referenced this pull request Nov 15, 2018
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.
mattmoor added a commit to mattmoor/serving that referenced this pull request Nov 15, 2018
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.
mattmoor added a commit to mattmoor/serving that referenced this pull request Nov 15, 2018
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.
mattmoor added a commit to mattmoor/serving that referenced this pull request Nov 15, 2018
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.
mattmoor added a commit to mattmoor/serving that referenced this pull request Nov 15, 2018
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.
@mattmoor mattmoor force-pushed the simple-conditions branch 2 times, most recently from 6654928 to 23f4fe5 Compare November 15, 2018 04:20
@mattmoor
Copy link
Copy Markdown
Member Author

/lint

Copy link
Copy Markdown
Contributor

@knative-prow-robot knative-prow-robot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Golint comments: comment on exported function WithSucessfulBuild should be of the form "WithSucessfulBuild ...". More info.

mattmoor added a commit to mattmoor/serving that referenced this pull request Nov 15, 2018
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.
@mattmoor mattmoor force-pushed the simple-conditions branch 2 times, most recently from dbee406 to c43df9d Compare November 15, 2018 04:24
@mattmoor
Copy link
Copy Markdown
Member Author

/lint

Copy link
Copy Markdown
Contributor

@knative-prow-robot knative-prow-robot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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.

@mattmoor
Copy link
Copy Markdown
Member Author

/test pull-knative-serving-unit-tests

mattmoor added a commit to mattmoor/serving that referenced this pull request Nov 16, 2018
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.
knative-prow-robot pushed a commit that referenced this pull request Nov 16, 2018
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 #2447 to make things a bit more manageable to review.
mattmoor added a commit to mattmoor/serving that referenced this pull request Nov 16, 2018
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.
@mattmoor mattmoor changed the title [WIP] PoC Use functional options to reduce boilerplace Convert the Revision controller to use functional options to reduce boilerplate. Nov 16, 2018
@knative-prow-robot knative-prow-robot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Nov 16, 2018
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}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Ready 😄

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@jonjohnsonjr
Copy link
Copy Markdown
Contributor

/lgtm
/approve

@knative-prow-robot knative-prow-robot added the lgtm Indicates that a PR is ready to be merged. label Nov 16, 2018
@knative-prow-robot
Copy link
Copy Markdown
Contributor

[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

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@knative-prow-robot knative-prow-robot merged commit 7c4f3c5 into knative:master Nov 16, 2018
@mattmoor mattmoor deleted the simple-conditions branch November 16, 2018 19:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files. lgtm Indicates that a PR is ready to be merged. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants