Skip to content
This repository has been archived by the owner on Jun 4, 2021. It is now read-only.

Refactor k8s source to use the sdk. #123

Closed
wants to merge 5 commits into from

Conversation

n3wscott
Copy link
Contributor

@n3wscott n3wscott commented Nov 20, 2018

Proposed Changes

  • Use sdk for k8s source.
  • Add tests
  • Delete was not being checked in reconcile.
  • The first time you create a container source, it has no status so it would deep copy erase all the k8s source status conditions
  • Moved it to best practice for conditionals.

Release Note

NONE

@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 20, 2018
@knative-prow-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: n3wscott
To fully approve this pull request, please assign additional approvers.
We suggest the following additional approver: evankanderson

If they are not already assigned, you can assign the PR to them by writing /assign @evankanderson in a comment when ready.

The full list of commands accepted by this bot can be found here.

The pull request process is described here

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 added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Nov 20, 2018
@knative-prow-robot knative-prow-robot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Nov 20, 2018
@knative-prow-robot knative-prow-robot added size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. and removed size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Nov 20, 2018
@n3wscott n3wscott changed the title [WIP] Refactor k8s source to use the sdk. Refactor k8s source to use the sdk. Nov 20, 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 20, 2018
@n3wscott
Copy link
Contributor Author

/test pull-knative-eventing-sources-go-coverage

@n3wscott
Copy link
Contributor Author

/assign @grantr

@knative-metrics-robot
Copy link

The following is the coverage report on pkg/.
Say /test pull-knative-eventing-sources-go-coverage to re-run this coverage report

File Old Coverage New Coverage Delta
pkg/controller/kuberneteseventsource/reconcile.go 0.0% 86.7% 86.7

kubernetesEventSourceCondSet.Manage(s).MarkTrue(KubernetesEventSourceConditionReady)
// PropagateContainerSourceStatus examines the given container source and synchronizes the conditions that matter to
// the kubernetes event source status.
func (ss *KubernetesEventSourceStatus) MarkContainerSourceReadyStatus(cs ContainerSourceStatus) {
Copy link
Contributor

Choose a reason for hiding this comment

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

The comment starts with PropagateContainerSourceStatus, which seems like what this method does, but the method is named MarkContainerSourceReadyStatus.

kubernetesEventSourceCondSet.Manage(s).MarkTrue(KubernetesEventSourceConditionReady)
// PropagateContainerSourceStatus examines the given container source and synchronizes the conditions that matter to
// the kubernetes event source status.
func (ss *KubernetesEventSourceStatus) MarkContainerSourceReadyStatus(cs ContainerSourceStatus) {
Copy link
Contributor

Choose a reason for hiding this comment

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

If we expect people to use ContainerSource this way (having their own source wrap it), this method should be moved somewhere it can be shared.

func PropagateContainerSourceStatus(cm ConditionManager, cs ContainerSourceStatus)

Then in this file:

func PropagateContainerSourceStatus(cs ContainerSourceStatus) {
    containersource.PropagateConatinerSourceStatus(kubernetesEventSourceCondSet.Manage(s), cs)
}

kubernetesEventSourceCondSet.Manage(s).MarkTrue(KubernetesEventSourceConditionReady)
// PropagateContainerSourceStatus examines the given container source and synchronizes the conditions that matter to
// the kubernetes event source status.
func (ss *KubernetesEventSourceStatus) MarkContainerSourceReadyStatus(cs ContainerSourceStatus) {
Copy link
Contributor

Choose a reason for hiding this comment

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

ss -> s to match the other functions in the file.


reason := ""
message := ""
isFalse := false
Copy link
Contributor

Choose a reason for hiding this comment

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

How about statusFalse? For some reason isFalse feels wrong to me.

// the source does not have Ready status True.
func (s *KubernetesEventSourceStatus) MarkUnready(reason, messageFormat string, messageA ...interface{}) {
kubernetesEventSourceCondSet.Manage(s).MarkFalse(KubernetesEventSourceConditionReady, reason, messageFormat, messageA...)
func appendMessage(a string, b string) string {
Copy link
Contributor

Choose a reason for hiding this comment

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

How about using strings.Join instead?

Above would change to something like:

messages := make([]string)
...
messages = append(messages, "SinkProvided status is nil")
...
 MarkUnknown(..., reason, strings.Join(messages, "; "))

},
}

func TestAllCases(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

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

TestReconcile

duckAddKnownTypes(scheme.Scheme)
}

var testCases = []controllertesting.TestCase{
Copy link
Contributor

Choose a reason for hiding this comment

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

Move this variable inside the TestAllCases method.

Reconciles: &sourcesv1alpha1.KubernetesEventSource{},
InitialState: []runtime.Object{
func() runtime.Object {
s := getSource()
Copy link
Contributor

Choose a reason for hiding this comment

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

Every call to getSource() (except one where I don't think it matters), is immediately followed by s.UID = sourceUID, move that into the getSource() method.

return u
}(),
},
ReconcileKey: fmt.Sprintf("%s/%s", testNS, sourceName),
Copy link
Contributor

Choose a reason for hiding this comment

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

I recommend removing ReconcileKey and IgnoreTimes out of every test case and just set them in the test itself, because every test case uses the same values for those two fields.

// Add creates a new KubernetesEventSource Controller and adds it to the Manager
// with default RBAC. The Manager will set fields on the Controller and Start it
// when the Manager is Started.
// Add creates a new GitHubSource Controller and adds it to the
Copy link
Contributor

Choose a reason for hiding this comment

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

KubernetesSource

@matzew
Copy link
Member

matzew commented Mar 15, 2019

@n3wscott what's the status here ?

@evankanderson
Copy link
Member

/assign Harwayne
/unassign grantr

@n3wscott n3wscott closed this Apr 23, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
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.

7 participants